Package me.kzlyth.api.events
Klasse ZenithEventBus
java.lang.Object
me.kzlyth.api.events.ZenithEventBus
Event bus for Zenith-Mod events.
For detailed documentation and examples, see: https://docs.zenith-studios.org/
Example:
ZenithEventBus bus = ZenithEventBus.getInstance();
bus.subscribe(me.kzlyth.api.events.ban.PlayerBanEvent.class, event -> {
getLogger().info(event.getPlayerName() + " was banned");
});
- Seit:
- 1.2.3
- Autor:
- Zenith-Studios
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoidclear()Clears all handlers for all event types.<T extends ZenithEvent>
intgetHandlerCount(@NotNull Class<T> eventClass) Gets the number of handlers for a specific event type.static @NotNull ZenithEventBusGets the singleton instance of the event bus.<T extends ZenithEvent>
voidpublish(T event) Publishes an event to all subscribed handlers.<T extends ZenithEvent>
voidSubscribes a handler to events of the specified type.<T extends ZenithEvent>
voidunsubscribe(@NotNull Class<T> eventClass, @NotNull Consumer<T> handler) Unsubscribes a handler from events of the specified type.
-
Methodendetails
-
getInstance
Gets the singleton instance of the event bus.- Gibt zurück:
- The event bus instance
-
subscribe
public <T extends ZenithEvent> void subscribe(@NotNull @NotNull Class<T> eventClass, @NotNull @NotNull Consumer<T> handler) Subscribes a handler to events of the specified type.- Typparameter:
T- The event type- Parameter:
eventClass- The event class to subscribe tohandler- The handler function
-
unsubscribe
public <T extends ZenithEvent> void unsubscribe(@NotNull @NotNull Class<T> eventClass, @NotNull @NotNull Consumer<T> handler) Unsubscribes a handler from events of the specified type.- Typparameter:
T- The event type- Parameter:
eventClass- The event class to unsubscribe fromhandler- The handler function to remove
-
publish
Publishes an event to all subscribed handlers.This method runs asynchronously if called from a non-main thread, or synchronously if called from the main thread.
- Typparameter:
T- The event type- Parameter:
event- The event to publish
-
clear
public void clear()Clears all handlers for all event types. -
getHandlerCount
Gets the number of handlers for a specific event type.- Typparameter:
T- The event type- Parameter:
eventClass- The event class- Gibt zurück:
- The number of handlers
-