Contents
Class CommandContext
java.lang.Object
com.hypixel.hytale.server.core.command.system.CommandContext
Holds data in the context of an in-progress command execution, such as the input,
the sender, and the parsed values of arguments. This class also handles the parsing
and validation of arguments.
A CommandContext is similar to a ParserContext except it is within the context of the command, as opposed to the system as a whole. Where a ParserContext is before the command is chosen, a CommandContext is created after the command is chosen. A ParserContext is used to create a CommandContext.
-
Constructor Summary
ConstructorsConstructorDescriptionCommandContext(AbstractCommand calledCommand, CommandSender sender, String inputString) Default Constructor for aCommandContextinstance. -
Method Summary
Modifier and TypeMethodDescription<DataType> DataTypeReturn the value relating to the specified argument, parsed byappendArgumentData(Argument, String[], boolean, ParseResult).String[]Get the actual input String(s) associated with this argument, in case you want to do some parsing yourself or use them for another system.booleanisPlayer()booleanCheck if anArgumentis provided on this command context.sender()<T extends CommandSender>
TCalled to fetch the command sender as a specific type.voidsendMessage(Message message) Called to send a message to the command sender.
-
Constructor Details
-
CommandContext
public CommandContext(@Nonnull AbstractCommand calledCommand, @Nonnull CommandSender sender, @Nonnull String inputString) Default Constructor for aCommandContextinstance.- Parameters:
calledCommand- The command instance that was called.sender- The sender that called the command.inputString- The full input string that called the command.
-
-
Method Details
-
get
Return the value relating to the specified argument, parsed byappendArgumentData(Argument, String[], boolean, ParseResult).Note: If you are using an
OptionalArgyou should useArgument.provided(CommandContext)before fetching, or else you will get an unexpected null value- Type Parameters:
DataType- The Type to return.- Parameters:
argument- The argument to parse.- Returns:
- the parse result of the argument, or
nullif not specified or no default value.
-
getInput
Get the actual input String(s) associated with this argument, in case you want to do some parsing yourself or use them for another system.- Parameters:
argument- The argument to get the input String(s) from.- Returns:
- the input String(s) of this argument.
-
provided
Check if anArgumentis provided on this command context. Never needs to be used for provided arguments.- Parameters:
argument- the argument to check if it is provided or not.- Returns:
trueif the argument is provided on this context,falseotherwise.
-
getInputString
- Returns:
- the cleaned input string that called this command.
-
sendMessage
Called to send a message to the command sender.- Parameters:
message- The message to send.
-
isPlayer
public boolean isPlayer()- Returns:
trueif the sender is a player,falseotherwise.
-
senderAs
Called to fetch the command sender as a specific type.- Type Parameters:
T- The type of the command sender.- Parameters:
senderType- The class type to cast the sender to.- Returns:
- the command sender as the specified type, or throws a
SenderTypeExceptionif the sender is not of the specified type.
-
senderAsPlayerRef
- Returns:
- the entity reference of the command sender, or
nullif the sender is not a player.
-
sender
- Returns:
- the command sender of this command context.
-
getCalledCommand
- Returns:
- the command that was called to create this context.
-