Class EventBus
java.lang.Object
com.sk89q.worldedit.util.eventbus.EventBus
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Posts an event to all registered handlers.void
Registers all handler methods onobject
to receive events.void
subscribe
(Class<?> clazz, EventHandler handler) Registers the given handler for the given class to receive events.void
subscribeAll
(com.google.common.collect.Multimap<Class<?>, EventHandler> handlers) Registers the given handler for the given class to receive events.void
unregister
(Object object) Unregisters all handler methods on a registeredobject
.void
unsubscribe
(Class<?> clazz, EventHandler handler) Unregisters the given handler for the given class.void
unsubscribeAll
(com.google.common.collect.Multimap<Class<?>, EventHandler> handlers) Unregisters the given handlers.
-
Constructor Details
-
EventBus
public EventBus()
-
-
Method Details
-
subscribe
Registers the given handler for the given class to receive events.- Parameters:
clazz
- the event class to registerhandler
- the handler to register
-
subscribeAll
Registers the given handler for the given class to receive events.- Parameters:
handlers
- a map of handlers
-
unsubscribe
Unregisters the given handler for the given class.- Parameters:
clazz
- the classhandler
- the handler
-
unsubscribeAll
Unregisters the given handlers.- Parameters:
handlers
- a map of handlers
-
register
Registers all handler methods onobject
to receive events. Handler methods are selected and classified using this EventBus'sSubscriberFindingStrategy
; the default strategy is theAnnotatedSubscriberFinder
.- Parameters:
object
- object whose handler methods should be registered.
-
unregister
Unregisters all handler methods on a registeredobject
.- Parameters:
object
- object whose handler methods should be unregistered.- Throws:
IllegalArgumentException
- if the object was not previously registered.
-
post
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.
-