Ver código fonte

Revert back to ugly-alias in PlayerCommandPreprocessEvent for /skillname
commands.

GJ 12 anos atrás
pai
commit
9326921e2a

+ 0 - 4
src/main/java/com/gmail/nossr50/commands/CommandRegistrationHelper.java

@@ -47,9 +47,6 @@ public final class CommandRegistrationHelper {
             String commandName = skill.toString().toLowerCase();
             String localizedName = LocaleLoader.getString(Misc.getCapitalized(commandName) + ".SkillName").toLowerCase();
 
-            List<String> aliasList = new ArrayList<String>();
-            aliasList.add(localizedName);
-
             PluginCommand command;
 
             // Make us play nice with Essentials
@@ -60,7 +57,6 @@ public final class CommandRegistrationHelper {
                 command = mcMMO.p.getCommand(commandName);
             }
 
-            command.setAliases(aliasList);
             command.setDescription(LocaleLoader.getString("Commands.Description.Skill", Misc.getCapitalized(localizedName)));
             command.setPermission("mcmmo.commands." + commandName);
             command.setPermissionMessage(permissionsMessage);

+ 29 - 0
src/main/java/com/gmail/nossr50/listeners/PlayerListener.java

@@ -10,6 +10,7 @@ import org.bukkit.event.EventPriority;
 import org.bukkit.event.Listener;
 import org.bukkit.event.player.AsyncPlayerChatEvent;
 import org.bukkit.event.player.PlayerChangedWorldEvent;
+import org.bukkit.event.player.PlayerCommandPreprocessEvent;
 import org.bukkit.event.player.PlayerFishEvent;
 import org.bukkit.event.player.PlayerInteractEvent;
 import org.bukkit.event.player.PlayerJoinEvent;
@@ -347,4 +348,32 @@ public class PlayerListener implements Listener {
             event.setCancelled(true);
         }
     }
+
+    /**
+     * Handle "ugly" aliasing /skillname commands, since setAliases doesn't work.
+     *
+     * @param event The event to watch
+     */
+    @EventHandler(priority = EventPriority.LOWEST)
+    public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
+        if (!Config.getInstance().getLocale().equalsIgnoreCase("en_US")) {
+            String message = event.getMessage();
+            String command = message.substring(1).split(" ")[0];
+            String lowerCaseCommand = command.toLowerCase();
+
+            for (SkillType skill : SkillType.values()) {
+                String commandName = skill.toString().toLowerCase();
+                String localizedName = LocaleLoader.getString(Misc.getCapitalized(commandName) + ".SkillName").toLowerCase();
+
+                if (lowerCaseCommand.equals(localizedName)) {
+                    break;
+                }
+
+                if (lowerCaseCommand.equals(commandName)) {
+                    event.setMessage(message.replace(command, localizedName));
+                    break;
+                }
+            }
+        }
+    }
 }