PaperMC/Spigot-Server-Patches/0531-Thread-Safe-Vanilla-Command-permission-checking.patch
Josh Roy b31089a929
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#5325)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
d264e972 #591: Add option for a consumer before spawning an item
1c537fce #590: Add spawn and transform reasons for piglin zombification.

CraftBukkit Changes:
ee5006d1 #810: Add option for a consumer before spawning an item
f6a39d3c #809: Add spawn and transform reasons for piglin zombification.
0c24068a Organise imports

Spigot Changes:
bff52619 Organise imports
2021-03-08 15:12:31 -08:00

53 lines
3.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 11 Jul 2020 03:54:28 -0400
Subject: [PATCH] Thread Safe Vanilla Command permission checking
Datapacks check this on load and are built concurrently. This was breaking them badly due
to race conditions.
Plus, .canUse we want to be safe for async anyways.
diff --git a/src/main/java/com/mojang/brigadier/tree/CommandNode.java b/src/main/java/com/mojang/brigadier/tree/CommandNode.java
index 6976da79b20280fcd72dcfb8b48e2eb73257faf2..d9c47f3fc18266df3be1f564c01dfc3e26941380 100644
--- a/src/main/java/com/mojang/brigadier/tree/CommandNode.java
+++ b/src/main/java/com/mojang/brigadier/tree/CommandNode.java
@@ -75,10 +75,10 @@ public abstract class CommandNode<S> implements Comparable<CommandNode<S>> {
public synchronized boolean canUse(final S source) {
if (source instanceof CommandListenerWrapper) {
try {
- ((CommandListenerWrapper) source).currentCommand = this;
+ ((CommandListenerWrapper) source).currentCommand.set(this); // Paper
return requirement.test(source);
} finally {
- ((CommandListenerWrapper) source).currentCommand = null;
+ ((CommandListenerWrapper) source).currentCommand.set(null); // Paper
}
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/CommandListenerWrapper.java b/src/main/java/net/minecraft/server/CommandListenerWrapper.java
index efe2391f1648f4f83e9b77fdc6d9d81653cf65b3..31543b38a7c46d93333c5f96fdb718b0a7a087b2 100644
--- a/src/main/java/net/minecraft/server/CommandListenerWrapper.java
+++ b/src/main/java/net/minecraft/server/CommandListenerWrapper.java
@@ -34,7 +34,7 @@ public class CommandListenerWrapper implements ICompletionProvider, com.destroys
private final ResultConsumer<CommandListenerWrapper> l;
private final ArgumentAnchor.Anchor m;
private final Vec2F n;
- public volatile CommandNode currentCommand; // CraftBukkit
+ public ThreadLocal<CommandNode> currentCommand = new ThreadLocal<>(); // CraftBukkit // Paper
public CommandListenerWrapper(ICommandListener icommandlistener, Vec3D vec3d, Vec2F vec2f, WorldServer worldserver, int i, String s, IChatBaseComponent ichatbasecomponent, MinecraftServer minecraftserver, @Nullable Entity entity) {
this(icommandlistener, vec3d, vec2f, worldserver, i, s, ichatbasecomponent, minecraftserver, entity, false, (commandcontext, flag, j) -> {
@@ -151,9 +151,11 @@ public class CommandListenerWrapper implements ICompletionProvider, com.destroys
@Override
public boolean hasPermission(int i) {
// CraftBukkit start
- CommandNode currentCommand = this.currentCommand;
+ // Paper start - fix concurrency issue
+ CommandNode currentCommand = this.currentCommand.get();
if (currentCommand != null) {
return hasPermission(i, org.bukkit.craftbukkit.command.VanillaCommandWrapper.getPermission(currentCommand));
+ // Paper end
}
// CraftBukkit end