Skip to content

SuggestionsBuilderHelper ​

com.jsmacrosce.jsmacros.client.api.helper.SuggestionsBuilderHelper

Since1.6.5

Wraps Brigadier's builder for command-completion callbacks, exposing the input range and methods for adding suggestions.

js
const command = Chat.getCommandManager().createCommandBuilder("teleport")
  .literalArg("home")
  .suggest(JavaWrapper.methodToJava(function (ctx, suggestions) {
    // what the player has typed, and where the part being completed starts
    if (suggestions.getRemaining().length === 0) {
      suggestions.suggest("spawn").suggest("base").suggest(3);  
    }
  }));  
command.register();

Constructors ​

new SuggestionsBuilderHelper ​

new SuggestionsBuilderHelper(SuggestionsBuilder base)#
Wraps the supplied Brigadier suggestion builder directly; it is retained, not copied. Builder operations dereference it, so a null builder is not usable for those operations.

Parameters:

  • base: the builder to wrap; may be null and is retained as-is

Methods ​

getInput ​

getInput(): StringSince1.6.5#
Returns the full command input associated with this completion request.
Returns: the full input line the suggestions are for

getRemaining ​

getRemaining(): StringSince1.6.5#
Returns the input suffix beginning at getStart().
Returns: the unfinished tail of the input

getRemainingLowerCase ​

getRemainingLowerCase(): StringSince1.6.5#
Returns the input suffix beginning at getStart(), lowercased without trimming leading spaces.
Returns: the unfinished tail of the input, lowercased

getStart ​

getStart(): intSince1.6.5#
Returns the start offset of the text being completed, measured in getInput().
Returns: the character index in the input where completion starts

suggest ​

suggest(String suggestion): SuggestionsBuilderHelperSince1.6.5#
Adds a text suggestion and returns this helper for chaining.

Parameters:

  • suggestion: the text to offer
Returns: self for chaining
suggest(int value): SuggestionsBuilderHelperSince1.6.5#
Adds the decimal string representation of a number as a suggestion and returns this helper.

Parameters:

  • value: the number to offer
Returns: self for chaining

suggestBlockPositions ​

suggestBlockPositions(BlockPosHelper... positions): SuggestionsBuilderHelperSince1.8.4#
Offers block positions as x y z coordinate suggestions.
const command = Chat.getCommandManager().createCommandBuilder("tp")
  .literalArg("pos")
  .suggestBlockPositions(
    PositionCommon.createBlockPos(0, 64, 0),
    PositionCommon.createBlockPos(100, 64, 100)
  );
command.register();

Parameters:

  • positions: the positions to suggest
Returns: self for chaining
suggestBlockPositions(Collection<BlockPosHelper> positions): SuggestionsBuilderHelperSince1.8.4#
Offers the block positions in a collection as x y z coordinate suggestions.

Parameters:

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

suggestIdentifier ​

suggestIdentifier(String... identifiers): SuggestionsBuilderHelperSince1.8.4#
Offers registry identifier suggestions, parsing each string as a resource location before passing it to the game's resource matcher.
const command = Chat.getCommandManager().createCommandBuilder("give")
  .literalArg("item")
  .suggestIdentifier("diamond", "emerald", "gold_ingot");
command.register();

Parameters:

  • identifiers: the identifiers to match
Returns: self for chaining
suggestIdentifier(Collection<String> identifiers): SuggestionsBuilderHelperSince1.8.4#
Offers registry identifier suggestions from a collection, parsing each string as a resource location before passing it to the game's resource matcher.
const blocks = ["stone", "dirt", "oak_log"];
const command = Chat.getCommandManager().createCommandBuilder("setblock")
  .literalArg("block")
  .suggest(JavaWrapper.methodToJava(function (ctx, suggestions) {
    suggestions.suggestIdentifier(blocks);
  }));
command.register();

Parameters:

  • identifiers: the identifiers to match
Returns: self for chaining

suggestMatching ​

suggestMatching(String... suggestions): SuggestionsBuilderHelperSince1.8.4#
Offers string suggestions filtered against the text currently being completed.
const command = Chat.getCommandManager().createCommandBuilder("difficulty")
  .literalArg("value")
  .suggestMatching("peaceful", "easy", "normal", "hard");
command.register();

Parameters:

  • suggestions: the strings to match
Returns: self for chaining
suggestMatching(Collection<String> suggestions): SuggestionsBuilderHelperSince1.8.4#
Offers string suggestions filtered against the text currently being completed.
const names = ["alpha", "beta", "gamma"];
const command = Chat.getCommandManager().createCommandBuilder("select")
  .literalArg("name")
  .suggest(JavaWrapper.methodToJava(function (ctx, suggestions) {
    suggestions.suggestMatching(names);
  }));
command.register();

Parameters:

  • suggestions: the strings to match
Returns: self for chaining

suggestPositions ​

suggestPositions(String... positions): SuggestionsBuilderHelperSince1.8.4#
Offers coordinate strings containing two or three whitespace-separated components; all strings in a call must have the same number of components. Strings are passed to the collection overload for validation and suggestion.

Parameters:

  • positions: the positions to suggest
Returns: self for chaining.
suggestPositions(Collection<String> positions): SuggestionsBuilderHelperSince1.8.4#
Validates coordinate strings containing two or three whitespace-separated components, with the same component count throughout the collection, then offers them through the game's 2D or 3D coordinate matcher against the current unfinished input. Components are split on whitespace (surrounding and repeated spaces are not retained); relative-coordinate tokens are passed to the matcher. An empty collection adds no suggestions and a null collection is not accepted.

Parameters:

  • positions: the coordinate strings to suggest
Returns: self for chaining

suggestWithTooltip ​

suggestWithTooltip(String suggestion, TextHelper tooltip): SuggestionsBuilderHelperSince1.6.5#
Adds a text suggestion with a tooltip and returns this helper for chaining.
const command = Chat.getCommandManager().createCommandBuilder("teleport")
  .literalArg("home")
  .suggest(JavaWrapper.methodToJava(function (ctx, suggestions) {
    suggestions.suggestWithTooltip("spawn", Chat.createTextHelperFromString("world spawn point"));
    suggestions.suggestWithTooltip("base", Chat.createTextHelperFromString("your base, set with /sethome"));
  }));
command.register();

Parameters:

  • suggestion: the text to offer
  • tooltip: the text to show beside the suggestion
Returns: self for chaining
suggestWithTooltip(int value, TextHelper tooltip): SuggestionsBuilderHelperSince1.6.5#
Adds the decimal string representation of a number with a tooltip and returns this helper for chaining.
const command = Chat.getCommandManager().createCommandBuilder("setgamemode")
  .literalArg("value")
  .suggest(JavaWrapper.methodToJava(function (ctx, suggestions) {
    const survival = Chat.createTextHelperFromString("take damage, need to eat");
    const creative = Chat.createTextHelperFromString("fly and break blocks");
    suggestions.suggestWithTooltip(0, survival).suggestWithTooltip(1, creative);
  }));
command.register();

Parameters:

  • value: the number to offer
  • tooltip: the text to show beside the suggestion
Returns: self for chaining