Class CommandContext

java.lang.Object
org.core.command.argument.context.CommandContext

public class CommandContext extends Object
The magic that is the CommandContext. Everything important about the command processing can be found in this class.
  • Constructor Details

    • CommandContext

      public CommandContext(CommandSource source, Collection<ArgumentCommand> commands, String... command)
      Parameters:
      source - The command source who is running the command
      commands - The potential commands of the command context
      command - The string arguments that the source wrote
  • Method Details

    • getArgument

      public <T> T getArgument(ArgumentCommand command, CommandArgument<T> id) throws NotEnoughArguments
      Gets the argument value of the command argument provided
      Type Parameters:
      T - The expected type of argument (by providing the command argument, the type will be the same unless the argument is breaking the standard)
      Parameters:
      command - The command to target
      id - The command argument that should be used
      Returns:
      The value of the argument
      Throws:
      IllegalArgumentException - If the provided id argument is not part of the command
      IllegalStateException - Argument requested is asking for string requirements then what is provided
      NotEnoughArguments - If a optional argument fails and is actually required
    • getArgument

      public <T> T getArgument(ArgumentCommand command, String id) throws NotEnoughArguments
      Gets the argument value of the id provided
      Type Parameters:
      T - The expected type of argument
      Parameters:
      command - The command to target
      id - The id of the argument to get
      Returns:
      The value of the argument
      Throws:
      IllegalArgumentException - If the provided id argument is not part of the command
      IllegalStateException - Argument requested is asking for string requirements then what is provided
      NotEnoughArguments - If a optional argument fails and is actually required
    • getCommand

      public String[] getCommand()
      Gets the raw string arguments that the command source used
      Returns:
      A String array of the raw string arguments
    • getCompleteCommand

      public Optional<ArgumentCommand> getCompleteCommand()
      Gets the command the user is targeting
      Returns:
      A single argument command, if none can be found then Optional.empty() will be used
    • getErrors

      public Set<ErrorContext> getErrors()
      If there is a issue with the command the user is attempting to parse, you can get all the errors with this function. The error is not specific to the command argument
      Returns:
      A set of all errors
    • getPotentialCommands

      public Set<ArgumentCommand> getPotentialCommands()
      Gets all potential commands from what the user has entered
      Returns:
      A set of all the potential commands
    • getSource

      public CommandSource getSource()
      The source of the command
      Returns:
      The command sender
    • getSuggestions

      public Collection<String> getSuggestions(ArgumentCommand command)
      Gets the suggestions for the next argument in the command. This is based upon the argument command provided as well as the raw string arguments. The suggestion will be to the last of the raw string argument
      Parameters:
      command - The command to target
      Returns:
      A list of suggestions for the current context and provided command