Fix prefixing issues with handleaschat/exclusions.

This commit is contained in:
asofold 2012-09-29 20:04:05 +02:00
parent d83d07c42a
commit 2518bf499d
2 changed files with 21 additions and 7 deletions

View File

@ -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);

View File

@ -92,6 +92,21 @@ public class CharPrefixTree<N extends CharNode<N>, L extends CharLookupEntry<N>>
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));
}