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

@@ -24,25 +24,6 @@
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 +_,17 @@
return modifier;
}
- public boolean canUse(final S source) {
+ // CraftBukkit start
+ public synchronized boolean canUse(final S source) {
+ if (source instanceof final net.minecraft.commands.CommandSourceStack css) {
+ try {
+ css.currentCommand.put(Thread.currentThread(), this); // Paper - Thread Safe Vanilla Command permission checking
+ return this.requirement.test(source);
+ } finally {
+ css.currentCommand.remove(Thread.currentThread()); // Paper - Thread Safe Vanilla Command permission checking
+ }
+ }
+ // CraftBukkit end
return requirement.test(source);
}
@@ -151,6 +_,12 @@
protected abstract String getSortedKey();