Interface EventBus


public interface EventBus
The event bus of this server. A better alternative to 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 = Distributor.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 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 to
      priority - the priority of the listener
      plugin - the plugin that owns the listener
      listener - 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 to
      plugin - the plugin that owns the listener
      listener - 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 to
      priority - the priority of the listener
      plugin - the plugin that owns the listener
      listener - 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 to
      plugin - the plugin that owns the listener
      listener - 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

      <E> void post(Class<? super E> clazz, E event)
      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 event
      event - the event to post
    • post

      <E extends Enum<E>> void post(E event)
      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