Skip to content

Commit

Permalink
fix: remove deprecated Velocity API usage (#504)
Browse files Browse the repository at this point in the history
* Update event.mdx

Update event.mdx to remove deprecated API usage

* Update docs/velocity/dev/api/event.mdx

Co-authored-by: powercas_gamer <[email protected]>

* Update docs/velocity/dev/api/event.mdx

Co-authored-by: powercas_gamer <[email protected]>

* Update docs/velocity/dev/api/event.mdx

Co-authored-by: Matouš Kučera <[email protected]>

* Update docs/velocity/dev/api/event.mdx

Co-authored-by: Matouš Kučera <[email protected]>

* Update docs/velocity/dev/api/event.mdx

Co-authored-by: Matouš Kučera <[email protected]>

---------

Co-authored-by: powercas_gamer <[email protected]>
Co-authored-by: Matouš Kučera <[email protected]>
  • Loading branch information
3 people authored Dec 6, 2024
1 parent 04a1f02 commit 48e45d0
Showing 1 changed file with 12 additions and 7 deletions.
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

0 comments on commit 48e45d0

Please sign in to comment.