Class CommandContext

java.lang.Object
com.zetaplugins.zetacore.command.CommandContext

public class CommandContext extends Object
Context for a command execution, containing the sender, command, label, and arguments.
  • Constructor Details

  • Method Details

    • getSender

      public CommandSender getSender()
      Get the sender of the command.
      Returns:
      The CommandSender
    • getCommand

      public Command getCommand()
      Get the command that was executed.
      Returns:
      The Command
    • getLabel

      public String getLabel()
      Get the label (alias) used to execute the command.
      Returns:
      The command label
    • getArgs

      public ArgumentList getArgs()
      Get the arguments passed to the command.
      Returns:
      The ArgumentList
    • getPlayerSender

      public Optional<Player> getPlayerSender()
      Get the sender as a player.
      Returns:
      The sender if it is a player, otherwise empty
    • getPlayer

      public Optional<Player> getPlayer(int index)
      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

      public Optional<Player> getPlayerOrSender(int index)
      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