Class CommandContext
java.lang.Object
org.core.command.argument.context.CommandContext
The magic that is the CommandContext. Everything important about the command processing can be found
in this class.
-
Constructor Summary
ConstructorsConstructorDescriptionCommandContext(CommandSource source, Collection<ArgumentCommand> commands, String... command)
-
Method Summary
Modifier and TypeMethodDescription<T> T
getArgument(ArgumentCommand command, String id)
Gets the argument value of the id provided<T> T
getArgument(ArgumentCommand command, CommandArgument<T> id)
Gets the argument value of the command argument providedString[]
Gets the raw string arguments that the command source usedGets the command the user is targetingIf there is a issue with the command the user is attempting to parse, you can get all the errors with this function.Gets all potential commands from what the user has enteredThe source of the commandgetSuggestions(ArgumentCommand command)
Gets the suggestions for the next argument in the command.
-
Constructor Details
-
CommandContext
public CommandContext(CommandSource source, Collection<ArgumentCommand> commands, String... command)- Parameters:
source
- The command source who is running the commandcommands
- The potential commands of the command contextcommand
- The string arguments that the source wrote
-
-
Method Details
-
getArgument
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 targetid
- 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 commandIllegalStateException
- Argument requested is asking for string requirements then what is providedNotEnoughArguments
- If a optional argument fails and is actually required
-
getArgument
Gets the argument value of the id provided- Type Parameters:
T
- The expected type of argument- Parameters:
command
- The command to targetid
- 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 commandIllegalStateException
- Argument requested is asking for string requirements then what is providedNotEnoughArguments
- If a optional argument fails and is actually required
-
getCommand
Gets the raw string arguments that the command source used- Returns:
- A String array of the raw string arguments
-
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
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
Gets all potential commands from what the user has entered- Returns:
- A set of all the potential commands
-
getSource
The source of the command- Returns:
- The command sender
-
getSuggestions
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
-