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 TypeMethodDescriptionvoidPublishes an event to all registered listeners of its type.<T extends GameEvent>
voidSubscribes a listener to receive events of the specified type.<T extends GameEvent>
voidunsubscribe(Class<T> eventType, Consumer<T> listener) Removes a previously registered listener for the specified event type.
-
Method Details
-
subscribe
Subscribes a listener to receive events of the specified type.- Type Parameters:
T- the event type- Parameters:
eventType- the event class to listen forlistener- the callback to invoke when an event of this type is published
-
unsubscribe
-
publish
Publishes an event to all registered listeners of its type.- Parameters:
event- the event to publish
-