Class ExecutionResult<S extends CommandSource>

java.lang.Object
studio.mevera.imperat.context.ExecutionResult<S>
Type Parameters:
S - the type of command source that extends CommandSource

public final class ExecutionResult<S extends CommandSource> extends Object
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 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 data
      context - the original context
      Returns:
      a new ExecutionResult instance 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 failure
      context - the context
      Returns:
      a new ExecutionResult instance representing failed execution
    • failure

      public static <S extends CommandSource> ExecutionResult<S> failure(CommandContext<S> context)
      Creates a failed execution result without specific error information.
      Type Parameters:
      S - the type of command source
      Parameters:
      context - the context
      Returns:
      a new ExecutionResult instance representing a generic failed execution
    • hasFailed

      public boolean hasFailed()
      Determines whether this execution result represents a failed command execution.
      Returns:
      true if the command execution failed, false if it succeeded
    • getError

      @Nullable public @Nullable Throwable getError()
      Returns the error that caused the command execution to fail, if any.
      Returns:
      the error that caused execution failure, or null
    • getContext

      public CommandContext<S> getContext()
    • getExecutionContext

      public ExecutionContext<S> getExecutionContext()
      Returns the execution context containing command execution data and environment.
      Returns:
      the execution context for successful executions, or null for failed executions