From 23550ec96082afc6278d35e34da30b6a769bfba5 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Mon, 12 Aug 2024 00:40:39 -0700 Subject: [PATCH] Fix BasicCommand suggestion arg count (#11241) --- patches/server/Brigadier-based-command-API.patch | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/patches/server/Brigadier-based-command-API.patch b/patches/server/Brigadier-based-command-API.patch index e3272914f6..ae0b5bf5ba 100644 --- a/patches/server/Brigadier-based-command-API.patch +++ b/patches/server/Brigadier-based-command-API.patch @@ -711,6 +711,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import java.util.Locale; +import java.util.Set; +import net.minecraft.commands.CommandBuildContext; ++import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.checkerframework.checker.nullness.qual.NonNull; @@ -868,7 +869,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + .then( + Commands.argument("args", StringArgumentType.greedyString()) + .suggests((context, suggestionsBuilder) -> { -+ final String[] args = StringUtils.split(suggestionsBuilder.getRemaining()); ++ String[] args = StringUtils.split(suggestionsBuilder.getRemaining()); ++ if (suggestionsBuilder.getRemaining().endsWith(" ")) { ++ // if there is trailing whitespace, we should add an empty argument to signify ++ // that there may be more, but no characters have been typed yet ++ args = ArrayUtils.add(args, ""); ++ } + final SuggestionsBuilder offsetSuggestionsBuilder = suggestionsBuilder.createOffset(suggestionsBuilder.getInput().lastIndexOf(' ') + 1); + + final Collection suggestions = basicCommand.suggest(context.getSource(), args);