Class EffectExecutionContext
java.lang.Object
io.artificial.enchantments.internal.EffectExecutionContext
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when strict mode is enabled and an effect handler fails.static enumExecution mode for handling effect handler failures. -
Constructor Summary
ConstructorsConstructorDescriptionEffectExecutionContext(@NotNull EnchantmentDefinition enchantment, EffectDispatchSpine.DispatchEventType eventType, @NotNull EffectExecutionContext.ExecutionMode executionMode) Creates a new execution context from an enchantment definition.EffectExecutionContext(@NotNull org.bukkit.NamespacedKey enchantmentKey, @NotNull String effectType, int level) Creates a new execution context with lenient mode (default).EffectExecutionContext(@NotNull org.bukkit.NamespacedKey enchantmentKey, @NotNull String effectType, int level, @NotNull EffectExecutionContext.ExecutionMode executionMode) Creates a new execution context. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanexecuteLenient(@Nullable Class<?> handlerClass, @NotNull Runnable action) Executes the given runnable with exception isolation, using lenient mode by default.booleanexecuteWithIsolation(@Nullable Class<?> handlerClass, @NotNull Runnable action) Executes the given runnable with exception isolation.@NotNull StringGets the effect type.@NotNull org.bukkit.NamespacedKeyGets the enchantment key.@NotNull EffectExecutionContext.ExecutionModeGets the execution mode.intgetLevel()Gets the enchantment level.@NotNull StringGets a quick log message prefix for use in logging.inthashCode()toString()@NotNull EffectExecutionContextwithExecutionMode(@NotNull EffectExecutionContext.ExecutionMode mode) Returns a new context with the specified execution mode.@NotNull EffectExecutionContextwithLevel(int level) Returns a new context with the specified level.
-
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 keyeffectType- the type of effect being executed (e.g., "ENTITY_DAMAGE_BY_ENTITY")level- the enchantment levelexecutionMode- 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 keyeffectType- the type of effect being executedlevel- 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 definitioneventType- the dispatch event typeexecutionMode- 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
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
Gets the effect type.- Returns:
- the type of effect being executed
-
getLevel
public int getLevel()Gets the enchantment level.- Returns:
- the enchantment level
-
getExecutionMode
Gets the execution mode.- Returns:
- the current execution mode
-
withLevel
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
-
hashCode
public int hashCode() -
toString
-