CommandBuilder
com.jsmacrosce.jsmacros.client.api.classes.inventory.CommandBuilder
Builds a command tree for client registration; obtain it from FChat.getCommandManager().
Each argument extends the current branch; use or() or or(int) to move back up the tree before adding an alternative branch.
executes(MethodWrapper) attaches to the current node. Argument values are read from the callback's CommandContextHelper with getArg; their value types depend on the argument methods used.
Register the completed tree with register().
const command = Chat.getCommandManager().createCommandBuilder("count");
// /count set 10
command.literalArg("set")
.intArg("amount", 1, 64)
.suggestMatching("10", "32", "64")
.executes(JavaWrapper.methodToJava(function (ctx) {
Chat.log(`the amount is now ${ctx.getArg("amount")}`);
return true;
}));
// fold the whole branch back up to the command name, so the next literal
// lands alongside "set" rather than below it
command.or(1);
// /count show
command.literalArg("show")
.executes(JavaWrapper.methodToJava(function (ctx) {
Chat.log("the amount is whatever it was");
return true;
}));
command.register();Constructors
new CommandBuilder
new CommandBuilder()#Methods
angleArg
angleArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
blockArg
blockArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
blockPosArg
blockPosArg(String name): CommandBuilder#~), or local (^), resolved against the command source.Parameters:
name: the name the argument is read back under
blockPredicateArg
blockPredicateArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
blockStateArg
blockStateArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
booleanArg
booleanArg(String name): CommandBuilder#true or false; its parsed value is a boolean.Parameters:
name: the name the argument is read back under
colorArg
colorArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
columnPosArg
columnPosArg(String name): CommandBuilder#~), or local (^), resolved against the command source.Parameters:
name: the name the argument is read back under
dimensionArg
dimensionArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
doubleArg
doubleArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
doubleArg(String name, double min, double max): CommandBuilder#Parameters:
name: the name the argument is read back undermin: the lowest value accepted, inclusivemax: the highest value accepted, inclusive
executes
executes(MethodWrapper<CommandContextHelper, Object, Object, ?> callback): CommandBuilder#Parameters:
callback: the command callback
floatRangeArg
floatRangeArg(String name): CommandBuilder#min..max range; the parsed value is a Brigadier range object.Parameters:
name: the name the argument is read back under
greedyStringArg
greedyStringArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
identifierArg
identifierArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
intArg
intArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
intArg(String name, int min, int max): CommandBuilder#min–max.Parameters:
name: the name the argument is read back undermin: the lowest value accepted, inclusivemax: the highest value accepted, inclusive
intRangeArg
intRangeArg(String name): CommandBuilder#min..max range; the parsed value is a Brigadier range object.Parameters:
name: the name the argument is read back under
itemArg
itemArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
itemPredicateArg
itemPredicateArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
itemSlotArg
itemSlotArg(String name): CommandBuilder#hotbar.0 selects the first hotbar slot, while hotbar.* is a multi-slot range and is rejected.Parameters:
name: the name the argument is read back under
itemStackArg
itemStackArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
literalArg
literalArg(String name): CommandBuilder#Parameters:
name: the word the player types
longArg
longArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
longArg(String name, long min, long max): CommandBuilder#min–max.Parameters:
name: the name the argument is read back undermin: the lowest value accepted, inclusivemax: the highest value accepted, inclusive
nbtArg
nbtArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
nbtCompoundArg
nbtCompoundArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
nbtElementArg
nbtElementArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
or
or(): CommandBuilder#or(int argumentLevel): CommandBuilder#Parameters:
argumentLevel: depth to retain after merging
otherwise
Parameters:
argLevel: depth to retain after merging branches, counting the root as depth 1; values below 1 are treated as 1
particleArg
particleArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
quotedStringArg
quotedStringArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
regexArgType
regexArgType(String name, String regex, String flags): CommandBuilder#imakes the match ignore caseslets a dot match a line break as well as any other characteruswitches on the unicode character classes
Parameters:
name: the name the argument is read back underregex: the regular expression the text has to match at the startflags: the flag letters to switch on, fromi,sandu
register
register(): CommandBuilder#suggest
suggest(MethodWrapper<CommandContextHelper, SuggestionsBuilderHelper, Object, ?> callback): CommandBuilderSince1.6.5#Parameters:
callback: callback that receives the command context and suggestions builder
suggestBlockPositions
Parameters:
positions: the block positions to suggest
Parameters:
positions: the block positions to suggest
suggestIdentifier
Parameters:
suggestions: identifiers offered as completions
Parameters:
suggestions: identifiers offered as completions after parsing as resource locations
suggestMatching
Parameters:
suggestions: strings offered as completions, without identifier parsing
Parameters:
suggestions: strings offered as completions, without identifier parsing
suggestPositions
Parameters:
positions: the positions to suggest
Parameters:
positions: the positions to suggest
textArgType
textArgType(String name): CommandBuilder#TextHelper.Parameters:
name: the name the argument is read back under
timeArg
timeArg(String name): CommandBuilder#t), seconds (s), or days (d); a unit is required.Parameters:
name: the name the argument is read back under
unregister
uuidArgType
uuidArgType(String name): CommandBuilder#Parameters:
name: the name the argument is read back under
wordArg
wordArg(String name): CommandBuilder#Parameters:
name: the name the argument is read back under