Klasse ZenithEventBus

java.lang.Object
me.kzlyth.api.events.ZenithEventBus

public class ZenithEventBus extends Object
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
  • Methodendetails

    • getInstance

      @NotNull public static @NotNull ZenithEventBus 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 to
      handler - 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 from
      handler - The handler function to remove
    • publish

      public <T extends ZenithEvent> void publish(@NotNull T event)
      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

      public <T extends ZenithEvent> int getHandlerCount(@NotNull @NotNull Class<T> eventClass)
      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