From 7fa1a8c6c76f62a958713069c7e715132b22f48a Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 16 Jan 2013 00:06:14 -0500 Subject: [PATCH] Make /mctop [skillname] work for localized skillnames --- .../nossr50/commands/mc/MctopCommand.java | 38 ++++++++++++------- .../java/com/gmail/nossr50/util/Skills.java | 22 ++++++++++- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java index bdbdc29ef..8f65db1d5 100644 --- a/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/mc/MctopCommand.java @@ -37,6 +37,9 @@ public class MctopCommand implements CommandExecutor { else if (Skills.isSkill(args[0])) { flatfileDisplay(1, args[0].toUpperCase(), sender); } + else if (Skills.isLocalizedSkill(args[0])) { + flatfileDisplay(1, Skills.translateLocalizedSkill(args[0]).toUpperCase(), sender); + } else { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); } @@ -44,13 +47,16 @@ public class MctopCommand implements CommandExecutor { return true; case 2: - if (!Skills.isSkill(args[0])) { - sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); - return true; - } - if (Misc.isInt(args[1])) { - flatfileDisplay(Integer.valueOf(args[1]), args[0].toUpperCase(), sender); + if (Skills.isSkill(args[0])) { + flatfileDisplay(Integer.valueOf(args[1]), args[0].toUpperCase(), sender); + } + else if (Skills.isLocalizedSkill(args[0])) { + flatfileDisplay(Integer.valueOf(args[1]), Skills.translateLocalizedSkill(args[0]).toUpperCase(), sender); + } + else { + sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); + } } else { sender.sendMessage(usage); @@ -78,6 +84,9 @@ public class MctopCommand implements CommandExecutor { else if (Skills.isSkill(args[0])) { sqlDisplay(1, args[0].toLowerCase(), sender); } + else if (Skills.isLocalizedSkill(args[0])) { + sqlDisplay(1, Skills.translateLocalizedSkill(args[0]).toLowerCase(), sender); + } else { sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); } @@ -85,13 +94,16 @@ public class MctopCommand implements CommandExecutor { return true; case 2: - if (!Skills.isSkill(args[0])) { - sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); - return true; - } - if (Misc.isInt(args[1])) { - sqlDisplay(Integer.valueOf(args[1]), args[0].toLowerCase(), sender); + if (Skills.isSkill(args[0])) { + sqlDisplay(Integer.valueOf(args[1]), args[0].toLowerCase(), sender); + } + else if (Skills.isLocalizedSkill(args[0])) { + sqlDisplay(Integer.valueOf(args[1]), Skills.translateLocalizedSkill(args[0]).toLowerCase(), sender); + } + else { + sender.sendMessage(LocaleLoader.getString("Commands.Skill.Invalid")); + } } else { sender.sendMessage(usage); @@ -110,7 +122,7 @@ public class MctopCommand implements CommandExecutor { SkillType skillType = SkillType.getSkill(skill); String[] info = Leaderboard.retrieveInfo(skillType, page); - if (skill.equals("ALL")) { + if (skill.equalsIgnoreCase("ALL")) { sender.sendMessage(LocaleLoader.getString("Commands.PowerLevel.Leaderboard")); } else { diff --git a/src/main/java/com/gmail/nossr50/util/Skills.java b/src/main/java/com/gmail/nossr50/util/Skills.java index 8704765b6..41b869c99 100644 --- a/src/main/java/com/gmail/nossr50/util/Skills.java +++ b/src/main/java/com/gmail/nossr50/util/Skills.java @@ -13,9 +13,7 @@ import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.SpoutConfig; import com.gmail.nossr50.datatypes.AbilityType; -import com.gmail.nossr50.datatypes.McMMOPlayer; import com.gmail.nossr50.datatypes.PlayerProfile; -import com.gmail.nossr50.datatypes.PlayerStat; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.ToolType; import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent; @@ -296,6 +294,26 @@ public class Skills { return false; } + public static boolean isLocalizedSkill(String skillName) { + for (SkillType skill : SkillType.values()) { + if (skillName.equalsIgnoreCase(LocaleLoader.getString(Misc.getCapitalized(skill.toString() + ".SkillName")))) { + return true; + } + } + + return false; + } + + public static String translateLocalizedSkill(String skillName) { + for (SkillType skill : SkillType.values()) { + if (skillName.equalsIgnoreCase(LocaleLoader.getString(Misc.getCapitalized(skill.toString() + ".SkillName")))) { + return skill.toString(); + } + } + + return null; + } + /** * Check if the player has any combat skill permissions. *