Package com.xpdustry.distributor.event
Interface EventBus
public interface EventBus
The event bus of this server. A better alternative to
Event subscribers registered with this class will not crash the server if an exception is thrown but be logged instead. Subscribers also come with
Events.
Event subscribers registered with this class will not crash the server if an exception is thrown but be logged instead. Subscribers also come with
EventSubscription objects to dynamically unsubscribe them. And also
Priority to make sure your subscribers are called in a specific order.
final EventBus bus = DistributorProvider.get().getEventBus();
final MindustryPlugin plugin = ...;
final EventSubscription subscription = bus.subscribe(EventType.PlayerJoin.class, plugin, event -> {
event.player.sendMessage("Hello " + event.player.name() + "!");
});
// When no longer needed, you can unsubscribe the listener
subscription.unsubscribe();
-
Method Summary
Modifier and TypeMethodDescription<E> voidpost(E event) Posts the event to the arc event bus.<E> voidPosts the event to the arc event bus to the listeners of the given super class.default <E extends Enum<E>>
EventSubscriptionsubscribe(E event, MindustryPlugin plugin, Runnable listener) Subscribe to an event.<E extends Enum<E>>
EventSubscriptionsubscribe(E event, Priority priority, MindustryPlugin plugin, Runnable listener) Subscribe to an event.default <E> EventSubscriptionsubscribe(Class<E> event, MindustryPlugin plugin, Consumer<E> listener) Subscribe to an event.subscribe(Class<E> event, Priority priority, MindustryPlugin plugin, Consumer<E> listener) Subscribe to an event.
-
Method Details
-
subscribe
<E> EventSubscription subscribe(Class<E> event, Priority priority, MindustryPlugin plugin, Consumer<E> listener) Subscribe to an event.- Type Parameters:
E- the type of the event- Parameters:
event- the event class to subscribe topriority- the priority of the listenerplugin- the plugin that owns the listenerlistener- the listener to subscribe- Returns:
- the subscription of the subscribed listener
-
subscribe
default <E> EventSubscription subscribe(Class<E> event, MindustryPlugin plugin, Consumer<E> listener) Subscribe to an event.- Type Parameters:
E- the type of the event- Parameters:
event- the event class to subscribe toplugin- the plugin that owns the listenerlistener- the listener to subscribe- Returns:
- the subscription of the subscribed listener
-
subscribe
<E extends Enum<E>> EventSubscription subscribe(E event, Priority priority, MindustryPlugin plugin, Runnable listener) Subscribe to an event.- Type Parameters:
E- the type of the enum event- Parameters:
event- the event enum to subscribe topriority- the priority of the listenerplugin- the plugin that owns the listenerlistener- the listener to subscribe- Returns:
- the subscription of the subscribed listener
-
subscribe
default <E extends Enum<E>> EventSubscription subscribe(E event, MindustryPlugin plugin, Runnable listener) Subscribe to an event.- Type Parameters:
E- the type of the enum event- Parameters:
event- the event enum to subscribe toplugin- the plugin that owns the listenerlistener- the listener to subscribe- Returns:
- the subscription of the subscribed listener
-
post
<E> void post(E event) Posts the event to the arc event bus.- Type Parameters:
E- the type of the event- Parameters:
event- the event to post
-
post
Posts the event to the arc event bus to the listeners of the given super class.- Type Parameters:
E- the type of the event- Parameters:
clazz- the class of the eventevent- the event to post
-
post
Posts the enum event to the arc event bus.- Type Parameters:
E- the type of the enum event- Parameters:
event- the enum event to post
-