--- 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; @@ -303,9 +304,15 @@ } final CommandContextBuilder context = contextSoFar.copy(); final StringReader reader = new StringReader(originalReader); + boolean stop = false; // Paper - Handle non-recoverable exceptions try { try { child.parse(reader, context); + // Paper start - Handle non-recoverable exceptions + } catch (final io.papermc.paper.brigadier.TagParseCommandSyntaxException e) { + stop = true; + throw e; + // Paper end - Handle non-recoverable exceptions } catch (final RuntimeException ex) { throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherParseException().createWithContext(reader, ex.getMessage()); } @@ -320,6 +327,7 @@ } errors.put(child, ex); reader.setCursor(cursor); + if (stop) return new ParseResults<>(contextSoFar, originalReader, errors); // Paper - Handle non-recoverable exceptions continue; } @@ -537,10 +545,14 @@ int i = 0; for (final CommandNode node : parent.getChildren()) { CompletableFuture 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; }