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 Details

    • subscribe

      default <E extends Event> Subscription subscribe(Class<E> type, Consumer<E> listener)
      Subscribes a listener at EventPriority.NORMAL priority.
      Type Parameters:
      E - the event type
      Parameters:
      type - the event type to observe; subtypes are delivered too
      listener - 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 too
      priority - when the listener is called relative to the others
      listener - the listener to call
      Returns:
      the handle of the subscription
      Since:
      0.1.0
    • post

      <E extends Event> E post(E event)
      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

      void unsubscribeAll(Object owner)
      Unsubscribes every listener owned by owner.
      Parameters:
      owner - the owner of the subscriptions, usually a Plugin
      Since:
      0.1.0