From 2518bf499db55b1c4e57cb9d74a641b6b6e0e408 Mon Sep 17 00:00:00 2001 From: asofold Date: Sat, 29 Sep 2012 20:04:05 +0200 Subject: [PATCH] Fix prefixing issues with handleaschat/exclusions. --- .../nocheatplus/checks/chat/ChatListener.java | 13 ++++++------- .../utilities/ds/prefixtree/CharPrefixTree.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java b/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java index e36de079..06afcd2d 100644 --- a/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/chat/ChatListener.java @@ -132,14 +132,15 @@ public class ChatListener implements Listener, INotifyReload { // Trim is necessary because the server accepts leading spaces with commands. // TODO: Maybe: only remove the leading whitespace or spaces. - final String command = event.getMessage().trim().split(" ")[0].substring(1).toLowerCase(); + final String lcMessage = event.getMessage().trim().toLowerCase(); + final String command = lcMessage.split(" ")[0].substring(1); final ChatConfig cc = ChatConfig.getConfig(player); // Protect some commands to prevent players for seeing which plugins are installed. if (cc.protectPlugins) - if ((command.equalsIgnoreCase("plugins") || command.equalsIgnoreCase("pl") - || command.equalsIgnoreCase("version") || command.equalsIgnoreCase("ver")) + if ((command.equals("plugins") || command.equals("pl") + || command.equals("version") || command.equals("ver")) && !player.hasPermission(Permissions.ADMINISTRATION_PLUGINS)) { event.getPlayer().sendMessage( ChatColor.RED + "I'm sorry, but you do not have permission to perform this command. " @@ -159,12 +160,10 @@ public class ChatListener implements Listener, INotifyReload { // First the color check. if (color.isEnabled(player)) event.setMessage(color.check(player, event.getMessage(), true)); - final String lcMessage = event.getMessage().trim().toLowerCase(); - - final boolean handleAsChat = chatCommands.hasPrefix(lcMessage); + final boolean handleAsChat = chatCommands.hasPrefixWords(lcMessage); // Then the no pwnage check. - if (!commandExclusions.hasPrefix(lcMessage) && noPwnage.isEnabled(player) && noPwnage.check(player, event.getMessage(), !handleAsChat, true)) + if (!commandExclusions.hasPrefixWords(lcMessage) && noPwnage.isEnabled(player) && noPwnage.check(player, event.getMessage(), !handleAsChat, true)) event.setCancelled(true); else if (handleAsChat && globalChat.isEnabled(player) && globalChat.check(player, event.getMessage(), noPwnage, true)) event.setCancelled(true); diff --git a/src/fr/neatmonster/nocheatplus/utilities/ds/prefixtree/CharPrefixTree.java b/src/fr/neatmonster/nocheatplus/utilities/ds/prefixtree/CharPrefixTree.java index eb45403b..06cb7f60 100644 --- a/src/fr/neatmonster/nocheatplus/utilities/ds/prefixtree/CharPrefixTree.java +++ b/src/fr/neatmonster/nocheatplus/utilities/ds/prefixtree/CharPrefixTree.java @@ -92,6 +92,21 @@ public class CharPrefixTree, L extends CharLookupEntry> return hasPrefix(input.toCharArray()); } + /** + * Quick and dirty addition: Test if a prefix is contained which either matches the whole input or does not end inside of a word in the input, i.e. the inputs next character is a space. + * @param lcMessage + * @return + */ + public boolean hasPrefixWords(final String input) { + // TODO build this in in a more general way (super classes + stop symbol)! + final L result = lookup(input, false); + if (!result.hasPrefix) return false; + if (input.length() == result.depth) return true; + if (Character.isWhitespace(input.charAt(result.depth))) return true; + System.out.println(input + " -> " + result.depth + ":" + input.charAt(result.depth)); + return false; + } + public boolean isPrefix(final char[] chars){ return isPrefix(toCharacterList(chars)); }