CommandContext
com.jsmacrosce.jsmacros.client.api.helper.CommandContextHelper
The parsed context for a client command, containing its arguments and command source. A script receives one in a command callback or a suggestion callback.
getArg(String) reads a named argument. Command execution dispatches this BaseEvent before invoking the command callback, so JsMacros.on("CommandContext", ...) can observe it. Suggestion callbacks receive a context helper without dispatching this event.
js
const builder = Chat.getCommandManager().createCommandBuilder("hello");
builder.greedyStringArg("name");
builder.executes(JavaWrapper.methodToJava(function (ctx) {
// getArg hands the argument back already wrapped for its type,
// a greedy string comes back as a plain string
Chat.log(`hello ${ctx.getArg("name")}`);
return true;
}));
builder.register();Constructors
new CommandContextHelper
new CommandContextHelper(CommandContext<?> base)#Stores the Brigadier context and initializes the event base with the client core; this does not dispatch the event or execute the command. The reference is retained without copying or validation. A
null context is accepted, but methods that dereference it will fail.Parameters:
base: the raw Brigadier context to retain; may benull
Methods
equals
Delegates equality to the underlying context, unwrapping another
CommandContextHelper to its context first; any other object is passed directly to the underlying context's equals. A null underlying context causes NullPointerException.Parameters:
obj: another helper or an object to compare through the underlying context
Returns: the result of the underlying context's equality comparison
getArg
Returns a named argument, converting recognized Brigadier argument values to JsMacros helpers or script-friendly values. The conversions are: a block argument becomes a BlockStateHelper, an identifier becomes its
namespace:path string, an item becomes an ItemStackHelper of one item, an NBT argument becomes the matching NBTElementHelper, text becomes a TextHelper, a colour becomes a FormattingHelper, an angle becomes a plain number, an enchantment becomes an EnchantmentHelper, a particle and a status effect each become their identifier string, a position becomes a BlockPosHelper, and an entity selector becomes a plain list of EntityHelper. An item predicate and a block predicate become a Java predicate, which takes the thing being tested and answers whether it is accepted, with an item stack for the first and a block position for the second. Anything not on that list comes back as the raw brigadier value. Item arguments produce a stack of one. Entity selectors use findEntities, so the result may be empty or contain multiple entities; unlike findSingleEntity, this does not fail for zero or multiple matches. Selector permission checks can still throw CommandSyntaxException. Angles, coordinates, and selectors use a fake command source when the context source is a client suggestion provider. In that provider context, every successful name lookup constructs the fake source before conversion. A missing current client player therefore causes NullPointerException regardless of argument type. The fake source has no server or server level: selectors that require either can also fail with NullPointerException, rather than returning an empty list. A non-client provider context supplies no fake source, so conversions that dereference it can fail too. Selector permission failures throw CommandSyntaxException; on Minecraft 26.1.2, item-stack conversion can also throw it for an oversized or malformed stack. Other unconverted argument types are returned as their raw Brigadier values. A name absent from this context throws IllegalArgumentException before conversion.Parameters:
name: the name the argument was declared with on the command
Returns: the argument's value, wrapped as described above
getChild
getChild(): CommandContextHelper#getInput
getRange
getRange(): StringRange#Returns the Brigadier range covered by this context. Its start and end offsets are relative to the input returned by getInput().
Returns: the range of this context within the command line.
getRaw
getRaw(): CommandContext<?>#Returns the underlying Brigadier context, exposing its raw values rather than JsMacros wrappers.
Returns: the brigadier context this wraps.
hashCode
hashCode(): int#Returns the hash code delegated to the underlying Brigadier context. A
null underlying context causes NullPointerException.Returns: the underlying context's hash code