Package com.velocitypowered.api.event
Interface EventManager
public interface EventManager
Allows plugins to register and deregister listeners for event handlers.
-
Method Summary
Modifier and TypeMethodDescription<E> CompletableFuture<E>
fire
(E event) Fires the specified event to the event bus asynchronously.default void
fireAndForget
(Object event) Posts the specified event to the event bus and discards the result.<E> void
register
(Object plugin, Class<E> eventClass, short postOrder, EventHandler<E> handler) Requests that the specifiedhandler
listen for events and associate it with theplugin
.default <E> void
register
(Object plugin, Class<E> eventClass, EventHandler<E> handler) Requests that the specifiedhandler
listen for events and associate it with theplugin
.<E> void
register
(Object plugin, Class<E> eventClass, PostOrder postOrder, EventHandler<E> handler) Deprecated.void
Requests that the specifiedlistener
listen for events and associate it with theplugin
.<E> void
unregister
(Object plugin, EventHandler<E> handler) Unregisters a specific event handler for a specific plugin.void
unregisterListener
(Object plugin, Object listener) Unregisters a specific listener for a specific plugin.void
unregisterListeners
(Object plugin) Unregisters all listeners for the specifiedplugin
.
-
Method Details
-
register
Requests that the specifiedlistener
listen for events and associate it with theplugin
.- Parameters:
plugin
- the plugin to associate with the listenerlistener
- the listener to register
-
register
Requests that the specifiedhandler
listen for events and associate it with theplugin
.- Type Parameters:
E
- the event type to handle- Parameters:
plugin
- the plugin to associate with the handlereventClass
- the class for the event handler to registerhandler
- the handler to register
-
register
@Deprecated <E> void register(Object plugin, Class<E> eventClass, PostOrder postOrder, EventHandler<E> handler) Deprecated.useregister(Object, Class, short, EventHandler)
insteadRequests that the specifiedhandler
listen for events and associate it with theplugin
.- Type Parameters:
E
- the event type to handle- Parameters:
plugin
- the plugin to associate with the handlereventClass
- the class for the event handler to registerpostOrder
- the order in which events should be posted to the handlerhandler
- the handler to register
-
register
Requests that the specifiedhandler
listen for events and associate it with theplugin
.Note that this method will register a non-asynchronous listener by default. If you want to use an asynchronous event handler, return
EventTask.async(Runnable)
from the handler.- Type Parameters:
E
- the event type to handle- Parameters:
plugin
- the plugin to associate with the handlereventClass
- the class for the event handler to registerpostOrder
- the relative order in which events should be posted to the handlerhandler
- the handler to register
-
fire
Fires the specified event to the event bus asynchronously. This allows Velocity to continue servicing connections while a plugin handles a potentially long-running operation such as a database query.- Parameters:
event
- the event to fire- Returns:
- a
CompletableFuture
representing the posted event
-
fireAndForget
Posts the specified event to the event bus and discards the result.- Parameters:
event
- the event to fire
-
unregisterListeners
Unregisters all listeners for the specifiedplugin
.- Parameters:
plugin
- the plugin to deregister listeners for
-
unregisterListener
Unregisters a specific listener for a specific plugin.- Parameters:
plugin
- the plugin associated with the listenerlistener
- the listener to deregister
-
unregister
Unregisters a specific event handler for a specific plugin.- Type Parameters:
E
- the event type to handle- Parameters:
plugin
- the plugin to associate with the handlerhandler
- the handler to register
-
register(Object, Class, short, EventHandler)
instead