Interface EventBus
public interface EventBus
Dispatches events to the listeners subscribed to them.
Events are delivered synchronously, on the thread that posts them, usually the region thread owning the block or entity involved. A listener that throws is logged and does not prevent the other listeners from running.
Every subscription has an owner, released all at once by unsubscribeAll(Object). The
bus returned by PluginContext.events() is bound to its plugin: what is
subscribed through it is released when the plugin is disabled, whatever the thread it was
subscribed from.
- Since:
- 0.1.0
-
Method Summary
Modifier and TypeMethodDescription<E extends Event>
Epost(E event) Delivers an event to every matching listener, in priority order, on the calling thread.<E extends Event>
Subscriptionsubscribe(Class<E> type, EventPriority priority, Consumer<E> listener) Subscribes a listener.default <E extends Event>
SubscriptionSubscribes a listener atEventPriority.NORMALpriority.voidunsubscribeAll(Object owner) Unsubscribes every listener owned byowner.
-
Method Details
-
subscribe
Subscribes a listener atEventPriority.NORMALpriority.- Type Parameters:
E- the event type- Parameters:
type- the event type to observe; subtypes are delivered toolistener- the listener to call- Returns:
- the handle of the subscription
- Since:
- 0.1.0
-
subscribe
<E extends Event> Subscription subscribe(Class<E> type, EventPriority priority, Consumer<E> listener) Subscribes a listener.- Type Parameters:
E- the event type- Parameters:
type- the event type to observe; subtypes are delivered toopriority- when the listener is called relative to the otherslistener- the listener to call- Returns:
- the handle of the subscription
- Since:
- 0.1.0
-
post
Delivers an event to every matching listener, in priority order, on the calling thread.- Type Parameters:
E- the event type- Parameters:
event- the event to deliver- Returns:
- the same event, as left by the listeners
- Since:
- 0.1.0
-
unsubscribeAll
-