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 StringThe primary command label, without a namespace or slash.private final ObjectThe live executor instance captured by the typed command invocation.private final Class<?> The concreteBaseCommandExecutorclass dispatching this command -- the live executor class captured by typed invocation, 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.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, Object> params) Creates a new context with additional parsed parameters.
-
Field Details
-
sender
private final org.bukkit.command.CommandSender senderThe sender of the command. -
commandName
The primary command label, without a namespace or slash. -
alias
The alias used to invoke the command. -
rawArgs
The raw arguments passed to the command. -
parsedParams
-
matchedMethod
The matched method for execution. -
matchedFormat
The format string of the matched command. -
executorClass
The concreteBaseCommandExecutorclass dispatching this command -- the live executor class captured by typed invocation, i.e. the SAME classPluginManager's load-time contract gate inspects viaexecutor.getClass(). ThematchedMethodmethod'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 live executor instance captured by the typed command invocation. 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
@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
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
-
getParamValue
-
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
-