Skip to content
Merged
Changes from all commits
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
19 changes: 12 additions & 7 deletions docs/velocity/dev/api/event.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,25 @@ 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#priority()"} project={"velocity"}>`priority`</Javadoc>.
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

Due to compatibility constraints, you must specify <Javadoc name={"com.velocitypowered.api.event.PostOrder#CUSTOM"} project={"velocity"}>`PostOrder.CUSTOM`</Javadoc> in order to use this field.

:::

## Registering listeners

Expand Down Expand Up @@ -121,12 +126,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)
public void onLogin(LoginEvent event, Continuation continuation) {
doSomeAsyncProcessing().addListener(continuation::resume, continuation::resumeWithException);
}

@Subscribe(order = PostOrder.EARLY)
@Subscribe(priority = 100, order = PostOrder.CUSTOM)
public EventTask onPlayerChat(PlayerChatEvent event) {
if (mustFurtherProcess(event)) {
return EventTask.async(() => ...);
Expand Down
Loading