Class DefaultEventManager

java.lang.Object
eu.cloudnetservice.driver.event.DefaultEventManager
All Implemented Interfaces:
EventManager

@Singleton @Provides(EventManager.class) public class DefaultEventManager extends Object implements EventManager
The default implementation of an event manager.
Since:
4.0
  • Field Details

  • Constructor Details

    • DefaultEventManager

      public DefaultEventManager()
  • Method Details

    • unregisterListeners

      @NonNull public @NonNull EventManager unregisterListeners(@NonNull @NonNull ClassLoader classLoader)
      Unregisters all listeners in classes which were loaded by the given class loader.
      Specified by:
      unregisterListeners in interface EventManager
      Parameters:
      classLoader - the loader based onm which to unregister listeners.
      Returns:
      the same event manager as used to call the method, for chaining.
    • unregisterListener

      @NonNull public @NonNull EventManager unregisterListener(Object @NonNull ... listeners)
      Unregisters all listeners which were registered in each of the given listener classes.
      Specified by:
      unregisterListener in interface EventManager
      Parameters:
      listeners - the classes to unregister all listeners of.
      Returns:
      the same event manager as used to call the method, for chaining.
    • callEvent

      @NonNull public <T extends Event> T callEvent(@NonNull @NonNull String channel, @NonNull T event)
      Calls the given event to the given channel, only triggering the event listeners which are specifically listening to the given channel unless the channel is *.
      Specified by:
      callEvent in interface EventManager
      Type Parameters:
      T - the type of the event.
      Parameters:
      channel - the specific channel to call the listeners on.
      event - the event to call.
      Returns:
      the same event as used to call the method, after processing.
    • registerListener

      @NonNull public @NonNull EventManager registerListener(@NonNull @NonNull Class<?> listenerClass)
      Registers all methods in the given listener class which are annotated with EventListener and are taking only one argument with a subtype of Event. The instance the constructed event listeners are bound to are created by requesting it from the default external injection layer.

      This method accepts public, protected, default (package) access, and private methods but will not include inherited methods at all.

      All methods which are not annotated with EventListener, are static and are not taking one or more arguments are silently ignored.

      Specified by:
      registerListener in interface EventManager
      Parameters:
      listenerClass - the class to create an instance of and register all listeners in.
      Returns:
      the same event manager as used to call the method, for chaining.
    • registerListener

      @NonNull public @NonNull EventManager registerListener(@NonNull @NonNull Object listener)
      Registers all methods in the given listener class which are annotated with EventListener and are taking only one argument with a subtype of Event.

      This method accepts public, protected, default (package) access, and private methods but will not include inherited methods at all.

      All methods which are not annotated with EventListener, are static and are not taking one or more arguments are silently ignored.

      Specified by:
      registerListener in interface EventManager
      Parameters:
      listener - the instance of the listener to register the methods in.
      Returns:
      the same event manager as used to call the method, for chaining.
    • registerListener

      @NonNull protected @NonNull EventManager registerListener(@NonNull @NonNull InjectionLayer<?> layer, @NonNull @NonNull Object listener)
      Registers all methods in the given listener class which are annotated with EventListener and are taking only one argument with a subtype of Event.

      This method accepts public, protected, default (package) access, and private methods but will not include inherited methods at all.

      All methods which are not annotated with EventListener, are static and are not taking one or more arguments are silently ignored.

      Parameters:
      layer - the injection layer to use to get instances needed for event listeners.
      listener - the instance of the listener to register the methods in.
      Returns:
      the same event manager as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given listener or injection layer is null.
      IllegalArgumentException - if an event listener target doesn't take an event as it's first argument.
    • safeRemove

      protected void safeRemove(@NonNull @NonNull Predicate<RegisteredEventListener> predicate)
      Safely removes the all registered event listeners which are matching the given predicate.
      Parameters:
      predicate - the predicate all listeners to remove must match.
      Throws:
      NullPointerException - if the given predicate is null.