Interface EventManager


public sealed interface EventManager
The EventManager interface manages event listeners and event handling.
  • Method Details

    • newEventManager

      @Internal @NotNull static @NotNull EventManager newEventManager()
    • addListener

      @NotNull <T extends Event> @NotNull EventManager addListener(@NotNull @NotNull EventListener<T> listener)
      Registers an EventListener with the EventManager.

      The EventListener will be invoked when events of the specified type occur.

      Type Parameters:
      T - The type of event that the EventListener is designed to handle.
      Parameters:
      listener - The EventListener to be added to the EventManager. It should be capable of handling events of type T.
      Returns:
      The current EventManager instance.
    • addListener

      @NotNull <E extends Event> @NotNull EventManager addListener(@NotNull @NotNull Class<E> eventType, @NotNull @NotNull Consumer<E> listener)
      Registers an EventListener with the EventManager using a Consumer.

      This method simplifies the process of creating and registering a new EventListener by directly providing the event type and the consumer that will handle the events. The consumer is invoked when events of the specified type occur. This is not recommended in case you need more control over your listener.

      Type Parameters:
      E - The type of event that the EventListener will handle.
      Parameters:
      eventType - The Class of the event that the EventListener will handle.
      listener - The Consumer that will process events of the specified type. This consumer will be called when events of the specified type are dispatched.
      Returns:
      The current EventManager instance.
      See Also:
    • call

      @NotNull <T extends Event> @NotNull CompletableFuture<T> call(@NotNull T event)
      Triggers an event and returns a CompletableFuture representing the processed event itself.
      Type Parameters:
      T - The type of event being triggered.
      Parameters:
      event - The event to be triggered. This event will be dispatched to all registered listeners of its type.
      Returns:
      A CompletableFuture that will be completed with the event result.