Skip to content

CommandBuilder ​

com.jsmacrosce.jsmacros.client.api.classes.inventory.CommandBuilder

Since1.4.2

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().

js
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#
Adds an angle argument; the parsed value is resolved against the command source and returned as degrees.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

blockArg ​

blockArg(String name): CommandBuilder#
Alias for blockStateArg(String); returns the parsed block state as a helper.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

blockPosArg ​

blockPosArg(String name): CommandBuilder#
Adds a block position argument and returns its parsed value as a BlockPosHelper. The coordinates may be absolute, relative (~), or local (^), resolved against the command source.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

blockPredicateArg ​

blockPredicateArg(String name): CommandBuilder#
Adds a block predicate argument, returned as a function that tests the block at a position.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

blockStateArg ​

blockStateArg(String name): CommandBuilder#
Adds a block-state argument and returns the parsed state as a helper.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

booleanArg ​

booleanArg(String name): CommandBuilder#
Adds a boolean argument accepting true or false; its parsed value is a boolean.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

colorArg ​

colorArg(String name): CommandBuilder#
Adds a vanilla color argument; its value is returned as a formatting helper.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

columnPosArg ​

columnPosArg(String name): CommandBuilder#
Adds a two-coordinate horizontal position argument and returns its parsed value as a BlockPosHelper. Its Y coordinate is zero; coordinates may be absolute, relative (~), or local (^), resolved against the command source.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

dimensionArg ​

dimensionArg(String name): CommandBuilder#
Adds a dimension argument, returned to scripts as its full identifier string.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

doubleArg ​

doubleArg(String name): CommandBuilder#
Adds an unbounded decimal-number argument.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.
doubleArg(String name, double min, double max): CommandBuilder#
Adds a bounded decimal argument. Both bounds are inclusive; values outside them are rejected during parsing. This is the decimal counterpart to intArg(String, int, int).

Parameters:

  • name: the name the argument is read back under
  • min: the lowest value accepted, inclusive
  • max: the highest value accepted, inclusive
Returns: self for chaining.

executes ​

Attaches a callback to the innermost command node. Its return value is ignored; after it runs, the command reports success. Use FJsMacros.runScript(String, BaseEvent) when the callback needs waits; the CommandContextHelper is a BaseEvent and can be passed to that method.

Parameters:

  • callback: the command callback
Returns: this builder, for chaining

floatRangeArg ​

floatRangeArg(String name): CommandBuilder#
Adds a decimal argument accepting either one value or a min..max range; the parsed value is a Brigadier range object.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

greedyStringArg ​

greedyStringArg(String name): CommandBuilder#
Adds a greedy text argument that consumes the remaining input, including spaces. It must be the final argument on its branch.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

identifierArg ​

identifierArg(String name): CommandBuilder#
Adds a resource-location argument; CommandContextHelper.getArg(String) returns its full identifier as a string.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

intArg ​

intArg(String name): CommandBuilder#
Adds an unbounded signed 32-bit integer argument.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.
intArg(String name, int min, int max): CommandBuilder#
Adds a signed 32-bit integer argument constrained to the inclusive range min–max.

Parameters:

  • name: the name the argument is read back under
  • min: the lowest value accepted, inclusive
  • max: the highest value accepted, inclusive
Returns: self for chaining.

intRangeArg ​

intRangeArg(String name): CommandBuilder#
Adds an integer argument accepting either one value or a min..max range; the parsed value is a Brigadier range object.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

itemArg ​

itemArg(String name): CommandBuilder#
Adds an item argument. This is an alias for itemStackArg(String); its returned stack always has a count of one.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

itemPredicateArg ​

itemPredicateArg(String name): CommandBuilder#
Adds an item predicate argument, returned as a function that tests an item stack.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

itemSlotArg ​

itemSlotArg(String name): CommandBuilder#
Adds a named slot argument. The name must resolve in the game's slot-range list and select exactly one slot; multi-slot ranges are rejected. The parsed value is that slot's integer index. Available names are defined by the target Minecraft version; for example, 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
Returns: self for chaining.

itemStackArg ​

itemStackArg(String name): CommandBuilder#
Adds an item argument and returns a stack with a count of one.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

literalArg ​

literalArg(String name): CommandBuilder#
Adds a fixed word to the current command branch; it has no value to read from the context.

Parameters:

  • name: the word the player types
Returns: self for chaining.

longArg ​

longArg(String name): CommandBuilder#
Adds an unbounded signed 64-bit integer argument.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.
longArg(String name, long min, long max): CommandBuilder#
Adds a signed 64-bit integer argument constrained to the inclusive range min–max.

Parameters:

  • name: the name the argument is read back under
  • min: the lowest value accepted, inclusive
  • max: the highest value accepted, inclusive
Returns: self for chaining.

nbtArg ​

nbtArg(String name): CommandBuilder#
Alias for nbtCompoundArg(String); the parsed compound is returned as its NBT helper.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

nbtCompoundArg ​

