Package kr.toxicity.model.api
Interface BetterModelEventBus
public interface BetterModelEventBus
A central event bus for handling model-related events.
This interface allows subscribing to and publishing ModelEvents.
It serves as a decoupling mechanism between different parts of the engine.
- Since:
- 2.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumRepresents the outcome of an event publication. -
Method Summary
Modifier and TypeMethodDescription<T extends ModelEvent>
@NotNull BetterModelEventBus.ResultPublishes an event to all registered subscribers.default @NotNull BetterModelEventBus.Resultcall(@NotNull ModelEvent event) Publishes an event to all registered subscribers.<T extends ModelEvent>
@NotNull ModelEventListenersubscribe(@NotNull ModelEventApplication application, @NotNull Class<T> eventClass, @NotNull Consumer<T> consumer) Subscribes a consumer to a specific event type.
-
Method Details
-
subscribe
@NotNull <T extends ModelEvent> @NotNull ModelEventListener subscribe(@NotNull @NotNull ModelEventApplication application, @NotNull @NotNull Class<T> eventClass, @NotNull @NotNull Consumer<T> consumer) Subscribes a consumer to a specific event type.- Type Parameters:
T- the type of the event- Parameters:
application- the application that subscribes to the eventeventClass- the class of the event to subscribe toconsumer- the consumer to handle the event- Returns:
- a listener handle that can be used to unregister the subscription
- Since:
- 2.0.0
-
call
@NotNull <T extends ModelEvent> @NotNull BetterModelEventBus.Result call(@NotNull @NotNull Class<? extends T> eventClass, @NotNull @NotNull Supplier<T> eventSupplier) Publishes an event to all registered subscribers.The event is created lazily using the provided supplier if there are subscribers.
- Type Parameters:
T- the type of the event- Parameters:
eventClass- the class of the eventeventSupplier- a supplier that creates the event- Returns:
- the result of the event call
- Since:
- 2.0.0
-
call
Publishes an event to all registered subscribers.- Parameters:
event- the event to publish- Returns:
- the result of the event call
- Since:
- 2.0.0
-