Class EffectDispatchSpine
java.lang.Object
io.artificial.enchantments.internal.EffectDispatchSpine
Central dispatch spine for all enchantment effects.
This class is the single unified coordinator that powers both:
- Typed callbacks - direct invocation of
EnchantmentEffectHandlermethods - Event bus - dispatch of
EnchantEffectEventsubclasses to registered listeners
Both paths flow through this spine to ensure:
- Single point of validation and calculation
- No duplicate effect execution
- Consistent cancellation propagation
- Thread-safe dispatch via FoliaScheduler
Processing order:
- Calculate scaled value using enchantment's
LevelScaling - Create appropriate
EffectContextviaContextFactory - Fire typed callback path (if handler exists)
- Check cancellation - stop if cancelled
- Fire event bus path (if listeners registered)
- Check cancellation after bus
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of all dispatchable event types. -
Constructor Summary
ConstructorsConstructorDescriptionEffectDispatchSpine(@NotNull FoliaScheduler scheduler, @NotNull EnchantmentEventBus eventBus) Creates a new EffectDispatchSpine with the given components.EffectDispatchSpine(@NotNull FoliaScheduler scheduler, @NotNull EnchantmentEventBus eventBus, EffectExecutionContext.ExecutionMode executionMode) Creates a new EffectDispatchSpine with the given components and execution mode. -
Method Summary
Modifier and TypeMethodDescriptionbooleandispatch(@NotNull EnchantmentDefinition enchantment, int level, @NotNull org.bukkit.event.Event bukkitEvent, @Nullable org.bukkit.inventory.EquipmentSlot slot, @NotNull EffectDispatchSpine.DispatchEventType eventType) Dispatches an enchantment effect through both callback and event bus paths.@NotNull ContextFactoryReturns the ContextFactory for creating effect contexts.Gets the current execution mode.@NotNull FoliaSchedulerReturns the FoliaScheduler for scheduling tasks.booleanCheck if the spine has been shut down.voidSets the execution mode for effect handler failures.voidshutdown()Shuts down the dispatch spine, preventing further dispatches.
-
Constructor Details
-
EffectDispatchSpine
public EffectDispatchSpine(@NotNull @NotNull FoliaScheduler scheduler, @NotNull @NotNull EnchantmentEventBus eventBus) Creates a new EffectDispatchSpine with the given components.Defaults to LENIENT execution mode where exceptions in effect handlers are logged but do not prevent other handlers from executing.
- Parameters:
scheduler- the folia scheduler for thread-safe dispatcheventBus- the event bus for dispatching events to listeners
-
EffectDispatchSpine
public EffectDispatchSpine(@NotNull @NotNull FoliaScheduler scheduler, @NotNull @NotNull EnchantmentEventBus eventBus, @NotNull EffectExecutionContext.ExecutionMode executionMode) Creates a new EffectDispatchSpine with the given components and execution mode.- Parameters:
scheduler- the folia scheduler for thread-safe dispatcheventBus- the event bus for dispatching events to listenersexecutionMode- the execution mode (LENIENT or STRICT)
-
-
Method Details
-
dispatch
public boolean dispatch(@NotNull @NotNull EnchantmentDefinition enchantment, int level, @NotNull @NotNull org.bukkit.event.Event bukkitEvent, @Nullable @Nullable org.bukkit.inventory.EquipmentSlot slot, @NotNull @NotNull EffectDispatchSpine.DispatchEventType eventType) Dispatches an enchantment effect through both callback and event bus paths.This is the main entry point for effect dispatch. It coordinates:
- Value calculation via LevelScaling
- Context creation
- Typed callback invocation
- Event bus dispatch
- Cancellation handling
- Parameters:
enchantment- the enchantment definitionlevel- the enchantment levelbukkitEvent- the underlying Bukkit eventslot- the equipment slot where the enchantment is applied (may be null for non-equipment events)eventType- the type of event being dispatched- Returns:
- true if the effect was dispatched successfully, false if cancelled or error occurred
-
getScheduler
Returns the FoliaScheduler for scheduling tasks.- Returns:
- the scheduler
-
getContextFactory
Returns the ContextFactory for creating effect contexts.- Returns:
- the context factory
-
shutdown
public void shutdown()Shuts down the dispatch spine, preventing further dispatches. -
isShutdown
public boolean isShutdown()Check if the spine has been shut down.- Returns:
- true if shutdown
-
getExecutionMode
Gets the current execution mode.- Returns:
- the current execution mode (LENIENT or STRICT)
-
setExecutionMode
Sets the execution mode for effect handler failures.In LENIENT mode (default), exceptions from effect handlers are logged but do not prevent other handlers from executing.
In STRICT mode, exceptions from effect handlers are logged and propagated to stop all further execution. This is useful for debugging.
- Parameters:
mode- the execution mode to set
-