Package org.teleight.teleightbots.event
Interface EventManager
public sealed interface EventManager
The
EventManager interface manages event listeners and event handling.-
Method Summary
Modifier and TypeMethodDescription<E extends Event>
@NotNull EventManageraddListener(@NotNull Class<E> eventType, @NotNull Consumer<E> listener) Registers anEventListenerwith the EventManager using aConsumer.<T extends Event>
@NotNull EventManageraddListener(@NotNull EventListener<T> listener) Registers anEventListenerwith the EventManager.<T extends Event>
@NotNull CompletableFuture<T> call(T event) Triggers an event and returns aCompletableFuturerepresenting the processed event itself.static @NotNull EventManager
-
Method Details
-
newEventManager
-
addListener
@NotNull <T extends Event> @NotNull EventManager addListener(@NotNull @NotNull EventListener<T> listener) Registers anEventListenerwith the EventManager.The EventListener will be invoked when events of the specified type occur.
- Type Parameters:
T- The type of event that theEventListeneris designed to handle.- Parameters:
listener- TheEventListenerto be added to the EventManager. It should be capable of handling events of typeT.- Returns:
- The current
EventManagerinstance.
-
addListener
@NotNull <E extends Event> @NotNull EventManager addListener(@NotNull @NotNull Class<E> eventType, @NotNull @NotNull Consumer<E> listener) Registers anEventListenerwith the EventManager using aConsumer.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- TheClassof the event that the EventListener will handle.listener- TheConsumerthat will process events of the specified type. This consumer will be called when events of the specified type are dispatched.- Returns:
- The current
EventManagerinstance. - See Also:
-
call
Triggers an event and returns aCompletableFuturerepresenting 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
CompletableFuturethat will be completed with the event result.
-