Class CommandContext
java.lang.Object
com.ultikits.ultitools.abstracts.command.CommandContext
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final StringThe alias used to invoke the command.private final org.bukkit.command.CommandThe Bukkit command object.private final StringThe format string of the matched command.private final MethodThe matched method for execution.The parsed parameters mapped by their names.private final String[]The raw arguments passed to the command.private final org.bukkit.command.CommandSenderThe sender of the command.private final longTimestamp when the command was received. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetArg(int index) Gets an argument at the specified index.intGets the number of arguments.String[]Gets a parsed parameter by name.getParamValue(String name) Gets a single parsed parameter value by name.org.bukkit.entity.PlayerGets the sender as a player.booleanisPlayer()Checks if the sender is a player.withMatchedMethod(Method method, String format) Creates a new context with a matched method.withParsedParams(Map<String, String[]> params) Creates a new context with additional parsed parameters.
-
Field Details
-
sender
private final org.bukkit.command.CommandSender senderThe sender of the command. 命令的发送者。 -
command
private final org.bukkit.command.Command commandThe Bukkit command object. Bukkit 命令对象。 -
alias
The alias used to invoke the command. 用于调用命令的别名。 -
rawArgs
The raw arguments passed to the command. 传递给命令的原始参数。 -
parsedParams
The parsed parameters mapped by their names. 按名称映射的已解析参数。 -
matchedMethod
The matched method for execution. 匹配的执行方法。 -
matchedFormat
The format string of the matched command. 匹配命令的格式字符串。 -
timestamp
private final long timestampTimestamp 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
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
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
Gets a parsed parameter by name. 按名称获取已解析的参数。- Parameters:
name- the parameter name- Returns:
- the parameter values, or null if not found
-
getParamValue
Gets a single parsed parameter value by name. 按名称获取单个已解析的参数值。- Parameters:
name- the parameter name- Returns:
- the first parameter value, or null if not found
-
withParsedParams
Creates a new context with additional parsed parameters. 创建带有附加已解析参数的新上下文。- Parameters:
params- the parameters to add- Returns:
- a new context with the merged parameters
-
withMatchedMethod
Creates a new context with a matched method. 创建带有匹配方法的新上下文。- Parameters:
method- the matched methodformat- the command format- Returns:
- a new context with the matched method
-