Package studio.mevera.imperat.context
Class ExecutionResult<S extends CommandSource>
java.lang.Object
studio.mevera.imperat.context.ExecutionResult<S>
- Type Parameters:
S- the type of command source that extendsCommandSource
Represents the result of a command execution operation in the Imperat framework.
This class follows a Result/Either pattern, encapsulating either a successful command execution with its associated context, or a failure state with error information.
Thread Safety: This class is immutable and thread-safe once constructed.
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <S extends CommandSource>
ExecutionResult<S>failure(@Nullable Throwable error, CommandContext<S> context) Creates a failed execution result with the provided error information.static <S extends CommandSource>
ExecutionResult<S>failure(CommandContext<S> context) Creates a failed execution result without specific error information.@Nullable ThrowablegetError()Returns the error that caused the command execution to fail, if any.Returns the execution context containing command execution data and environment.booleanDetermines whether this execution result represents a failed command execution.static <S extends CommandSource>
ExecutionResult<S>of(ExecutionContext<S> executionContext, CommandContext<S> context) Creates a successful execution result.
-
Method Details
-
of
public static <S extends CommandSource> ExecutionResult<S> of(ExecutionContext<S> executionContext, CommandContext<S> context) Creates a successful execution result.- Type Parameters:
S- the type of command source- Parameters:
executionContext- the execution context containing command execution datacontext- the original context- Returns:
- a new
ExecutionResultinstance representing successful execution
-
failure
public static <S extends CommandSource> ExecutionResult<S> failure(@Nullable @Nullable Throwable error, CommandContext<S> context) Creates a failed execution result with the provided error information.- Type Parameters:
S- the type of command source- Parameters:
error- the exception that caused the failurecontext- the context- Returns:
- a new
ExecutionResultinstance representing failed execution
-
failure
Creates a failed execution result without specific error information.- Type Parameters:
S- the type of command source- Parameters:
context- the context- Returns:
- a new
ExecutionResultinstance representing a generic failed execution
-
hasFailed
public boolean hasFailed()Determines whether this execution result represents a failed command execution.- Returns:
trueif the command execution failed,falseif it succeeded
-
getError
Returns the error that caused the command execution to fail, if any.- Returns:
- the error that caused execution failure, or
null
-
getContext
-
getExecutionContext
Returns the execution context containing command execution data and environment.- Returns:
- the execution context for successful executions,
or
nullfor failed executions
-