Class EventBus

java.lang.Object
com.ultikits.ultitools.events.EventBus

public class EventBus extends Object
Central event bus for inter-module communication. Supports sync and async dispatch, annotation and programmatic subscriptions.

模块间通信的中央事件总线。 支持同步和异步分发、注解和编程式订阅。

Since:
6.2.2
  • Field Details

  • Constructor Details

    • EventBus

      public EventBus()
  • Method Details

    • register

      public void register(Class<? extends ModuleEvent> eventType, EventPriority priority, boolean ignoreCancelled, String ownerModule, Method method, Object instance)
      Register an annotation-based handler.
    • subscribe

      public <T extends ModuleEvent> Subscription subscribe(Class<T> eventType, Consumer<T> consumer)
      Register a programmatic handler. Returns a Subscription for manual unsubscribe.
    • subscribe

      public <T extends ModuleEvent> Subscription subscribe(Class<T> eventType, EventPriority priority, boolean ignoreCancelled, String ownerModule, Consumer<T> consumer)
      Register a programmatic handler with full options.
    • unregisterAll

      public void unregisterAll(String moduleName)
      Unregister all handlers owned by a module.
    • publish

      public void publish(ModuleEvent event)
      Publish an event synchronously. Handlers run on the calling thread in priority order.
    • publishAsync

      public void publishAsync(ModuleEvent event)
      Publish an event asynchronously. Handlers run on a worker thread. Cancellable events are rejected — cancellation is only meaningful for sync dispatch.
    • shutdown

      public void shutdown()
      Shutdown the async thread pool. Called on plugin disable.
    • collectHandlers

      private List<HandlerEntry> collectHandlers(Class<? extends ModuleEvent> eventType)
      Collect all handlers matching the event type (including superclass handlers), sorted by priority.
    • invokeHandler

      private void invokeHandler(HandlerEntry entry, ModuleEvent event)