From 86acb1c4d4444554dca543c7b9e33c1c7e2bd0bd Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Tue, 18 Apr 2023 17:28:38 +0200 Subject: [PATCH] Simplify command dispatch to ensure command order (#2131) --- .../platform/PlatformCommandManager.java | 43 ++++++++----------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index 3922710fc..7b493cf98 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -678,31 +678,26 @@ public final class PlatformCommandManager { Actor actor = event.getActor(); String args = event.getArguments(); - TaskManager.taskManager().taskNow(() -> { - if (!Fawe.isMainThread()) { - Thread.currentThread().setName("FAWE Thread for player: " + actor.getName()); + int space0 = args.indexOf(' '); + String arg0 = space0 == -1 ? args : args.substring(0, space0); + Optional optional = commandManager.getCommand(arg0); + if (optional.isEmpty()) { + return; + } + Command cmd = optional.get(); + PermissionCondition queued = cmd.getCondition().as(PermissionCondition.class).orElse(null); + if (queued != null && !queued.isQueued()) { + TaskManager.taskManager().taskNow(() -> handleCommandOnCurrentThread(event), Fawe.isMainThread()); + return; + } else { + actor.decline(); + } + actor.runAction(() -> { + SessionKey key = actor.getSessionKey(); + if (key.isActive()) { + PlatformCommandManager.this.handleCommandOnCurrentThread(event); } - int space0 = args.indexOf(' '); - String arg0 = space0 == -1 ? args : args.substring(0, space0); - Optional optional = commandManager.getCommand(arg0); - if (!optional.isPresent()) { - return; - } - Command cmd = optional.get(); - PermissionCondition queued = cmd.getCondition().as(PermissionCondition.class).orElse(null); - if (queued != null && !queued.isQueued()) { - handleCommandOnCurrentThread(event); - return; - } else { - actor.decline(); - } - actor.runAction(() -> { - SessionKey key = actor.getSessionKey(); - if (key.isActive()) { - PlatformCommandManager.this.handleCommandOnCurrentThread(event); - } - }, false, true); - }, Fawe.isMainThread()); + }, false, true); } public void handleCommandOnCurrentThread(CommandEvent event) {