Package com.zetaplugins.zetacore.command
Class CommandContext
java.lang.Object
com.zetaplugins.zetacore.command.CommandContext
Context for a command execution, containing the sender, command, label, and arguments.
-
Constructor Summary
ConstructorsConstructorDescriptionCommandContext(CommandSender sender, Command command, String label, ArgumentList args) -
Method Summary
Modifier and TypeMethodDescriptiongetArgs()Get the arguments passed to the command.Get the command that was executed.getLabel()Get the label (alias) used to execute the command.getPlayer(int index) Get the online player whose exact name is given at the specified argument index.getPlayerOrSender(int index) Get the player given at the specified argument index, or the sender if the argument is missing.Get the sender as a player.Get the sender of the command.
-
Constructor Details
-
CommandContext
-
-
Method Details
-
getSender
Get the sender of the command.- Returns:
- The CommandSender
-
getCommand
Get the command that was executed.- Returns:
- The Command
-
getLabel
Get the label (alias) used to execute the command.- Returns:
- The command label
-
getArgs
Get the arguments passed to the command.- Returns:
- The ArgumentList
-
getPlayerSender
Get the sender as a player.- Returns:
- The sender if it is a player, otherwise empty
-
getPlayer
Get the online player whose exact name is given at the specified argument index.- Parameters:
index- The index of the argument- Returns:
- The player, or empty if the argument is missing or no such player is online
-
getPlayerOrSender
Get the player given at the specified argument index, or the sender if the argument is missing.If the argument is present but no such player is online, the result is empty; it does not fall back to the sender.
Player target = ctx.getPlayerOrSender(0).orElseThrow(CommandSenderMustBeOrSpecifyPlayerException::new);
- Parameters:
index- The index of the argument- Returns:
- The player, the sender if it is a player and the argument is missing, or empty
-