Interface ExecutionContext<S extends CommandSource>

Type Parameters:
S - the type of the command source/sender
All Superinterfaces:
CommandContext<S>

@AvailableSince("1.0.0") public interface ExecutionContext<S extends CommandSource> extends CommandContext<S>
Represents the execution context for a command, responsible for resolving and managing command arguments, flags, and their values during command execution.

This interface serves as the bridge between raw command input and executable command logic by:

  • Resolving string inputs into typed values
  • Managing command flags and their values
  • Caching resolved arguments for execution
  • Tracking the command execution path

Each Command maintains its own context, allowing subcommands to have independent argument resolution while preserving the full execution chain.

Since:
1.0.0
See Also:
  • Method Details

    • getTreeExecutionResult

      @NotNull @NotNull TreeExecutionResult<S> getTreeExecutionResult()
    • setDetectedPathway

      void setDetectedPathway(CommandPathway<S> pathway)
    • handleRemainingParsing

      void handleRemainingParsing(TreeExecutionResult<S> result) throws CommandException
      Throws:
      CommandException
    • getFlag

      Optional<ParsedFlagArgument<S>> getFlag(String flagName)
      Retrieves a flag by its name if it was provided in the command input.
      Parameters:
      flagName - the name of the flag (without prefix)
      Returns:
      an Optional containing the flag if present, empty otherwise
    • getFlagValue

      @Nullable <T> T getFlagValue(String flagName)
      Gets the resolved value of a command flag.
      Type Parameters:
      T - the type of the flag value
      Parameters:
      flagName - the name of the flag (without prefix)
      Returns:
      the resolved flag value, or null if:
      • The flag is a switch (no value)
      • The flag wasn't provided
      • The value couldn't be resolved
    • getArgument

      @Nullable <T> T getArgument(String name)
      Gets a resolved command argument by its parameter name.
      Type Parameters:
      T - the type of the argument value
      Parameters:
      name - the parameter name defined in the CommandPathway
      Returns:
      the resolved argument value, or null if not provided or couldn't be resolved
      See Also:
    • getArgumentOr

      @NotNull default <T> T getArgumentOr(String name, T value)
      Gets a resolved argument or returns a default value if not present.
      Type Parameters:
      T - the type of the argument value
      Parameters:
      name - the parameter name
      value - the default value to return if argument isn't present
      Returns:
      the resolved argument value or the default value
    • getRawArgument

      default String getRawArgument(int index)
      Gets the raw string input for an argument by its position.
      Parameters:
      index - the zero-based position of the argument in the command input
      Returns:
      the raw argument string, or null if index is out of bounds
    • provideSource

      @NotNull <R> R provideSource(Type type) throws CommandException
      Resolves the command source into a different type using the configured source resolver.
      Type Parameters:
      R - the target type to resolve to
      Parameters:
      type - the target type class
      Returns:
      the resolved source, never null
      Throws:
      CommandException - if resolution fails
      See Also:
    • getContextArgument

      @Nullable <T> T getContextArgument(Class<T> type) throws CommandException
      Gets an argument resolved by the context resolver system.
      Type Parameters:
      T - the type of the argument
      Parameters:
      type - the class of the argument type
      Returns:
      the resolved argument value, or null if not resolvable
      Throws:
      CommandException - if resolution fails
      See Also:
    • getResolvedFlags

      Collection<? extends ParsedFlagArgument> getResolvedFlags()
      Gets all flags that were resolved from the command input.
      Returns:
      a collection of resolved flags
    • parseArgument

      <T> void parseArgument(Cursor<S> stream, @Nullable T value) throws CommandException
      Resolves and registers a command argument.
      Type Parameters:
      T - the type of the argument value
      Parameters:
      stream - the stream having the current input's data.
      value - the resolved value.
      Throws:
      CommandException - if resolution fails.
    • parseArgument

      void parseArgument(ParsedArgument<S> argument) throws CommandException
      Registers a resolved argument in the context.
      Parameters:
      argument - the resolved argument to register
      Throws:
      CommandException
    • resolveFlag

      void resolveFlag(ParsedFlagArgument<S> flag) throws CommandException
      Registers a resolved flag in the context.
      Parameters:
      flag - the resolved flag to register
      Throws:
      CommandException
    • getLastUsedCommand

      Command<S> getLastUsedCommand()
      Gets the most specific command that was resolved in this context.
      Returns:
      the terminal command that will be executed
    • getDetectedPathway

      CommandPathway<S> getDetectedPathway()
      Gets the command usage pattern that matched the input.
      Returns:
      the detected command usage
    • getParsedArgument

      @Nullable @Nullable ParsedArgument<S> getParsedArgument(Command<S> command, String name)
      Gets a resolved argument by its owning command and parameter name.
      Parameters:
      command - the owning command
      name - the parameter name
      Returns:
      the resolved argument, or null if not present
    • getParsedArgument

      @Nullable @Nullable ParsedArgument<S> getParsedArgument(String argumentName)
    • getParsedArguments

      List<ParsedArgument<S>> getParsedArguments(Command<S> command)
      Gets all resolved arguments for a specific command.
      Parameters:
      command - the owning command
      Returns:
      a list of resolved arguments in declaration order
    • getCommandsUsed

      @NotNull @NotNull Iterable<? extends Command<S>> getCommandsUsed()
      Gets all commands in the resolution path.
      Returns:
      an iterable of all commands from root to terminal command
    • getParsedArguments

      Collection<? extends ParsedArgument<S>> getParsedArguments()
      Gets all resolved arguments in input order.
      Returns:
      a collection of arguments in the order they appeared in the input
    • hasResolvedFlag

      default boolean hasResolvedFlag(Argument<S> currentParameter)
      Checks if a flag parameter was resolved in this context.
      Parameters:
      currentParameter - the flag parameter to check
      Returns:
      true if the flag was provided and resolved
    • hasResolvedFlag

      boolean hasResolvedFlag(FlagData<S> flagData)
      Checks if a flag was resolved in this context.
      Parameters:
      flagData - the flag definition to check
      Returns:
      true if the flag was provided and resolved
    • debug

      void debug()
      Debugs the current resolved arguments cached/mapped.
      This requires ImperatDebugger to be enabled.
      Example: ImperatDebugger.setEnabled(true)
    • setTreeResult

      void setTreeResult(TreeExecutionResult<S> treeResult)