nbtCompoundArg(String name): CommandBuilder#
Adds an NBT compound tag. The parsed compound is converted to its corresponding NBT helper.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

nbtElementArg ​

nbtElementArg(String name): CommandBuilder#
Adds one NBT tag of any type; nbtCompoundArg(String) accepts only a compound. The parsed tag is converted to its corresponding NBT helper.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

or ​

Merges the innermost argument branch one level upward, so the next argument is attached at that parent level rather than beneath the innermost argument.
Returns: self for chaining.
or(int argumentLevel): CommandBuilder#
Merges branches upward until the command tree has the requested depth, counting the root as depth 1. Values below 1 are treated as 1; a depth greater than the current depth leaves the tree unchanged.

Parameters:

  • argumentLevel: depth to retain after merging
Returns: self for chaining.

otherwise ​

otherwise(): CommandBuilderSince1.5.2#
name overload for or() to work around language keyword restrictions
Returns: self for chaining
otherwise(int argLevel): CommandBuilderSince1.5.2#
Name overload for or(int) to work around language keyword restrictions.

Parameters:

  • argLevel: depth to retain after merging branches, counting the root as depth 1; values below 1 are treated as 1
Returns: self for chaining

particleArg ​

particleArg(String name): CommandBuilder#
Adds a particle argument, returned to scripts as its particle registry id.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

quotedStringArg ​

quotedStringArg(String name): CommandBuilder#
Adds a quoted string argument, which can contain spaces and ends at the closing quote. The parsed value is returned without its quotes.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

regexArgType ​

regexArgType(String name, String regex, String flags): CommandBuilder#
Adds an argument matched against a regular expression and returns an array containing the whole match followed by its capture groups. The pattern must match at the start of the remaining input; the entire match is consumed. A failed match reports the pattern to the player between slashes. Recognized flag characters are:
  • i makes the match ignore case
  • s lets a dot match a line break as well as any other character
  • u switches on the unicode character classes

Parameters:

  • name: the name the argument is read back under
  • regex: the regular expression the text has to match at the start
  • flags: the flag letters to switch on, from i, s and u
Returns: self for chaining.

register ​

register(): CommandBuilder#
Registers this command with the client.
Returns: self for chaining.

suggest ​

Uses the callback to add suggestions to the current suggestions builder.

Parameters:

  • callback: callback that receives the command context and suggestions builder
Returns: self for chaining

suggestBlockPositions ​

suggestBlockPositions(BlockPosHelper... positions): CommandBuilderSince1.8.4#
Suggests these block positions as space-separated integer coordinates.

Parameters:

  • positions: the block positions to suggest
Returns: self for chaining.
suggestBlockPositions(Collection<BlockPosHelper> positions): CommandBuilderSince1.8.4#
Suggests these block positions as space-separated integer coordinates.

Parameters:

  • positions: the block positions to suggest
Returns: self for chaining.

suggestIdentifier ​

suggestIdentifier(String... suggestions): CommandBuilderSince1.6.5#

Parameters:

  • suggestions: identifiers offered as completions
Returns: self for chaining
suggestIdentifier(Collection<String> suggestions): CommandBuilderSince1.8.4#

Parameters:

  • suggestions: identifiers offered as completions after parsing as resource locations
Returns: self for chaining.

suggestMatching ​

suggestMatching(String... suggestions): CommandBuilderSince1.6.5#

Parameters:

  • suggestions: strings offered as completions, without identifier parsing
Returns: self for chaining
suggestMatching(Collection<String> suggestions): CommandBuilderSince1.8.4#

Parameters:

  • suggestions: strings offered as completions, without identifier parsing
Returns: self for chaining.

suggestPositions ​

suggestPositions(String... positions): CommandBuilderSince1.8.4#
Suggests positions expressed as three space-separated coordinate components.

Parameters:

  • positions: the positions to suggest
Returns: self for chaining.
suggestPositions(Collection<String> positions): CommandBuilderSince1.8.4#
Suggests positions expressed as three space-separated coordinate components. Each input must contain at least three components; they are parsed without validation here.

Parameters:

  • positions: the positions to suggest
Returns: self for chaining.

textArgType ​

textArgType(String name): CommandBuilder#
Adds a text-component argument using vanilla command syntax; the parsed component is returned as a TextHelper.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

timeArg ​

timeArg(String name): CommandBuilder#
Adds a duration argument; its parsed value is an integer number of ticks. The input unit may be ticks (t), seconds (s), or days (d); a unit is required.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

unregister ​

unregister(): CommandBuilderSince1.6.5#
Unregisters this command.
Returns: self for chaining.

uuidArgType ​

uuidArgType(String name): CommandBuilder#
Adds a UUID argument; CommandContextHelper.getArg(String) returns its parsed value as a UUID.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.

wordArg ​

wordArg(String name): CommandBuilder#
Adds a single-word string argument, which does not accept spaces.

Parameters:

  • name: the name the argument is read back under
Returns: self for chaining.