Move patches to unapplied
This commit is contained in:
@@ -1,75 +0,0 @@
|
||||
--- 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;
|
||||
@@ -297,15 +298,21 @@
|
||||
List<ParseResults<S>> potentials = null;
|
||||
final int cursor = originalReader.getCursor();
|
||||
|
||||
- for (final CommandNode<S> child : node.getRelevantNodes(originalReader)) {
|
||||
+ for (final CommandNode<S> child : node.getRelevantNodes(originalReader, source)) { // Paper - prioritize mc commands in function parsing
|
||||
if (!child.canUse(source)) {
|
||||
continue;
|
||||
}
|
||||
final CommandContextBuilder<S> 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;
|
||||
}
|
||||
|
||||
@@ -451,7 +459,7 @@
|
||||
}
|
||||
|
||||
private String getSmartUsage(final CommandNode<S> node, final S source, final boolean optional, final boolean deep) {
|
||||
- if (!node.canUse(source)) {
|
||||
+ if (source != null && !node.canUse(source)) { // Paper
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -465,7 +473,7 @@
|
||||
final String redirect = node.getRedirect() == this.root ? "..." : "-> " + node.getRedirect().getUsageText();
|
||||
return self + CommandDispatcher.ARGUMENT_SEPARATOR + redirect;
|
||||
} else {
|
||||
- final Collection<CommandNode<S>> children = node.getChildren().stream().filter(c -> c.canUse(source)).collect(Collectors.toList());
|
||||
+ final Collection<CommandNode<S>> children = node.getChildren().stream().filter(c -> source == null || c.canUse(source)).collect(Collectors.toList()); // Paper
|
||||
if (children.size() == 1) {
|
||||
final String usage = this.getSmartUsage(children.iterator().next(), source, childOptional, childOptional);
|
||||
if (usage != null) {
|
||||
@@ -537,10 +545,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;
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
--- a/com/mojang/brigadier/builder/ArgumentBuilder.java
|
||||
+++ b/com/mojang/brigadier/builder/ArgumentBuilder.java
|
||||
@@ -14,9 +14,17 @@
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public abstract class ArgumentBuilder<S, T extends ArgumentBuilder<S, T>> {
|
||||
+ // Paper start - Vanilla command permission fixes
|
||||
+ private static final Predicate<Object> DEFAULT_REQUIREMENT = s -> true;
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ public static <S> Predicate<S> defaultRequirement() {
|
||||
+ return (Predicate<S>) DEFAULT_REQUIREMENT;
|
||||
+ }
|
||||
+ // Paper end - Vanilla command permission fixes
|
||||
private final RootCommandNode<S> arguments = new RootCommandNode<>();
|
||||
private Command<S> command;
|
||||
- private Predicate<S> requirement = s -> true;
|
||||
+ private Predicate<S> requirement = defaultRequirement(); // Paper - Vanilla command permission fixes
|
||||
private CommandNode<S> target;
|
||||
private RedirectModifier<S> modifier = null;
|
||||
private boolean forks;
|
||||
@@ -1,102 +0,0 @@
|
||||
--- a/com/mojang/brigadier/tree/CommandNode.java
|
||||
+++ b/com/mojang/brigadier/tree/CommandNode.java
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
package com.mojang.brigadier.tree;
|
||||
|
||||
+// CHECKSTYLE:OFF
|
||||
import com.mojang.brigadier.AmbiguityConsumer;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.RedirectModifier;
|
||||
@@ -22,6 +23,7 @@
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Predicate;
|
||||
+import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
|
||||
private final Map<String, CommandNode<S>> children = new LinkedHashMap<>();
|
||||
@@ -32,6 +34,16 @@
|
||||
private final RedirectModifier<S> modifier;
|
||||
private final boolean forks;
|
||||
private Command<S> command;
|
||||
+ public CommandNode<CommandSourceStack> clientNode; // Paper - Brigadier API
|
||||
+ public CommandNode<io.papermc.paper.command.brigadier.CommandSourceStack> unwrappedCached = null; // Paper - Brigadier Command API
|
||||
+ public CommandNode<io.papermc.paper.command.brigadier.CommandSourceStack> wrappedCached = null; // Paper - Brigadier Command API
|
||||
+ // CraftBukkit start
|
||||
+ public void removeCommand(String name) {
|
||||
+ this.children.remove(name);
|
||||
+ this.literals.remove(name);
|
||||
+ this.arguments.remove(name);
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
|
||||
protected CommandNode(final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks) {
|
||||
this.command = command;
|
||||
@@ -61,7 +73,17 @@
|
||||
return this.modifier;
|
||||
}
|
||||
|
||||
- public boolean canUse(final S source) {
|
||||
+ // CraftBukkit start
|
||||
+ public synchronized boolean canUse(final S source) {
|
||||
+ if (source instanceof CommandSourceStack) {
|
||||
+ try {
|
||||
+ ((CommandSourceStack) source).currentCommand.put(Thread.currentThread(), this); // Paper - Thread Safe Vanilla Command permission checking
|
||||
+ return this.requirement.test(source);
|
||||
+ } finally {
|
||||
+ ((CommandSourceStack) source).currentCommand.remove(Thread.currentThread()); // Paper - Thread Safe Vanilla Command permission checking
|
||||
+ }
|
||||
+ }
|
||||
+ // CraftBukkit end
|
||||
return this.requirement.test(source);
|
||||
}
|
||||
|
||||
@@ -151,6 +173,12 @@
|
||||
protected abstract String getSortedKey();
|
||||
|
||||
public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input) {
|
||||
+ // Paper start - prioritize mc commands in function parsing
|
||||
+ return this.getRelevantNodes(input, null);
|
||||
+ }
|
||||
+ @org.jetbrains.annotations.ApiStatus.Internal
|
||||
+ public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input, final Object source) {
|
||||
+ // Paper end - prioritize mc commands in function parsing
|
||||
if (this.literals.size() > 0) {
|
||||
final int cursor = input.getCursor();
|
||||
while (input.canRead() && input.peek() != ' ') {
|
||||
@@ -158,7 +186,21 @@
|
||||
}
|
||||
final String text = input.getString().substring(cursor, input.getCursor());
|
||||
input.setCursor(cursor);
|
||||
- final LiteralCommandNode<S> literal = this.literals.get(text);
|
||||
+ // Paper start - prioritize mc commands in function parsing
|
||||
+ LiteralCommandNode<S> literal = null;
|
||||
+ if (source instanceof CommandSourceStack css && css.source == net.minecraft.commands.CommandSource.NULL) {
|
||||
+ if (!text.contains(":")) {
|
||||
+ literal = this.literals.get("minecraft:" + text);
|
||||
+ }
|
||||
+ } else if (source instanceof CommandSourceStack css && css.source instanceof net.minecraft.world.level.BaseCommandBlock) {
|
||||
+ if (css.getServer().server.getCommandBlockOverride(text) && !text.contains(":")) {
|
||||
+ literal = this.literals.get("minecraft:" + text);
|
||||
+ }
|
||||
+ }
|
||||
+ if (literal == null) {
|
||||
+ literal = this.literals.get(text);
|
||||
+ }
|
||||
+ // Paper end - prioritize mc commands in function parsing
|
||||
if (literal != null) {
|
||||
return Collections.singleton(literal);
|
||||
} else {
|
||||
@@ -183,4 +225,11 @@
|
||||
}
|
||||
|
||||
public abstract Collection<String> getExamples();
|
||||
+ // Paper start - Brigadier Command API
|
||||
+ public void clearAll() {
|
||||
+ this.children.clear();
|
||||
+ this.literals.clear();
|
||||
+ this.arguments.clear();
|
||||
+ }
|
||||
+ // Paper end - Brigadier Command API
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
--- a/com/mojang/brigadier/tree/LiteralCommandNode.java
|
||||
+++ b/com/mojang/brigadier/tree/LiteralCommandNode.java
|
||||
@@ -23,11 +23,19 @@
|
||||
public class LiteralCommandNode<S> extends CommandNode<S> {
|
||||
private final String literal;
|
||||
private final String literalLowerCase;
|
||||
+ private final String nonPrefixed; // Paper - prioritize mc commands in function parsing
|
||||
|
||||
public LiteralCommandNode(final String literal, final Command<S> command, final Predicate<S> requirement, final CommandNode<S> redirect, final RedirectModifier<S> modifier, final boolean forks) {
|
||||
super(command, requirement, redirect, modifier, forks);
|
||||
this.literal = literal;
|
||||
this.literalLowerCase = literal.toLowerCase(Locale.ROOT);
|
||||
+ // Paper start - prioritize mc commands in function parsing
|
||||
+ if (literal.startsWith("minecraft:")) {
|
||||
+ this.nonPrefixed = literal.substring("minecraft:".length());
|
||||
+ } else {
|
||||
+ this.nonPrefixed = null;
|
||||
+ }
|
||||
+ // Paper end - prioritize mc commands in function parsing
|
||||
}
|
||||
|
||||
public String getLiteral() {
|
||||
@@ -42,7 +50,12 @@
|
||||
@Override
|
||||
public void parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
|
||||
final int start = reader.getCursor();
|
||||
- final int end = parse(reader);
|
||||
+ // Paper start - prioritize mc commands in function parsing
|
||||
+ int end = parse(reader, false);
|
||||
+ if (end == -1 && this.nonPrefixed != null) {
|
||||
+ end = parse(reader, true);
|
||||
+ }
|
||||
+ // Paper end - prioritize mc commands in function parsing
|
||||
if (end > -1) {
|
||||
contextBuilder.withNode(this, StringRange.between(start, end));
|
||||
return;
|
||||
@@ -51,7 +64,10 @@
|
||||
throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.literalIncorrect().createWithContext(reader, literal);
|
||||
}
|
||||
|
||||
- private int parse(final StringReader reader) {
|
||||
+ // Paper start - prioritize mc commands in function parsing
|
||||
+ private int parse(final StringReader reader, final boolean secondPass) {
|
||||
+ String literal = secondPass ? this.nonPrefixed : this.literal;
|
||||
+ // Paper end - prioritize mc commands in function parsing
|
||||
final int start = reader.getCursor();
|
||||
if (reader.canRead(literal.length())) {
|
||||
final int end = start + literal.length();
|
||||
@@ -78,7 +94,7 @@
|
||||
|
||||
@Override
|
||||
public boolean isValidInput(final String input) {
|
||||
- return parse(new StringReader(input)) > -1;
|
||||
+ return parse(new StringReader(input), false) > -1; // Paper - prioritize mc commands in function parsing
|
||||
}
|
||||
|
||||
@Override
|
||||
Reference in New Issue
Block a user