Interface EventManager


public interface EventManager
Allows plugins to register and deregister listeners for event handlers.
  • Method Details

    • register

      void register(Object plugin, Object listener)
      Requests that the specified listener listen for events and associate it with the plugin.
      Parameters:
      plugin - the plugin to associate with the listener
      listener - the listener to register
    • register

      default <E> void register(Object plugin, Class<E> eventClass, EventHandler<E> handler)
      Requests that the specified handler listen for events and associate it with the plugin.
      Type Parameters:
      E - the event type to handle
      Parameters:
      plugin - the plugin to associate with the handler
      eventClass - the class for the event handler to register
      handler - the handler to register
    • register

      @Deprecated <E> void register(Object plugin, Class<E> eventClass, PostOrder postOrder, EventHandler<E> handler)
      Requests that the specified handler listen for events and associate it with the plugin.
      Type Parameters:
      E - the event type to handle
      Parameters:
      plugin - the plugin to associate with the handler
      eventClass - the class for the event handler to register
      postOrder - the order in which events should be posted to the handler
      handler - the handler to register
    • register

      <E> void register(Object plugin, Class<E> eventClass, short postOrder, EventHandler<E> handler)
      Requests that the specified handler listen for events and associate it with the plugin.

      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 handler
      eventClass - the class for the event handler to register
      postOrder - the relative order in which events should be posted to the handler
      handler - the handler to register
    • fire

      <E> CompletableFuture<E> fire(E event)
      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

      default void fireAndForget(Object event)
      Posts the specified event to the event bus and discards the result.
      Parameters:
      event - the event to fire
    • unregisterListeners

      void unregisterListeners(Object plugin)
      Unregisters all listeners for the specified plugin.
      Parameters:
      plugin - the plugin to deregister listeners for
    • unregisterListener

      void unregisterListener(Object plugin, Object listener)
      Unregisters a specific listener for a specific plugin.
      Parameters:
      plugin - the plugin associated with the listener
      listener - the listener to deregister
    • unregister

      <E> void unregister(Object plugin, EventHandler<E> handler)
      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 handler
      handler - the handler to register