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.
This commit is contained in:
Aikar
2020-07-11 03:54:28 -04:00
parent 3ceb5297a3
commit def8b96d4b
2 changed files with 9 additions and 7 deletions

View File

@@ -40,10 +40,10 @@
+ public synchronized boolean canUse(final S source) {
+ if (source instanceof CommandSourceStack) {
+ try {
+ ((CommandSourceStack) source).currentCommand = this;
+ ((CommandSourceStack) source).currentCommand.put(Thread.currentThread(), this); // Paper - Thread Safe Vanilla Command permission checking
+ return this.requirement.test(source);
+ } finally {
+ ((CommandSourceStack) source).currentCommand = null;
+ ((CommandSourceStack) source).currentCommand.remove(Thread.currentThread()); // Paper - Thread Safe Vanilla Command permission checking
+ }
+ }
+ // CraftBukkit end