diff --git a/src/main/java/com/mojang/brigadier/CommandDispatcher.java b/src/main/java/com/mojang/brigadier/CommandDispatcher.java index 1035767..f67a95d 100644 --- a/src/main/java/com/mojang/brigadier/CommandDispatcher.java +++ b/src/main/java/com/mojang/brigadier/CommandDispatcher.java @@ -588,12 +588,13 @@ public class CommandDispatcher { final String fullInput = parse.getReader().getString(); final String truncatedInput = fullInput.substring(0, cursor); + final String truncatedInputLowerCase = truncatedInput.toLowerCase(); @SuppressWarnings("unchecked") final CompletableFuture[] futures = new CompletableFuture[parent.getChildren().size()]; int i = 0; for (final CommandNode node : parent.getChildren()) { CompletableFuture future = Suggestions.empty(); try { - future = node.listSuggestions(context.build(truncatedInput), new SuggestionsBuilder(truncatedInput, start)); + future = node.listSuggestions(context.build(truncatedInput), new SuggestionsBuilder(truncatedInput, truncatedInputLowerCase, start)); } catch (final CommandSyntaxException ignored) { } futures[i++] = future; diff --git a/src/main/java/com/mojang/brigadier/arguments/BoolArgumentType.java b/src/main/java/com/mojang/brigadier/arguments/BoolArgumentType.java index cb993ca..935bb84 100644 --- a/src/main/java/com/mojang/brigadier/arguments/BoolArgumentType.java +++ b/src/main/java/com/mojang/brigadier/arguments/BoolArgumentType.java @@ -34,10 +34,10 @@ public class BoolArgumentType implements ArgumentType { @Override public CompletableFuture listSuggestions(final CommandContext context, final SuggestionsBuilder builder) { - if ("true".startsWith(builder.getRemaining().toLowerCase())) { + if ("true".startsWith(builder.getRemainingLowerCase())) { builder.suggest("true"); } - if ("false".startsWith(builder.getRemaining().toLowerCase())) { + if ("false".startsWith(builder.getRemainingLowerCase())) { builder.suggest("false"); } return builder.buildFuture(); diff --git a/src/main/java/com/mojang/brigadier/suggestion/SuggestionsBuilder.java b/src/main/java/com/mojang/brigadier/suggestion/SuggestionsBuilder.java index bc0024a..3cc72b9 100644 --- a/src/main/java/com/mojang/brigadier/suggestion/SuggestionsBuilder.java +++ b/src/main/java/com/mojang/brigadier/suggestion/SuggestionsBuilder.java @@ -12,14 +12,22 @@ import java.util.concurrent.CompletableFuture; public class SuggestionsBuilder { private final String input; + private final String inputLowerCase; private final int start; private final String remaining; + private final String remainingLowerCase; private final List result = new ArrayList<>(); - public SuggestionsBuilder(final String input, final int start) { + public SuggestionsBuilder(final String input, final String inputLowerCase, final int start) { this.input = input; + this.inputLowerCase = inputLowerCase; this.start = start; this.remaining = input.substring(start); + this.remainingLowerCase = inputLowerCase.substring(start); + } + + public SuggestionsBuilder(final String input, final int start) { + this(input, input.toLowerCase(), start); } public String getInput() { @@ -34,6 +42,10 @@ public class SuggestionsBuilder { return remaining; } + public String getRemainingLowerCase() { + return remainingLowerCase; + } + public Suggestions build() { return Suggestions.create(input, result); } @@ -74,10 +86,10 @@ public class SuggestionsBuilder { } public SuggestionsBuilder createOffset(final int start) { - return new SuggestionsBuilder(input, start); + return new SuggestionsBuilder(input, inputLowerCase, start); } public SuggestionsBuilder restart() { - return new SuggestionsBuilder(input, start); + return createOffset(start); } } diff --git a/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java b/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java index 7720578..90c0cbb 100644 --- a/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java +++ b/src/main/java/com/mojang/brigadier/tree/LiteralCommandNode.java @@ -21,10 +21,12 @@ import java.util.function.Predicate; public class LiteralCommandNode extends CommandNode { private final String literal; + private final String literalLowerCase; public LiteralCommandNode(final String literal, final Command command, final Predicate requirement, final CommandNode redirect, final RedirectModifier modifier, final boolean forks) { super(command, requirement, redirect, modifier, forks); this.literal = literal; + this.literalLowerCase = literal.toLowerCase(); } public String getLiteral() { @@ -66,7 +68,7 @@ public class LiteralCommandNode extends CommandNode { @Override public CompletableFuture listSuggestions(final CommandContext context, final SuggestionsBuilder builder) { - if (literal.toLowerCase().startsWith(builder.getRemaining().toLowerCase())) { + if (literalLowerCase.startsWith(builder.getRemainingLowerCase())) { return builder.suggest(literal).buildFuture(); } else { return Suggestions.empty();