Improve command permission lookups

This allows us to append to the vanilla permission check object to avoid having to look into a map.

This also fixes non vanilla commands from technically being able to be skipped through permissions.
This commit is contained in:
Owen1212055
2025-06-06 22:11:49 -04:00
parent 94fefb88e6
commit 73d218c154
4 changed files with 29 additions and 35 deletions

View File

@@ -9,11 +9,10 @@
public static final SimpleCommandExceptionType ERROR_NOT_PLAYER = new SimpleCommandExceptionType(Component.translatable("permissions.requires.player"));
public static final SimpleCommandExceptionType ERROR_NOT_ENTITY = new SimpleCommandExceptionType(Component.translatable("permissions.requires.entity"));
public final CommandSource source;
@@ -65,6 +_,8 @@
@@ -65,6 +_,7 @@
private final Vec2 rotation;
private final CommandSigningContext signingContext;
private final TaskChainer chatMessageChainer;
+ public java.util.Map<Thread, com.mojang.brigadier.tree.CommandNode> currentCommand = new java.util.concurrent.ConcurrentHashMap<>(); // CraftBukkit // Paper - Thread Safe Vanilla Command permission checking
+ public boolean bypassSelectorPermissions = false; // Paper - add bypass for selector permissions
public CommandSourceStack(
@@ -49,19 +48,7 @@
public CommandSourceStack withRotation(Vec2 rotation) {
return this.rotation.equals(rotation)
? this
@@ -393,9 +_,44 @@
@Override
public boolean hasPermission(int level) {
+ // CraftBukkit start
+ // Paper start - Thread Safe Vanilla Command permission checking
+ com.mojang.brigadier.tree.CommandNode currentCommand = this.currentCommand.get(Thread.currentThread());
+ if (currentCommand != null) {
+ return this.hasPermission(level, org.bukkit.craftbukkit.command.VanillaCommandWrapper.getPermission(currentCommand));
+ // Paper end - Thread Safe Vanilla Command permission checking
+ }
+ // CraftBukkit end
+
@@ -396,6 +_,32 @@
return this.permissionLevel >= level;
}