From 002e4df8a338ba5a7c318edd4cf86775f4180d7f Mon Sep 17 00:00:00 2001 From: Pratik Date: Sat, 28 Sep 2024 11:14:32 -0500 Subject: [PATCH] Friend notes remove on delete --- .../friendnotes/FriendNotesConfig.java | 19 +++- .../friendnotes/FriendNotesPlugin.java | 105 +++++++++--------- 2 files changed, 69 insertions(+), 55 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesConfig.java index abaa5915f71..4a245d9521d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesConfig.java @@ -34,13 +34,24 @@ public interface FriendNotesConfig extends Config { @ConfigItem( - keyName = "showIcons", - name = "Show Icons", - description = "Show icons on friend or ignore list", - position = 1 + keyName = "showIcons", + name = "Show Icons", + description = "Show icons on friend or ignore list", + position = 1 ) default boolean showIcons() { return true; } + + @ConfigItem( + keyName = "removeNoteOnDelete", + name = "Remove Note On Delete", + description = "Remove the note when a player is deleted", + position = 2 + ) + default boolean removeNoteOnDelete() + { + return false; + } } 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 22435ca7bcb..2a72e4837d6 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 @@ -64,8 +64,8 @@ @Slf4j @PluginDescriptor( - name = "Friend Notes", - description = "Store notes about your friends" + name = "Friend Notes", + description = "Store notes about your friends" ) public class FriendNotesPlugin extends Plugin { @@ -75,7 +75,7 @@ public class FriendNotesPlugin extends Plugin private static final String ADD_NOTE = "Add Note"; private static final String EDIT_NOTE = "Edit Note"; private static final String NOTE_PROMPT_FORMAT = "%s's Notes
" + - ColorUtil.prependColorTag("(Limit %s Characters)", new Color(0, 0, 170)); + ColorUtil.prependColorTag("(Limit %s Characters)", new Color(0, 0, 170)); private static final int ICON_WIDTH = 14; private static final int ICON_HEIGHT = 12; @@ -237,30 +237,30 @@ public void onMenuEntryAdded(MenuEntryAdded event) // Build "Add Note" or "Edit Note" menu entry client.createMenuEntry(-1) - .setOption(hoveredFriend == null || hoveredFriend.getNote() == null ? ADD_NOTE : EDIT_NOTE) - .setType(MenuAction.RUNELITE) - .setTarget(event.getTarget()) //Preserve color codes here - .onClick(e -> - { - //Friends have color tags - final String sanitizedTarget = Text.toJagexName(Text.removeTags(e.getTarget())); - final String note = getFriendNote(sanitizedTarget); - - // Open the new chatbox input dialog - chatboxPanelManager.openTextInput(String.format(NOTE_PROMPT_FORMAT, sanitizedTarget, CHARACTER_LIMIT)) - .value(Strings.nullToEmpty(note)) - .onDone((content) -> - { - if (content == null) - { - return; - } - - content = Text.removeTags(content).trim(); - log.debug("Set note for '{}': '{}'", sanitizedTarget, content); - setFriendNote(sanitizedTarget, content); - }).build(); - }); + .setOption(hoveredFriend == null || hoveredFriend.getNote() == null ? ADD_NOTE : EDIT_NOTE) + .setType(MenuAction.RUNELITE) + .setTarget(event.getTarget()) //Preserve color codes here + .onClick(e -> + { + //Friends have color tags + final String sanitizedTarget = Text.toJagexName(Text.removeTags(e.getTarget())); + final String note = getFriendNote(sanitizedTarget); + + // Open the new chatbox input dialog + chatboxPanelManager.openTextInput(String.format(NOTE_PROMPT_FORMAT, sanitizedTarget, CHARACTER_LIMIT)) + .value(Strings.nullToEmpty(note)) + .onDone((content) -> + { + if (content == null) + { + return; + } + + content = Text.removeTags(content).trim(); + log.debug("Set note for '{}': '{}'", sanitizedTarget, content); + setFriendNote(sanitizedTarget, content); + }).build(); + }); } else if (hoveredFriend != null) { @@ -282,8 +282,8 @@ public void onNameableNameChanged(NameableNameChanged event) if (prevName != null) { migrateFriendNote( - Text.toJagexName(name), - Text.toJagexName(prevName) + Text.toJagexName(name), + Text.toJagexName(prevName) ); } } @@ -292,10 +292,13 @@ public void onNameableNameChanged(NameableNameChanged event) @Subscribe public void onRemovedFriend(RemovedFriend event) { - // Delete a friend's note if they are removed - final String displayName = Text.toJagexName(event.getNameable().getName()); - log.debug("Remove friend: '{}'", displayName); - setFriendNote(displayName, null); + if (config.removeNoteOnDelete()) + { + // Delete a friend's note if they are removed + final String displayName = Text.toJagexName(event.getNameable().getName()); + log.debug("Remove friend: '{}'", displayName); + setFriendNote(displayName, null); + } } @Subscribe @@ -340,16 +343,16 @@ private void rebuildFriendsList() { log.debug("Rebuilding friends list"); client.runScript( - ScriptID.FRIENDS_UPDATE, - ComponentID.FRIEND_LIST_FULL_CONTAINER, - ComponentID.FRIEND_LIST_SORT_BY_NAME_BUTTON, - ComponentID.FRIEND_LIST_SORT_BY_LAST_WORLD_CHANGE_BUTTON, - ComponentID.FRIEND_LIST_SORT_BY_WORLD_BUTTON, - ComponentID.FRIEND_LIST_LEGACY_SORT_BUTTON, - ComponentID.FRIEND_LIST_NAMES_CONTAINER, - ComponentID.FRIEND_LIST_SCROLL_BAR, - ComponentID.FRIEND_LIST_LOADING_TEXT, - ComponentID.FRIEND_LIST_PREVIOUS_NAME_HOLDER + ScriptID.FRIENDS_UPDATE, + ComponentID.FRIEND_LIST_FULL_CONTAINER, + ComponentID.FRIEND_LIST_SORT_BY_NAME_BUTTON, + ComponentID.FRIEND_LIST_SORT_BY_LAST_WORLD_CHANGE_BUTTON, + ComponentID.FRIEND_LIST_SORT_BY_WORLD_BUTTON, + ComponentID.FRIEND_LIST_LEGACY_SORT_BUTTON, + ComponentID.FRIEND_LIST_NAMES_CONTAINER, + ComponentID.FRIEND_LIST_SCROLL_BAR, + ComponentID.FRIEND_LIST_LOADING_TEXT, + ComponentID.FRIEND_LIST_PREVIOUS_NAME_HOLDER ); }); } @@ -360,14 +363,14 @@ private void rebuildIgnoreList() { log.debug("Rebuilding ignore list"); client.runScript( - ScriptID.IGNORE_UPDATE, - ComponentID.IGNORE_LIST_FULL_CONTAINER, - ComponentID.IGNORE_LIST_SORT_BY_NAME_BUTTON, - ComponentID.IGNORE_LIST_LEGACY_SORT_BUTTON, - ComponentID.IGNORE_LIST_NAMES_CONTAINER, - ComponentID.IGNORE_LIST_SCROLL_BAR, - ComponentID.IGNORE_LIST_LOADING_TEXT, - ComponentID.IGNORE_LIST_PREVIOUS_NAME_HOLDER + ScriptID.IGNORE_UPDATE, + ComponentID.IGNORE_LIST_FULL_CONTAINER, + ComponentID.IGNORE_LIST_SORT_BY_NAME_BUTTON, + ComponentID.IGNORE_LIST_LEGACY_SORT_BUTTON, + ComponentID.IGNORE_LIST_NAMES_CONTAINER, + ComponentID.IGNORE_LIST_SCROLL_BAR, + ComponentID.IGNORE_LIST_LOADING_TEXT, + ComponentID.IGNORE_LIST_PREVIOUS_NAME_HOLDER ); }); }