Events interface
Dispatching and subscribing. Venus does not use Bukkit's event bus, so a listener registered here only ever sees Venus events.
| Signature | Description |
|---|---|
EventListenerRepository repository() | The registration surface: register, unregister, count. See EventListenerRepository. |
<T extends VenusApiEvent> T call(T event) | Dispatches on the calling thread and returns the same instance, so the caller can inspect cancellation. |
boolean hasListeners(Class<? extends VenusApiEvent>) | True when at least one listener is registered for that type. |
Registering
api.events().repository().register(
DetectionAlertEvent.class,
event -> {
String check = event.check().name();
double vl = event.violationLevel();
getLogger().info(event.user().username() + " | " + check + " | " + vl);
},
EventPriority.RUN_LAST, // after other listeners have had their say
true // skip events a previous listener already cancelled
);Firing your own
call is generic and returns the event, which makes it usable in a fluent chain. Your own event types are welcome as long as they extend VenusApiEvent; they will be dispatched to listeners registered for that class or for any supertype.
public final class MyEvent extends CancellableVenusEvent {
private final String payload;
public MyEvent(String payload) {
this.payload = payload;
}
public String payload() {
return payload;
}
}
// dispatch
MyEvent event = api.events().call(new MyEvent("hello"));
if (!event.cancelled()) {
// nobody vetoed it
}Ordering and cancellation
- Listeners run in priority order, then in registration order within a priority.
- A listener registered with
ignoreCancelled = truedoes not see events another listener already cancelled. - Cancellation only exists on events that inherit from
CancellableVenusEvent. - An exception thrown by a listener is caught and logged; it does not stop the remaining listeners and never breaks the check that fired the event.
Which event to listen to, and what each one carries, is on event classes.