Venusanticheat docs

EventPriority enum

Three values. That is the whole ordering model.

package xyz.kaosmc.anticheat.api.event
SignatureDescription
RUN_FIRSTRuns before everything else. Use it to cancel early or to sanitise an event for later listeners.
NORMALThe default. Most listeners belong here.
RUN_LASTRuns 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

  1. Matching listeners are collected from every registered type that is assignable from the event class.
  2. That list is sorted by priority.
  3. Within one priority the registration order is kept, so a plugin that registers two listeners sees them run in the order it wrote them.
  4. Listeners with ignoreCancelled set are skipped once an earlier listener has cancelled the event.
two listeners on the same 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.