2024-12-11 22:26:36 +01:00
--- 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;
2024-12-11 22:26:55 +01:00
@@ -22,6 +23,7 @@
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<>();
2020-04-20 00:15:29 +02:00
@@ -32,6 +34,14 @@
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
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;
2020-04-20 00:15:29 +02:00
@@ -61,7 +71,17 @@
2024-12-11 22:26:55 +01:00
return this.modifier;
2024-12-11 22:26:36 +01:00
}
- public boolean canUse(final S source) {
+ // CraftBukkit start
+ 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
+ }
+ }
+ // CraftBukkit end
2024-12-11 22:26:55 +01:00
return this.requirement.test(source);
2024-12-11 22:26:36 +01:00
}