PaperMC/paper-server/patches/sources/com/mojang/brigadier/CommandDispatcher.java.patch
stonar96 62607d2c90 Check requirement before suggesting root nodes
Child nodes are handled by CommandDispatcher#parse checking
requirements.

Vanilla clients only send ServerboundCommandSuggestionPacket when
encountering a command node with ASK_SERVER suggestions, however a
modified client can send this packet whenever it wants.
2021-09-12 00:14:21 +02:00

26 lines
1.2 KiB
Diff

--- a/com/mojang/brigadier/CommandDispatcher.java
+++ b/com/mojang/brigadier/CommandDispatcher.java
@@ -3,6 +3,7 @@
package com.mojang.brigadier;
+// CHECKSTYLE:OFF
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.context.CommandContextBuilder;
@@ -537,10 +538,14 @@
int i = 0;
for (final CommandNode<S> node : parent.getChildren()) {
CompletableFuture<Suggestions> future = Suggestions.empty();
+ // Paper start - Don't suggest if the requirement isn't met
+ if (parent != this.root || node.canUse(context.getSource())) {
try {
- future = node.listSuggestions(context.build(truncatedInput), new SuggestionsBuilder(truncatedInput, truncatedInputLowerCase, start));
+ future = node.listSuggestions(context.build(truncatedInput), new SuggestionsBuilder(truncatedInput, truncatedInputLowerCase, start)); // CraftBukkit
} catch (final CommandSyntaxException ignored) {
}
+ }
+ // Paper end - Don't suggest if the requirement isn't met
futures[i++] = future;
}