From 3159a02edf48b7cc36eb6c20c3c20fd6d162b67a Mon Sep 17 00:00:00 2001 From: Jordan Atwood Date: Thu, 2 Aug 2018 11:59:27 -0700 Subject: [PATCH] chat commands plugin: Use consistent message check All chat messages are either checked for equality to command strings which are not followed by spaces or are checked to start with command strings followed by a space, and use the constants' length (plus one, for the space) to get the command argument. --- .../chatcommands/ChatCommandsPlugin.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) 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 8612ee1f19..473892fbf5 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 @@ -86,6 +86,11 @@ public class ChatCommandsPlugin extends Plugin implements ChatboxInputListener private static final Pattern RAIDS_PATTERN = Pattern.compile("Your completed (.+) count is: (\\d+)."); private static final Pattern WINTERTODT_PATERN = Pattern.compile("Your subdued Wintertodt count is: (\\d+)."); private static final Pattern BARROWS_PATERN = Pattern.compile("Your Barrows chest count is: (\\d+)."); + private static final String TOTAL_LEVEL_COMMAND_STRING = "!total"; + private static final String PRICE_COMMAND_STRING = "!price"; + private static final String LEVEL_COMMAND_STRING = "!lvl"; + private static final String CLUES_COMMAND_STRING = "!clues"; + private static final String KILLCOUNT_COMMAND_STRING = "!kc"; private final HiscoreClient hiscoreClient = new HiscoreClient(); private final KillCountClient killCountClient = new KillCountClient(); @@ -184,40 +189,40 @@ public class ChatCommandsPlugin extends Plugin implements ChatboxInputListener // being reused messageNode.setRuneLiteFormatMessage(null); - if (config.lvl() && message.toLowerCase().equals("!total")) + if (config.lvl() && message.toLowerCase().equals(TOTAL_LEVEL_COMMAND_STRING)) { log.debug("Running total level lookup"); executor.submit(() -> playerSkillLookup(setMessage, "total")); } - else if (config.price() && message.toLowerCase().startsWith("!price") && message.length() > 7) + else if (config.price() && message.toLowerCase().startsWith(PRICE_COMMAND_STRING + " ")) { - String search = message.substring(7); + String search = message.substring(PRICE_COMMAND_STRING.length() + 1); log.debug("Running price lookup for {}", search); executor.submit(() -> itemPriceLookup(setMessage.getMessageNode(), search)); } - else if (config.lvl() && message.toLowerCase().startsWith("!lvl") && message.length() > 5) + else if (config.lvl() && message.toLowerCase().startsWith(LEVEL_COMMAND_STRING + " ")) { - String search = message.substring(5); + String search = message.substring(LEVEL_COMMAND_STRING.length() + 1); log.debug("Running level lookup for {}", search); executor.submit(() -> playerSkillLookup(setMessage, search)); } - else if (config.clue() && message.toLowerCase().equals("!clues")) + else if (config.clue() && message.toLowerCase().equals(CLUES_COMMAND_STRING)) { log.debug("Running lookup for overall clues"); executor.submit(() -> playerClueLookup(setMessage, "total")); } - else if (config.clue() && message.toLowerCase().startsWith("!clues") && message.length() > 7) + else if (config.clue() && message.toLowerCase().startsWith(CLUES_COMMAND_STRING + " ")) { - String search = message.substring(7); + String search = message.substring(CLUES_COMMAND_STRING.length() + 1); log.debug("Running clue lookup for {}", search); executor.submit(() -> playerClueLookup(setMessage, search)); } - else if (config.killcount() && message.toLowerCase().startsWith("!kc ")) + else if (config.killcount() && message.toLowerCase().startsWith(KILLCOUNT_COMMAND_STRING + " ")) { - String search = message.substring(4); + String search = message.substring(KILLCOUNT_COMMAND_STRING.length() + 1); log.debug("Running killcount lookup for {}", search); executor.submit(() -> killCountLookup(setMessage.getType(), setMessage, search));