Class EnchantmentEventBusImpl

java.lang.Object
io.artificial.enchantments.internal.EnchantmentEventBusImpl
All Implemented Interfaces:
EnchantmentEventBus

public class EnchantmentEventBusImpl extends Object implements EnchantmentEventBus
Implementation of EnchantmentEventBus.

Provides thread-safe subscription management using ConcurrentHashMap and CopyOnWriteArrayList. Subscriptions are sorted by EventPriority ordinal during dispatch.

Since:
0.2.0
  • Constructor Details

    • EnchantmentEventBusImpl

      public EnchantmentEventBusImpl()
      Creates a new enchantment event bus.
      Since:
      0.2.0
  • Method Details

    • register

      @NotNull public <T extends EnchantEffectEvent> @NotNull EnchantmentEventBus.EventSubscription<T> register(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Class<T> eventType, @NotNull @NotNull Consumer<T> handler)
      Description copied from interface: EnchantmentEventBus
      Registers a simple event handler with default priority and cancellation handling.
      Specified by:
      register in interface EnchantmentEventBus
      Type Parameters:
      T - the event type
      Parameters:
      plugin - the plugin registering the handler (must not be null)
      eventType - the event class to listen for (must not be null)
      handler - the handler to invoke (must not be null)
      Returns:
      a subscription object for later unsubscription
    • register

      @NotNull public <T extends EnchantEffectEvent> @NotNull EnchantmentEventBus.EventSubscription<T> register(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Class<T> eventType, @NotNull @NotNull org.bukkit.event.EventPriority priority, @NotNull @NotNull Consumer<T> handler)
      Description copied from interface: EnchantmentEventBus
      Registers an event handler with specific priority.
      Specified by:
      register in interface EnchantmentEventBus
      Type Parameters:
      T - the event type
      Parameters:
      plugin - the plugin registering the handler (must not be null)
      eventType - the event class to listen for (must not be null)
      priority - the Bukkit event priority (must not be null)
      handler - the handler to invoke (must not be null)
      Returns:
      a subscription object for later unsubscription
    • register

      @NotNull public <T extends EnchantEffectEvent> @NotNull EnchantmentEventBus.EventSubscription<T> register(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Class<T> eventType, @NotNull @NotNull org.bukkit.event.EventPriority priority, boolean ignoreCancelled, @NotNull @NotNull Consumer<T> handler)
      Description copied from interface: EnchantmentEventBus
      Registers an event handler with full control over priority and cancellation.
      Specified by:
      register in interface EnchantmentEventBus
      Type Parameters:
      T - the event type
      Parameters:
      plugin - the plugin registering the handler (must not be null)
      eventType - the event class to listen for (must not be null)
      priority - the Bukkit event priority (must not be null)
      ignoreCancelled - if true, handler won't fire for cancelled events
      handler - the handler to invoke (must not be null)
      Returns:
      a subscription object for later unsubscription
    • unregisterAll

      public void unregisterAll(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      Description copied from interface: EnchantmentEventBus
      Unregisters all handlers for a plugin.
      Specified by:
      unregisterAll in interface EnchantmentEventBus
      Parameters:
      plugin - the plugin to unregister (must not be null)
    • unregister

      public <T extends EnchantEffectEvent> void unregister(@NotNull @NotNull EnchantmentEventBus.EventSubscription<T> subscription)
      Description copied from interface: EnchantmentEventBus
      Unregisters a specific subscription.
      Specified by:
      unregister in interface EnchantmentEventBus
      Type Parameters:
      T - the event type
      Parameters:
      subscription - the subscription to cancel (must not be null)
    • dispatch

      @NotNull public <T extends EnchantEffectEvent> T dispatch(@NotNull T event)
      Description copied from interface: EnchantmentEventBus
      Dispatches an event to all registered handlers.

      Typically called internally by the library. Plugins can use this for testing or custom event scenarios.

      Specified by:
      dispatch in interface EnchantmentEventBus
      Type Parameters:
      T - the event type
      Parameters:
      event - the event to dispatch (must not be null)
      Returns:
      the dispatched event (may be modified by handlers)
    • dispatch

      @NotNull public <T extends EnchantEffectEvent> T dispatch(@NotNull @NotNull Class<T> type, @NotNull Supplier<T> factory)
      Description copied from interface: EnchantmentEventBus
      Dispatches an event created by a factory function.

      Convenience method that creates and dispatches in one call.

      Specified by:
      dispatch in interface EnchantmentEventBus
      Type Parameters:
      T - the event type
      Parameters:
      type - the event class (must not be null)
      factory - the factory to create the event (must not be null)
      Returns:
      the dispatched event