SuggestionsBuilderHelper
com.jsmacrosce.jsmacros.client.api.helper.SuggestionsBuilderHelper
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 benulland is retained as-is
Methods
getInput
getRemaining
Returns the input suffix beginning at getStart().
Returns: the unfinished tail of the input
getRemainingLowerCase
Returns the input suffix beginning at getStart(), lowercased without trimming leading spaces.
Returns: the unfinished tail of the input, lowercased
getStart
Returns the start offset of the text being completed, measured in getInput().
Returns: the character index in the input where completion starts
suggest
Adds a text suggestion and returns this helper for chaining.
Parameters:
suggestion: the text to offer
Returns: self for chaining
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
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
Offers the block positions in a collection as
x y z coordinate suggestions.Parameters:
positions: the positions to suggest
Returns: self for chaining
suggestIdentifier
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
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
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
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
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.
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
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 offertooltip: the text to show beside the suggestion
Returns: self for chaining
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 offertooltip: the text to show beside the suggestion
Returns: self for chaining