2024-12-11 22:26:36 +01:00
--- a/com/mojang/brigadier/tree/CommandNode.java
+++ b/com/mojang/brigadier/tree/CommandNode.java
2024-12-13 17:02:13 +01:00
@@ -3,6 +_,7 @@
2024-12-11 22:26:36 +01:00
package com.mojang.brigadier.tree;
+// CHECKSTYLE:OFF
import com.mojang.brigadier.AmbiguityConsumer;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.RedirectModifier;
2024-12-13 17:02:13 +01:00
@@ -22,6 +_,7 @@
2024-12-11 22:26:55 +01:00
import java.util.Set;
2024-12-11 22:26:36 +01:00
import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
2024-12-11 22:26:55 +01:00
+import net.minecraft.commands.CommandSourceStack;
2024-12-11 22:26:36 +01:00
public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
private final Map<String, CommandNode<S>> children = new LinkedHashMap<>();
2024-12-13 17:02:13 +01:00
@@ -32,6 +_,16 @@
2024-12-11 22:26:36 +01:00
private final RedirectModifier<S> modifier;
private final boolean forks;
private Command<S> command;
2020-04-20 00:15:29 +02:00
+ public CommandNode<CommandSourceStack> clientNode; // Paper - Brigadier API
2022-08-02 04:50:34 +02:00
+ 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
2024-12-11 22:26:36 +01:00
+ // CraftBukkit start
+ public void removeCommand(String name) {
2024-12-11 22:26:55 +01:00
+ this.children.remove(name);
+ this.literals.remove(name);
+ this.arguments.remove(name);
2024-12-11 22:26:36 +01:00
+ }
+ // 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;
2024-12-13 17:02:13 +01:00
@@ -61,7 +_,17 @@
return modifier;
2024-12-11 22:26:36 +01:00
}
- public boolean canUse(final S source) {
2024-12-13 17:02:13 +01:00
+ // Paper start
2024-12-11 22:26:36 +01:00
+ public synchronized boolean canUse(final S source) {
2024-12-11 22:26:55 +01:00
+ if (source instanceof CommandSourceStack) {
2024-12-11 22:26:36 +01:00
+ try {
2020-07-11 09:54:28 +02:00
+ ((CommandSourceStack) source).currentCommand.put(Thread.currentThread(), this); // Paper - Thread Safe Vanilla Command permission checking
2024-12-11 22:26:55 +01:00
+ return this.requirement.test(source);
2024-12-11 22:26:36 +01:00
+ } finally {
2020-07-11 09:54:28 +02:00
+ ((CommandSourceStack) source).currentCommand.remove(Thread.currentThread()); // Paper - Thread Safe Vanilla Command permission checking
2024-12-11 22:26:36 +01:00
+ }
+ }
2024-12-13 17:02:13 +01:00
+ // Paper end
return requirement.test(source);
2024-12-11 22:26:36 +01:00
}
2024-12-13 17:02:13 +01:00
@@ -151,6 +_,12 @@
2024-07-01 20:58:49 +02:00
protected abstract String getSortedKey();
public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input) {
2024-12-13 17:02:13 +01:00
+ // Paper start - prioritize mc commands in function parsing
2024-07-01 20:58:49 +02:00
+ return this.getRelevantNodes(input, null);
+ }
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public Collection<? extends CommandNode<S>> getRelevantNodes(final StringReader input, final Object source) {
2024-12-13 17:02:13 +01:00
+ // Paper end - prioritize mc commands in function parsing
if (literals.size() > 0) {
2024-07-01 20:58:49 +02:00
final int cursor = input.getCursor();
while (input.canRead() && input.peek() != ' ') {
2024-12-13 17:02:13 +01:00
@@ -158,7 +_,21 @@
2024-07-01 20:58:49 +02:00
}
final String text = input.getString().substring(cursor, input.getCursor());
input.setCursor(cursor);
2024-12-13 17:02:13 +01:00
- final LiteralCommandNode<S> literal = literals.get(text);
2024-07-01 20:58:49 +02:00
+ // 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 {
2024-12-13 17:02:13 +01:00
@@ -183,4 +_,11 @@
2022-08-02 04:50:34 +02:00
}
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
}