EventPriority enum
Three values. That is the whole ordering model.
| Signature | Description |
|---|---|
RUN_FIRST | Runs before everything else. Use it to cancel early or to sanitise an event for later listeners. |
NORMAL | The default. Most listeners belong here. |
RUN_LAST | Runs after every other listener. Use it to observe the final, possibly cancelled, state of an event. |
int priority() | The numeric order backing the enum: -1, 0, 1. |
How dispatch works
- Matching listeners are collected from every registered type that is assignable from the event class.
- That list is sorted by priority.
- Within one priority the registration order is kept, so a plugin that registers two listeners sees them run in the order it wrote them.
- Listeners with
ignoreCancelledset are skipped once an earlier listener has cancelled the event.
// Runs first: veto a flag for a whitelisted world.
api.events().repository().register(ViolationEvent.class, event -> {
if (whitelisted(event.user().getWorldName())) event.setCancelled(true);
}, EventPriority.RUN_FIRST, false);
// Runs last: log what survived.
api.events().repository().register(ViolationEvent.class, event ->
log.info("counted: " + event.check().name()), EventPriority.RUN_LAST, true);Choosing a priority
- Cancellation belongs in RUN_FIRST. It gives other plugins a predictable event rather than a race.
- Metrics and logging belong in RUN_LAST with ignoreCancelled. You then measure what actually happened, not what was proposed.
- Do not reach for priorities to avoid someone else's listener. If two plugins fight over an event, the fix is a shared rule, not a lower number.
See EventListenerRepository for registration and event classes for what can be cancelled.