Class EffectExecutionContext

java.lang.Object
io.artificial.enchantments.internal.EffectExecutionContext

public final class EffectExecutionContext extends Object
Context wrapper for executing enchantment effect handlers with exception isolation.

This class encapsulates all information needed to execute an effect handler and provides consistent exception handling with detailed logging. It ensures that exceptions from one handler do not prevent other handlers from executing.

Execution modes:

  • LENIENT (default): Log exceptions and continue with remaining handlers
  • STRICT: Log exceptions and propagate to stop all further execution

All logged errors include:

  • Enchantment key (namespaced)
  • Effect event type
  • Handler class name
  • Exception message and stack trace
  • Enchantment level (if applicable)
Since:
1.0.0
See Also:
  • Constructor Details

    • EffectExecutionContext

      public EffectExecutionContext(@NotNull @NotNull org.bukkit.NamespacedKey enchantmentKey, @NotNull @NotNull String effectType, int level, @NotNull @NotNull EffectExecutionContext.ExecutionMode executionMode)
      Creates a new execution context.
      Parameters:
      enchantmentKey - the enchantment's namespaced key
      effectType - the type of effect being executed (e.g., "ENTITY_DAMAGE_BY_ENTITY")
      level - the enchantment level
      executionMode - the execution mode for error handling
    • EffectExecutionContext

      public EffectExecutionContext(@NotNull @NotNull org.bukkit.NamespacedKey enchantmentKey, @NotNull @NotNull String effectType, int level)
      Creates a new execution context with lenient mode (default).
      Parameters:
      enchantmentKey - the enchantment's namespaced key
      effectType - the type of effect being executed
      level - the enchantment level
    • EffectExecutionContext

      public EffectExecutionContext(@NotNull @NotNull EnchantmentDefinition enchantment, @NotNull EffectDispatchSpine.DispatchEventType eventType, @NotNull @NotNull EffectExecutionContext.ExecutionMode executionMode)
      Creates a new execution context from an enchantment definition.
      Parameters:
      enchantment - the enchantment definition
      eventType - the dispatch event type
      executionMode - the execution mode
  • Method Details

    • executeWithIsolation

      public boolean executeWithIsolation(@Nullable @Nullable Class<?> handlerClass, @NotNull @NotNull Runnable action)
      Executes the given runnable with exception isolation.

      In LENIENT mode, exceptions are caught, logged, and the method returns normally. In STRICT mode, exceptions are caught, logged, and then re-thrown.

      Parameters:
      handlerClass - the class of the handler being invoked (for logging)
      action - the action to execute
      Returns:
      true if execution succeeded without exception, false if an exception was caught
    • executeLenient

      public boolean executeLenient(@Nullable @Nullable Class<?> handlerClass, @NotNull @NotNull Runnable action)
      Executes the given runnable with exception isolation, using lenient mode by default.
      Parameters:
      handlerClass - the class of the handler being invoked (for logging)
      action - the action to execute
      Returns:
      true if execution succeeded without exception, false if an exception was caught
    • getLogPrefix

      @NotNull public @NotNull String getLogPrefix()
      Gets a quick log message prefix for use in logging.
      Returns:
      a formatted prefix string with enchantment key and effect type
    • getEnchantmentKey

      @NotNull public @NotNull org.bukkit.NamespacedKey getEnchantmentKey()
      Gets the enchantment key.
      Returns:
      the enchantment's namespaced key
    • getEffectType

      @NotNull public @NotNull String getEffectType()
      Gets the effect type.
      Returns:
      the type of effect being executed
    • getLevel

      public int getLevel()
      Gets the enchantment level.
      Returns:
      the enchantment level
    • getExecutionMode

      @NotNull public @NotNull EffectExecutionContext.ExecutionMode getExecutionMode()
      Gets the execution mode.
      Returns:
      the current execution mode
    • withLevel

      @NotNull public @NotNull EffectExecutionContext withLevel(int level)
      Returns a new context with the specified level.
      Parameters:
      level - the enchantment level
      Returns:
      a new context with the updated level
    • withExecutionMode

      @NotNull public @NotNull EffectExecutionContext withExecutionMode(@NotNull @NotNull EffectExecutionContext.ExecutionMode mode)
      Returns a new context with the specified execution mode.
      Parameters:
      mode - the execution mode
      Returns:
      a new context with the updated mode
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object