EventListenerRepository
Where listeners are registered and removed. The handle you get back is the only way to unregister precisely.
| Signature | Description |
|---|---|
RegisteredListener<T> register(Class<T>, Consumer<T>) | Normal priority, receives cancelled events too. |
RegisteredListener<T> register(Class<T>, Consumer<T>, EventPriority) | Normal semantics with an explicit ordering. |
RegisteredListener<T> register(Class<T>, Consumer<T>, EventPriority, boolean ignoreCancelled) | Full form. |
void unregister(RegisteredListener<?> listener) | Removes one listener and marks its handle inactive. |
void unregisterAll() | Removes every listener registered through the API, including other plugins’ own. |
int listenerCount(Class<? extends VenusApiEvent>) | How many listeners are registered for a type. |
The handle
RegisteredListener is a small immutable record plus an active flag:
| Signature | Description |
|---|---|
UUID id() | Unique per registration, useful for logging. |
Class<T> eventClass() | The class the listener was registered for. |
Consumer<? super T> consumer() | The callback itself. |
EventPriority priority() | Ordering priority. |
boolean ignoreCancelled() | Whether cancelled events are skipped. |
boolean active() | False once unregistered. |
void unregister() | Marks the handle inactive without touching the repository. |
private RegisteredListener<ViolationEvent> violationListener;
void onApi(VenusApi api) {
violationListener = api.events().repository().register(
ViolationEvent.class,
event -> metrics.record(event.check().stableKey(), event.violationLevel()),
EventPriority.RUN_FIRST,
false);
}
void shutdown(VenusApi api) {
if (violationListener != null) {
api.events().repository().unregister(violationListener);
violationListener = null;
}
}Notes
- A listener registered for a supertype receives events of every subtype. Registering for
UserCancellableEventgives you everything a user did; registering forViolationEventgives you only flags. unregisterAll()is a blunt instrument — it clears the whole repository. Use it only in a shutdown path you own.- Callbacks run on the thread that dispatched the event. Keep them short; heavy work belongs on your own executor.
Ordering is described on EventPriority; the events themselves are on event classes.