Package io.artificial.enchantments.api
Interface EnchantmentEventBus
- All Known Implementing Classes:
EnchantmentEventBusImpl
public interface EnchantmentEventBus
Event bus for subscribing to enchantment-triggered effects.
This interface provides a publish-subscribe mechanism for listening to enchantment effects. Events are dispatched through the same spine as typed callbacks, ensuring consistent behavior regardless of which approach you use.
Dispatch Rules:
- Typed callbacks fire first (from
EnchantmentEffectHandler) - Event bus listeners fire second
- Cancellation stops both paths when detected
- Listeners can modify event data that syncs back to the context
Example Usage:
// Register a listener for combat events
EventSubscription<CombatEvent> sub = api.getEventBus().register(
plugin,
CombatEvent.class,
EventPriority.NORMAL,
event -> {
// Only handle our custom enchant
if (!event.getEnchantment().getKey().equals(MY_ENCHANT_KEY)) return;
// Modify the final damage
double multiplier = event.getScaledValue();
event.setFinalDamage(event.getFinalDamage() * multiplier);
}
);
// Unsubscribe later
sub.unsubscribe();
- Since:
- 0.1.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents a subscription to an event type. -
Method Summary
Modifier and TypeMethodDescription<T extends EnchantEffectEvent>
TDispatches an event created by a factory function.<T extends EnchantEffectEvent>
Tdispatch(T event) Dispatches an event to all registered handlers.<T extends EnchantEffectEvent>
@NotNull EnchantmentEventBus.EventSubscription<T> register(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Class<T> eventType, @NotNull Consumer<T> handler) Registers a simple event handler with default priority and cancellation handling.<T extends EnchantEffectEvent>
@NotNull EnchantmentEventBus.EventSubscription<T> register(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Class<T> eventType, @NotNull org.bukkit.event.EventPriority priority, boolean ignoreCancelled, @NotNull Consumer<T> handler) Registers an event handler with full control over priority and cancellation.<T extends EnchantEffectEvent>
@NotNull EnchantmentEventBus.EventSubscription<T> register(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Class<T> eventType, @NotNull org.bukkit.event.EventPriority priority, @NotNull Consumer<T> handler) Registers an event handler with specific priority.<T extends EnchantEffectEvent>
voidunregister(@NotNull EnchantmentEventBus.EventSubscription<T> subscription) Unregisters a specific subscription.voidunregisterAll(@NotNull org.bukkit.plugin.Plugin plugin) Unregisters all handlers for a plugin.
-
Method Details
-
register
@NotNull <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) Registers a simple event handler with default priority and cancellation handling.- 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
- Since:
- 0.1.0
-
register
@NotNull <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) Registers an event handler with specific priority.- 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
- Since:
- 0.1.0
-
register
@NotNull <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) Registers an event handler with full control over priority and cancellation.- 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 eventshandler- the handler to invoke (must not be null)- Returns:
- a subscription object for later unsubscription
- Since:
- 0.1.0
-
unregisterAll
void unregisterAll(@NotNull @NotNull org.bukkit.plugin.Plugin plugin) Unregisters all handlers for a plugin.- Parameters:
plugin- the plugin to unregister (must not be null)- Since:
- 0.1.0
-
unregister
<T extends EnchantEffectEvent> void unregister(@NotNull @NotNull EnchantmentEventBus.EventSubscription<T> subscription) Unregisters a specific subscription.- Type Parameters:
T- the event type- Parameters:
subscription- the subscription to cancel (must not be null)- Since:
- 0.1.0
-
dispatch
Dispatches an event to all registered handlers.Typically called internally by the library. Plugins can use this for testing or custom event scenarios.
- 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)
- Since:
- 0.1.0
-
dispatch
@NotNull <T extends EnchantEffectEvent> T dispatch(@NotNull @NotNull Class<T> type, @NotNull Supplier<T> factory) Dispatches an event created by a factory function.Convenience method that creates and dispatches in one call.
- 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
- Since:
- 0.1.0
-