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 ObjectThe executor instance dispatching this command --thiscaptured inBaseCommandExecutor#onCommand.private final Class<?> The concreteBaseCommandExecutorclass dispatching this command --this.getClass()captured inonCommand, i.e.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. -
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. -
executorClass
The concreteBaseCommandExecutorclass dispatching this command --this.getClass()captured inonCommand, i.e. the SAME classPluginManager's load-time contract gate inspects viaexecutor.getClass(). WR-02 (05-REVIEW.md):matchedMethod'sgetDeclaringClass()is NOT always this class -- an inherited, unoverridden@CmdMappingmethod's declaring class is whatever ancestor first declared it. Threading the concrete executor class through the context letscom.ultikits.ultitools.utils.ReflectionUtil#resolveMethodOrClassAnnotation(Method, Class, Class)resolve a class-level@CmdCD/@UsageLimitagainst the class the load-time gate actually checked, not an implementation detail of which ancestor happens to declare the mapping method.nullfor a context built without it (e.g. a unit test constructingCommandContextdirectly) -- callers fall back to the pre-WR-02, declaring-class-only resolution in that case; seeresolveMethodOrClassAnnotation's own javadoc.- Since:
- 6.3.0
-
executor
The executor instance dispatching this command --thiscaptured inBaseCommandExecutor#onCommand. The config-bound@CmdCDcache is kept per executor instance, because neither the binding key nor the executor class identifies the owning module when aCooldownValidatoris shared (#531).nullfor a context built without it.- Since:
- 6.3.0
-
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
-