diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java index a79e049bc7..da5faafebb 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/ChatCommandsPlugin.java @@ -148,7 +148,7 @@ public class ChatCommandsPlugin extends Plugin /** * Checks if the chat message is a command. * - * @param setMessage The chat message + * @param setMessage The chat message. */ @Subscribe public void onSetMessage(SetMessage setMessage) @@ -172,7 +172,7 @@ public class ChatCommandsPlugin extends Plugin String message = setMessage.getValue(); MessageNode messageNode = setMessage.getMessageNode(); - // clear runelite formatted messsage as the message node is + // clear RuneLite formatted message as the message node is // being reused messageNode.setRuneLiteFormatMessage(null); @@ -200,7 +200,7 @@ public class ChatCommandsPlugin extends Plugin /** * Looks up the item price and changes the original message to the - * reponse. + * response. * * @param messageNode The chat message containing the command. * @param search The item given with the command. @@ -273,13 +273,15 @@ public class ChatCommandsPlugin extends Plugin /** * Looks up the player skill and changes the original message to the - * reponse. + * response. * * @param setMessage The chat message containing the command. * @param search The item given with the command. */ private void playerSkillLookup(ChatMessageType type, SetMessage setMessage, String search) { + search = SkillAbbreviations.getFullName(search); + String player; if (type.equals(ChatMessageType.PRIVATE_MESSAGE_SENT)) { @@ -289,13 +291,6 @@ public class ChatCommandsPlugin extends Plugin { player = sanitize(setMessage.getName()); } - try - { - search = SkillAbbreviations.valueOf(search.toUpperCase()).getName(); - } - catch (IllegalArgumentException i) - { - } HiscoreSkill skill; try @@ -341,7 +336,7 @@ public class ChatCommandsPlugin extends Plugin /** * Compares the names of the items in the list with the original input. - * returns the item if its name is equal to the original input or null + * Returns the item if its name is equal to the original input or null * if it can't find the item. * * @param items List of items. @@ -361,11 +356,11 @@ public class ChatCommandsPlugin extends Plugin } /** - * Cleans the playername string from ironman status icon if present and - * corrects spaces + * Cleans the ironman status icon from playername string if present and + * corrects spaces. * - * @param lookup Playername to lookup - * @return Cleaned playername + * @param lookup Playername to lookup. + * @return Cleaned playername. */ private static String sanitize(String lookup) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/SkillAbbreviations.java b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/SkillAbbreviations.java index 698fe5b1fb..da89769172 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/SkillAbbreviations.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chatcommands/SkillAbbreviations.java @@ -24,29 +24,67 @@ */ package net.runelite.client.plugins.chatcommands; -enum SkillAbbreviations +import java.util.HashMap; +import java.util.Map; +import net.runelite.api.Skill; + +class SkillAbbreviations { - ATT("Attack"), - DEF("Defence"), - STR("Strength"), - HP("Hitpoints"), - RANGE("Ranged"), - WC("Woodcutting"), - FM("Firemaking"), - RUNECRAFTING("Runecraft"), - RC("Runecraft"), - CON("Construction"), - TOTAL("Overall"); + private static final Map MAP = new HashMap<>(); - private final String name; - - SkillAbbreviations(String name) + static { - this.name = name; + MAP.put("ATK", Skill.ATTACK.getName()); + MAP.put("ATT", Skill.ATTACK.getName()); + MAP.put("DEF", Skill.DEFENCE.getName()); + MAP.put("STR", Skill.STRENGTH.getName()); + MAP.put("HEALTH", Skill.HITPOINTS.getName()); + MAP.put("HIT", Skill.HITPOINTS.getName()); + MAP.put("HITPOINT", Skill.HITPOINTS.getName()); + MAP.put("HP", Skill.HITPOINTS.getName()); + MAP.put("RANGE", Skill.RANGED.getName()); + MAP.put("RANGING", Skill.RANGED.getName()); + MAP.put("RNG", Skill.RANGED.getName()); + MAP.put("PRAY", Skill.PRAYER.getName()); + MAP.put("MAG", Skill.MAGIC.getName()); + MAP.put("MAGE", Skill.MAGIC.getName()); + MAP.put("COOK", Skill.COOKING.getName()); + MAP.put("WC", Skill.WOODCUTTING.getName()); + MAP.put("WOOD", Skill.WOODCUTTING.getName()); + MAP.put("WOODCUT", Skill.WOODCUTTING.getName()); + MAP.put("FLETCH", Skill.FLETCHING.getName()); + MAP.put("FISH", Skill.FISHING.getName()); + MAP.put("FM", Skill.FIREMAKING.getName()); + MAP.put("FIRE", Skill.FIREMAKING.getName()); + MAP.put("CRAFT", Skill.CRAFTING.getName()); + MAP.put("SMITH", Skill.SMITHING.getName()); + MAP.put("MINE", Skill.MINING.getName()); + MAP.put("HL", Skill.HERBLORE.getName()); + MAP.put("HERB", Skill.HERBLORE.getName()); + MAP.put("AGI", Skill.AGILITY.getName()); + MAP.put("AGIL", Skill.AGILITY.getName()); + MAP.put("THIEF", Skill.THIEVING.getName()); + MAP.put("SLAY", Skill.SLAYER.getName()); + MAP.put("FARM", Skill.FARMING.getName()); + MAP.put("RC", Skill.RUNECRAFT.getName()); + MAP.put("RUNE", Skill.RUNECRAFT.getName()); + MAP.put("RUNECRAFTING", Skill.RUNECRAFT.getName()); + MAP.put("HUNT", Skill.HUNTER.getName()); + MAP.put("CON", Skill.CONSTRUCTION.getName()); + MAP.put("CONSTRUCT", Skill.CONSTRUCTION.getName()); + MAP.put("ALL", Skill.OVERALL.getName()); + MAP.put("TOTAL", Skill.OVERALL.getName()); } - public String getName() + /** + * Takes a string representing the name of a skill, and if abbreviated, + * expands it into its full canonical name. Case-insensitive. + * + * @param abbrev Skill name that may be abbreviated. + * @return Full skill name if recognized, else the original string. + */ + static String getFullName(String abbrev) { - return name; + return MAP.getOrDefault(abbrev.toUpperCase(), abbrev); } }