Interface EventBus


public interface EventBus
Publish-subscribe event bus for game events.

Scripts can subscribe to specific event types and receive callbacks when those events are published. All listeners are typed to a specific GameEvent subclass.

Example usage:

eventBus.subscribe(ChatMessageEvent.class, event -> {
    log.info("Chat: {}", event.message().text());
});
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Publishes an event to all registered listeners of its type.
    <T extends GameEvent>
    void
    subscribe(Class<T> eventType, Consumer<T> listener)
    Subscribes a listener to receive events of the specified type.
    <T extends GameEvent>
    void
    unsubscribe(Class<T> eventType, Consumer<T> listener)
    Removes a previously registered listener for the specified event type.
  • Method Details

    • subscribe

      <T extends GameEvent> void subscribe(Class<T> eventType, Consumer<T> listener)
      Subscribes a listener to receive events of the specified type.
      Type Parameters:
      T - the event type
      Parameters:
      eventType - the event class to listen for
      listener - the callback to invoke when an event of this type is published
    • unsubscribe

      <T extends GameEvent> void unsubscribe(Class<T> eventType, Consumer<T> listener)
      Removes a previously registered listener for the specified event type.
      Type Parameters:
      T - the event type
      Parameters:
      eventType - the event class the listener was registered for
      listener - the listener to remove
    • publish

      void publish(GameEvent event)
      Publishes an event to all registered listeners of its type.
      Parameters:
      event - the event to publish