From 68b9857409f24f89e80b2cf7c86dfccc29d13e15 Mon Sep 17 00:00:00 2001 From: bm01 Date: Wed, 9 May 2012 13:06:40 +0200 Subject: [PATCH] Fixed / command being processed twice when an alias was used --- .../gmail/nossr50/listeners/PlayerListener.java | 16 +++++----------- src/main/java/com/gmail/nossr50/mcMMO.java | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index c7d72aa74..8197162b1 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -341,9 +341,6 @@ public class PlayerListener implements Listener { } } - // Dynamically aliasing commands need to be re-done. - // For now, using a command with an alias will send both the original command, and the mcMMO command - /** * Monitor PlayerCommandPreprocess events. * @@ -352,18 +349,15 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.LOWEST) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { String message = event.getMessage(); - - if (!message.startsWith("/")) { - return; - } - String command = message.substring(1).split(" ")[0]; - if (plugin.aliasMap.containsKey(command)) { - if (command.equalsIgnoreCase(plugin.aliasMap.get(command))) { + if (plugin.aliasMap.containsKey(command.toLowerCase())) { + //We should find a better way to avoid string replacement where the alias is equals to the command + if (command.equals(plugin.aliasMap.get(command.toLowerCase()))) { return; } - event.getPlayer().chat(message.replaceFirst(command, plugin.aliasMap.get(command))); + + event.setMessage(message.replace(command, plugin.aliasMap.get(command.toLowerCase()))); } } } diff --git a/src/main/java/com/gmail/nossr50/mcMMO.java b/src/main/java/com/gmail/nossr50/mcMMO.java index e61d5f938..ef9250a8e 100644 --- a/src/main/java/com/gmail/nossr50/mcMMO.java +++ b/src/main/java/com/gmail/nossr50/mcMMO.java @@ -227,7 +227,7 @@ public class mcMMO extends JavaPlugin { aliasMap.put(LocaleLoader.getString("Swords.SkillName").toLowerCase(), "swords"); aliasMap.put(LocaleLoader.getString("Taming.SkillName").toLowerCase(), "taming"); aliasMap.put(LocaleLoader.getString("Unarmed.SkillName").toLowerCase(), "unarmed"); - aliasMap.put(LocaleLoader.getString("WoodCutting.SkillName").toLowerCase(), "woodcutting"); + aliasMap.put(LocaleLoader.getString("Woodcutting.SkillName").toLowerCase(), "woodcutting"); //Register commands //Skills commands