Class EventBus

java.lang.Object
com.sk89q.worldedit.util.eventbus.EventBus

public final class EventBus extends Object
Dispatches events to listeners, and provides ways for listeners to register themselves.

This class is based on Guava's EventBus but priority is supported and events are dispatched at the time of call, rather than being queued up. This does allow dispatching during an in-progress dispatch.

  • Constructor Details

    • EventBus

      public EventBus()
  • Method Details

    • subscribe

      public void subscribe(Class<?> clazz, EventHandler handler)
      Registers the given handler for the given class to receive events.
      Parameters:
      clazz - the event class to register
      handler - the handler to register
    • subscribeAll

      public void subscribeAll(com.google.common.collect.Multimap<Class<?>,EventHandler> handlers)
      Registers the given handler for the given class to receive events.
      Parameters:
      handlers - a map of handlers
    • unsubscribe

      public void unsubscribe(Class<?> clazz, EventHandler handler)
      Unregisters the given handler for the given class.
      Parameters:
      clazz - the class
      handler - the handler
    • unsubscribeAll

      public void unsubscribeAll(com.google.common.collect.Multimap<Class<?>,EventHandler> handlers)
      Unregisters the given handlers.
      Parameters:
      handlers - a map of handlers
    • register

      public void register(Object object)
      Registers all handler methods on object to receive events. Handler methods are selected and classified using this EventBus's SubscriberFindingStrategy; the default strategy is the AnnotatedSubscriberFinder.
      Parameters:
      object - object whose handler methods should be registered.
    • unregister

      public void unregister(Object object)
      Unregisters all handler methods on a registered object.
      Parameters:
      object - object whose handler methods should be unregistered.
      Throws:
      IllegalArgumentException - if the object was not previously registered.
    • post

      public void post(Object event)
      Posts an event to all registered handlers. This method will return successfully after the event has been posted to all handlers, and regardless of any exceptions thrown by handlers.
      Parameters:
      event - event to post.