Skip to content

Commit

Permalink
Friend notes remove on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
pratik-p committed Sep 28, 2024
1 parent 2316e2b commit 002e4df
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<br>" +
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;

Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
);
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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
);
});
}
Expand All @@ -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
);
});
}
Expand Down

0 comments on commit 002e4df

Please sign in to comment.