Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update velocity event.mdx #504

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions docs/velocity/dev/api/event.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,21 @@ and _not_ in `com.google.common.eventbus`.

## Orders

Every listener has a <Javadoc name={"com.velocitypowered.api.event.PostOrder"} project={"velocity"}>`PostOrder`</Javadoc>.
When an event is fired, the order in which listeners are invoked is defined by their `PostOrder`.
Listeners using `PostOrder.FIRST` are called first, then `EARLY`, `NORMAL`, etc.
Every listener has a <Javadoc name={"com.velocitypowered.api.event.Subscribe"} project={"velocity"}>`priority`</Javadoc>.
KastenKlicker marked this conversation as resolved.
Show resolved Hide resolved
When an event is fired, the order in which listeners are invoked is defined by their `priority`.
The higher the priority, the earlier the event handler will be called.

State the desired order in the `@Subscribe` annotation:

```java
@Subscribe(order = PostOrder.NORMAL)
@Subscribe(priority = 0, order = PostOrder.CUSTOM)
public void onPlayerChat(PlayerChatEvent event) {
// do stuff
}
```

`NORMAL` is the default value if you do not specify an order.
`-32768` is the default value if you do not specify an order.
Note that due to compatibility constraints, you must specify <Javadoc name={"com.velocitypowered.api.event.PostOrder"} project={"velocity"}>`PostOrder.CUSTOM`</Javadoc> in order to use this field.
KastenKlicker marked this conversation as resolved.
Show resolved Hide resolved

## Registering listeners

Expand Down Expand Up @@ -121,12 +122,12 @@ return an <Javadoc name={"com.velocitypowered.api.event.EventTask"} project={"ve
or add a second return an <Javadoc name={"com.velocitypowered.api.event.Continuation"} project={"velocity"}>`Continuation`</Javadoc> parameter:

```java
@Subscribe(order = PostOrder.EARLY)
@Subscribe(priority = 100,order = PostOrder.CUSTOM)
KastenKlicker marked this conversation as resolved.
Show resolved Hide resolved
public void onLogin(LoginEvent event, Continuation continuation) {
doSomeAsyncProcessing().addListener(continuation::resume, continuation::resumeWithException);
}

@Subscribe(order = PostOrder.EARLY)
@Subscribe(priority = 100,order = PostOrder.CUSTOM)
KastenKlicker marked this conversation as resolved.
Show resolved Hide resolved
public EventTask onPlayerChat(PlayerChatEvent event) {
if (mustFurtherProcess(event)) {
return EventTask.async(() => ...);
Expand Down
Loading