From b7d7646641d0f5026be70861ef74d1ef4eed7f15 Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Fri, 2 Jul 2021 16:14:20 +0200 Subject: [PATCH] fix subcommand blocker subcommandblocker broke when command included part of the subcommand, so for ex. /help he would remove "he" from the command and it would return as "/lp". --- pom.xml | 2 +- .../listeners/PlayerCommandPreProcessListener.java | 3 +-- .../listeners/TabCompleteBlockerListener.java | 14 +++++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 0fda030..4634371 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ eu.endermite CommandWhitelist - 1.7.7 + 1.7.8 jar CommandWhitelist diff --git a/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/PlayerCommandPreProcessListener.java b/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/PlayerCommandPreProcessListener.java index 1529dc7..3a73609 100644 --- a/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/PlayerCommandPreProcessListener.java +++ b/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/PlayerCommandPreProcessListener.java @@ -27,10 +27,9 @@ public class PlayerCommandPreProcessListener implements Listener { for (String comm : s.getValue()) { comm = comm.toLowerCase(); if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) { - String rawCmd = event.getMessage(); List bannedSubCommands = CommandsList.getSuggestions(player); for (String bannedSubCommand : bannedSubCommands) { - if (rawCmd.startsWith(bannedSubCommand)) { + if (command.startsWith(bannedSubCommand)) { event.setCancelled(true); ConfigCache config = CommandWhitelist.getConfigCache(); player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied()))); diff --git a/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/TabCompleteBlockerListener.java b/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/TabCompleteBlockerListener.java index 9c61816..a7dada1 100644 --- a/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/TabCompleteBlockerListener.java +++ b/src/main/java/eu/endermite/commandwhitelist/spigot/listeners/TabCompleteBlockerListener.java @@ -14,14 +14,22 @@ public class TabCompleteBlockerListener implements Listener { return; Player player = (Player) event.getSender(); String buffer = event.getBuffer(); - String cmd = buffer.replace(CommandsList.getLastArgument(buffer), ""); + List blockedCommands = CommandsList.getSuggestions(player); List suggestions = event.getCompletions(); + for (String s : blockedCommands) { String slast = CommandsList.getLastArgument(s); String scommand = s.replace(slast, ""); - cmd = cmd.replace(CommandsList.getLastArgument(cmd), ""); - if (cmd.startsWith("/" + scommand)) { + String[] cmdSplit = buffer.split(" "); + StringBuilder cmdBuilder = new StringBuilder(); + for (int i = 0; i <= cmdSplit.length-1; i++) + cmdBuilder.append(cmdSplit[i]).append(" "); + + String cmd = cmdBuilder.toString(); + if (cmd.startsWith("/"+scommand)) { + // This sometimes throws exceptions. No clue why, it just does. try/catch is the only fix. + // Probably happening when plugin adds suggestions in this event on the same priority - not confirmed. try { while (suggestions.contains(slast)) suggestions.remove(slast);