Class CommandContext

java.lang.Object
com.ultikits.ultitools.abstracts.command.CommandContext

public final class CommandContext extends Object
Immutable command execution context containing all information about a command invocation. This class follows the Context Object pattern, encapsulating command execution data.

不可变的命令执行上下文,包含命令调用的所有信息。 此类遵循上下文对象模式,封装命令执行数据。

Since:
6.2.0
Version:
2.0.0
Author:
wisdomme
  • Field Details

    • sender

      private final org.bukkit.command.CommandSender sender
      The sender of the command. 命令的发送者。
    • command

      private final org.bukkit.command.Command command
      The Bukkit command object. Bukkit 命令对象。
    • alias

      private final String alias
      The alias used to invoke the command. 用于调用命令的别名。
    • rawArgs

      private final String[] rawArgs
      The raw arguments passed to the command. 传递给命令的原始参数。
    • parsedParams

      private final Map<String,String[]> parsedParams
      The parsed parameters mapped by their names. 按名称映射的已解析参数。
    • matchedMethod

      @Nullable private final Method matchedMethod
      The matched method for execution. 匹配的执行方法。
    • matchedFormat

      @Nullable private final String matchedFormat
      The format string of the matched command. 匹配命令的格式字符串。
    • timestamp

      private final long timestamp
      Timestamp when the command was received. 命令接收的时间戳。
  • Constructor Details

    • CommandContext

      public CommandContext()
  • Method Details

    • isPlayer

      public boolean isPlayer()
      Checks if the sender is a player. 检查发送者是否为玩家。
      Returns:
      true if sender is a player, false otherwise
    • getPlayer

      @Nullable public org.bukkit.entity.Player getPlayer()
      Gets the sender as a player. 获取作为玩家的发送者。
      Returns:
      the player, or null if sender is not a player
    • getArgCount

      public int getArgCount()
      Gets the number of arguments. 获取参数数量。
      Returns:
      the number of raw arguments
    • getArg

      @Nullable public String getArg(int index)
      Gets an argument at the specified index. 获取指定索引处的参数。
      Parameters:
      index - the argument index (0-based)
      Returns:
      the argument value, or null if index is out of bounds
    • getParam

      @Nullable public String[] getParam(String name)
      Gets a parsed parameter by name. 按名称获取已解析的参数。
      Parameters:
      name - the parameter name
      Returns:
      the parameter values, or null if not found
    • getParamValue

      @Nullable public String getParamValue(String name)
      Gets a single parsed parameter value by name. 按名称获取单个已解析的参数值。
      Parameters:
      name - the parameter name
      Returns:
      the first parameter value, or null if not found
    • withParsedParams

      public CommandContext withParsedParams(Map<String,String[]> params)
      Creates a new context with additional parsed parameters. 创建带有附加已解析参数的新上下文。
      Parameters:
      params - the parameters to add
      Returns:
      a new context with the merged parameters
    • withMatchedMethod

      public CommandContext withMatchedMethod(Method method, String format)
      Creates a new context with a matched method. 创建带有匹配方法的新上下文。
      Parameters:
      method - the matched method
      format - the command format
      Returns:
      a new context with the matched method