From 2f999217dfc46a7a84e32c0cff269302a60622eb Mon Sep 17 00:00:00 2001 From: Zffu Date: Sat, 18 May 2024 00:27:31 +0200 Subject: [PATCH 1/2] Changed command blocker to work with command names --- src/main/java/org/mineacademy/fo/Common.java | 36 +++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/mineacademy/fo/Common.java b/src/main/java/org/mineacademy/fo/Common.java index 86760198e..320648287 100644 --- a/src/main/java/org/mineacademy/fo/Common.java +++ b/src/main/java/org/mineacademy/fo/Common.java @@ -1214,7 +1214,9 @@ public static void dispatchCommandAsPlayer(@NonNull final Player playerSender, @ if (command.startsWith("/") && !command.startsWith("//")) command = command.substring(1); - checkBlockedCommands(playerSender, command); + String commandName = command.split(" ")[0]; + + checkBlockedCommands(playerSender, commandName, command); final String finalCommand = command; @@ -1225,22 +1227,22 @@ public static void dispatchCommandAsPlayer(@NonNull final Player playerSender, @ * A pitiful attempt at blocking a few known commands which might have been used for malicious intent. * We log the attempt to a file for manual review. */ - private static boolean checkBlockedCommands(@Nullable CommandSender sender, String command) { - if (command.startsWith("gm ") || - command.startsWith("gmc ") || - command.startsWith("gms ") || - command.startsWith("gamemode ") || - command.startsWith("essentials:gamemode ") || - command.startsWith("essentials:gm ") || - command.startsWith("minecraft:gamemode ") || - command.startsWith("op ") || - command.startsWith("minecraft:op ") || - command.startsWith("lp ") || - command.startsWith("lp:") || - command.startsWith("luckperms ") || - command.startsWith("luckperms:")) { - - final String errorMessage = (sender != null ? sender.getName() : "Console") + " tried to run blocked command: " + command; + private static boolean checkBlockedCommands(@Nullable CommandSender sender, String commandName, String command) { + + if(commandName.startsWith("gm") || + commandName.equals("gamemode") || + commandName.equals("essentials:gamemode") || + commandName.equals("essentials:gm") || + commandName.equals("minecraft:gamemode") || + commandName.equals("op") || + commandName.equals("minecraft:op") || + commandName.equals("lp") || + commandName.equals("lp:") || + commandName.equals("luckperms") || + commandName.equals("luckperms:")) { + + + final String errorMessage = (sender != null ? sender.getName() : "Console") + " tried to run blocked command: " + commandName; FileUtil.writeFormatted("blocked-commands.log", errorMessage); throw new FoException(errorMessage); From 7edf2b30752c27ea66c147824befeaa91bb4d32d Mon Sep 17 00:00:00 2001 From: Zffu Date: Sat, 18 May 2024 00:28:09 +0200 Subject: [PATCH 2/2] Changed command blocker to work with command names --- src/main/java/org/mineacademy/fo/Common.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/mineacademy/fo/Common.java b/src/main/java/org/mineacademy/fo/Common.java index 320648287..dbb80bbd5 100644 --- a/src/main/java/org/mineacademy/fo/Common.java +++ b/src/main/java/org/mineacademy/fo/Common.java @@ -1192,7 +1192,9 @@ else if (command.startsWith("@success ")) { if (!command.startsWith("tellraw")) command = colorize(command); - checkBlockedCommands(playerReplacement, command); + String commandName = command.split(" ")[0]; + + checkBlockedCommands(playerReplacement, commandName, command); final String finalCommand = command;