From 98df416d89af7230d24347656b558a2e60a043f3 Mon Sep 17 00:00:00 2001 From: Luna <90072930+LunaWasFlaggedAgain@users.noreply.github.com> Date: Sat, 25 Feb 2023 13:45:50 -0300 Subject: [PATCH] Fix /execute command blocker bug (#337) Fixes a bug where commands in /execute would not have modifications applied to them. Example: `/execute run particle flame ~ ~ ~ 1 1 1 0 100 force @s` would not get modified before this PR, but now it gets modified to `/execute run particle flame ~ ~ ~ 1 1 1 0 10 force @s` --- .../extras/modules/server/ServerCommand.java | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java b/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java index 03a5dbc..c264583 100644 --- a/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java +++ b/src/main/java/pw/kaboom/extras/modules/server/ServerCommand.java @@ -102,31 +102,32 @@ public final class ServerCommand implements Listener { } for (int i = 1; i < arr.length; i++) { - if ("run".equalsIgnoreCase(arr[i])) { - if (i + 1 == arr.length) { - break; - } - if (checkExecuteCommand(arr[i + 1])) { - return "cancel"; - } else { - final String[] executeCommand = Arrays.copyOfRange( - arr, i + 1, arr.length); - String result = checkCommand(sender, - String.join(" ", executeCommand), true, depth + 1); - if (result == null) { - continue; - } - switch (result) { - case "cancel": - return "cancel"; - default: - String pureExecute = String.join( - " ", Arrays.copyOfRange(arr, 0, i + 1)); - return checkCommand(sender, pureExecute + " " + result, - isConsoleCommand, depth + 1); - } - } + if (!"run".equalsIgnoreCase(arr[i])) { + continue; } + if (i + 1 == arr.length) { + break; + } + if (checkExecuteCommand(arr[i + 1])) { + return "cancel"; + } + final String[] executeCommand = Arrays.copyOfRange( + arr, i + 1, arr.length); + final String result = checkCommand(sender, + String.join(" ", executeCommand), true, depth + 1); + if (result == null) { + continue; + } else if (result == "cancel") { + return "cancel"; + } + final String pureExecute = String.join( + " ", Arrays.copyOfRange(arr, 0, i + 1)); + final String finalResult = checkCommand(sender, + pureExecute + " " + result, isConsoleCommand, depth + 1); + if (finalResult == null) { + return pureExecute + " " + result; + } + return finalResult; } } break;