From 6371a7dd0b0d49259e2a3326c62e1f3e2c0f28ac Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 11 Mar 2019 09:04:33 -0400 Subject: [PATCH 1/4] config manager: throttle config saves to file When the default config is applied it queues a lot of saves to disk that are unnecessary --- .../runelite/client/config/ConfigManager.java | 45 ++++++++----------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/config/ConfigManager.java b/runelite-client/src/main/java/net/runelite/client/config/ConfigManager.java index 54318b887a..dc3fc07e41 100644 --- a/runelite-client/src/main/java/net/runelite/client/config/ConfigManager.java +++ b/runelite-client/src/main/java/net/runelite/client/config/ConfigManager.java @@ -99,6 +99,9 @@ public class ConfigManager public final void switchSession(AccountSession session) { + // Ensure existing config is saved + sendConfig(); + if (session == null) { this.session = null; @@ -315,7 +318,7 @@ public class ConfigManager } } - private synchronized void saveToFile(final File propertiesFile) throws IOException + private void saveToFile(final File propertiesFile) throws IOException { propertiesFile.getParentFile().mkdirs(); @@ -392,19 +395,6 @@ public class ConfigManager pendingChanges.put(groupName + "." + key, value); } - Runnable task = () -> - { - try - { - saveToFile(propertiesFile); - } - catch (IOException ex) - { - log.warn("unable to save configuration file", ex); - } - }; - executor.execute(task); - ConfigChanged configChanged = new ConfigChanged(); configChanged.setGroup(groupName); configChanged.setKey(key); @@ -435,19 +425,6 @@ public class ConfigManager pendingChanges.put(groupName + "." + key, null); } - Runnable task = () -> - { - try - { - saveToFile(propertiesFile); - } - catch (IOException ex) - { - log.warn("unable to save configuration file", ex); - } - }; - executor.execute(task); - ConfigChanged configChanged = new ConfigChanged(); configChanged.setGroup(groupName); configChanged.setKey(key); @@ -653,6 +630,7 @@ public class ConfigManager public void sendConfig() { + boolean changed; synchronized (pendingChanges) { if (client != null) @@ -672,7 +650,20 @@ public class ConfigManager } } } + changed = !pendingChanges.isEmpty(); pendingChanges.clear(); } + + if (changed) + { + try + { + saveToFile(propertiesFile); + } + catch (IOException ex) + { + log.warn("unable to save configuration file", ex); + } + } } } From d617d1960ffa9bc50aab478b3c4bef5ce9d35e7c Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 11 Mar 2019 18:17:16 -0400 Subject: [PATCH 2/4] friend notes: replace nbsp from friend names in config keys --- .../friendnotes/FriendNotesPlugin.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java index beb56a171f..75cc26163c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java @@ -167,7 +167,7 @@ public class FriendNotesPlugin extends Plugin if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() && event.getOption().equals("Message")) { // Friends have color tags - setHoveredFriend(Text.removeTags(event.getTarget())); + setHoveredFriend(Text.toJagexName(Text.removeTags(event.getTarget()))); // Build "Add Note" or "Edit Note" menu entry final MenuEntry addNote = new MenuEntry(); @@ -197,13 +197,13 @@ public class FriendNotesPlugin extends Plugin return; } - //Friends have color tags - final String sanitizedTarget = Text.removeTags(event.getMenuTarget()); - // Handle clicks on "Add Note" or "Edit Note" if (event.getMenuOption().equals(ADD_NOTE) || event.getMenuOption().equals(EDIT_NOTE)) { event.consume(); + + //Friends have color tags + final String sanitizedTarget = Text.toJagexName(Text.removeTags(event.getMenuTarget())); final String note = getFriendNote(sanitizedTarget); // Open the new chatbox input dialog @@ -234,7 +234,16 @@ public class FriendNotesPlugin extends Plugin { // Migrate a friend's note to their new display name final Friend friend = (Friend) nameable; - migrateFriendNote(friend.getName(), friend.getPrevName()); + String name = friend.getName(); + String prevName = friend.getPrevName(); + + if (prevName != null) + { + migrateFriendNote( + Text.toJagexName(name), + Text.toJagexName(prevName) + ); + } } } @@ -242,7 +251,7 @@ public class FriendNotesPlugin extends Plugin public void onRemovedFriend(RemovedFriend event) { // Delete a friend's note if they are removed - final String displayName = event.getName(); + final String displayName = Text.toJagexName(event.getName()); log.debug("Remove friend: '{}'", displayName); setFriendNote(displayName, null); } From 5f0b7313379737149088545c8363ec943a810dc7 Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 12 Mar 2019 01:37:26 +0100 Subject: [PATCH 3/4] wiki plugin: add deselect on shutdown --- .../java/net/runelite/client/plugins/wiki/WikiPlugin.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/wiki/WikiPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/wiki/WikiPlugin.java index aaf6a084e9..afbc30b766 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/wiki/WikiPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/wiki/WikiPlugin.java @@ -131,6 +131,9 @@ public class WikiPlugin extends Plugin return; } children[0] = null; + + onDeselect(); + client.setSpellSelected(false); }); } @@ -186,7 +189,10 @@ public class WikiPlugin extends Plugin private void onDeselect() { wikiSelected = false; - icon.setSpriteId(WikiSprite.WIKI_ICON.getSpriteId()); + if (icon != null) + { + icon.setSpriteId(WikiSprite.WIKI_ICON.getSpriteId()); + } } @Subscribe From 0562e9e49e38007a7f2ea95143990e623fb45464 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 12 Mar 2019 08:29:16 -0400 Subject: [PATCH 4/4] chat commands: check message length before use If we don't check the length of the message before we access it with substring(command.length() + 1) we will get a string index out of range error. Co-authored-by: Paul Wendelboe --- .../chatcommands/ChatCommandsPlugin.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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 7295577e34..e7e22cdae3 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 @@ -366,6 +366,11 @@ public class ChatCommandsPlugin extends Plugin return; } + if (message.length() <= KILLCOUNT_COMMAND_STRING.length()) + { + return; + } + ChatMessageType type = chatMessage.getType(); String search = message.substring(KILLCOUNT_COMMAND_STRING.length() + 1); @@ -483,6 +488,11 @@ public class ChatCommandsPlugin extends Plugin return; } + if (message.length() <= PB_COMMAND.length()) + { + return; + } + ChatMessageType type = chatMessage.getType(); String search = message.substring(PB_COMMAND.length() + 1); @@ -574,6 +584,11 @@ public class ChatCommandsPlugin extends Plugin return; } + if (message.length() <= PRICE_COMMAND_STRING.length()) + { + return; + } + MessageNode messageNode = chatMessage.getMessageNode(); String search = message.substring(PRICE_COMMAND_STRING.length() + 1); @@ -637,6 +652,11 @@ public class ChatCommandsPlugin extends Plugin } else { + if (message.length() <= LEVEL_COMMAND_STRING.length()) + { + return; + } + search = message.substring(LEVEL_COMMAND_STRING.length() + 1); }