friendslist: add option to hide per-friend login notifications
This commit is contained in:
@@ -28,9 +28,11 @@ import net.runelite.client.config.Config;
|
||||
import net.runelite.client.config.ConfigGroup;
|
||||
import net.runelite.client.config.ConfigItem;
|
||||
|
||||
@ConfigGroup("friendlist")
|
||||
@ConfigGroup(FriendListConfig.GROUP)
|
||||
public interface FriendListConfig extends Config
|
||||
{
|
||||
String GROUP = "friendlist";
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "showWorldOnLogin",
|
||||
name = "Show world on login",
|
||||
|
||||
@@ -26,30 +26,40 @@
|
||||
package net.runelite.client.plugins.friendlist;
|
||||
|
||||
import com.google.inject.Provides;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Iterator;
|
||||
import javax.inject.Inject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.ChatPlayer;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Friend;
|
||||
import net.runelite.api.Ignore;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.NameableContainer;
|
||||
import net.runelite.api.PendingLogin;
|
||||
import net.runelite.api.ScriptID;
|
||||
import net.runelite.api.VarPlayer;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.api.events.ScriptPostFired;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.chat.QueuedMessage;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.task.Schedule;
|
||||
import net.runelite.client.util.Text;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Friend List",
|
||||
description = "Add extra information to the friend and ignore lists"
|
||||
)
|
||||
@Slf4j
|
||||
public class FriendListPlugin extends Plugin
|
||||
{
|
||||
private static final int MAX_FRIENDS_P2P = 400;
|
||||
@@ -58,12 +68,21 @@ public class FriendListPlugin extends Plugin
|
||||
private static final int MAX_IGNORES_P2P = 400;
|
||||
private static final int MAX_IGNORES_F2P = 100;
|
||||
|
||||
private static final String HIDE_NOTIFICATIONS = "Hide notifications";
|
||||
private static final String SHOW_NOTIFICATIONS = "Show notifications";
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private FriendListConfig config;
|
||||
|
||||
@Inject
|
||||
private ConfigManager configManager;
|
||||
|
||||
@Inject
|
||||
private ChatMessageManager chatMessageManager;
|
||||
|
||||
@Provides
|
||||
FriendListConfig getConfig(ConfigManager configManager)
|
||||
{
|
||||
@@ -144,6 +163,46 @@ public class FriendListPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onMenuEntryAdded(MenuEntryAdded event)
|
||||
{
|
||||
final int groupId = WidgetInfo.TO_GROUP(event.getActionParam1());
|
||||
|
||||
// Look for "Message" on friends list
|
||||
if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() && event.getOption().equals("Message"))
|
||||
{
|
||||
String friend = Text.toJagexName(Text.removeTags(event.getTarget()));
|
||||
|
||||
client.createMenuEntry(-1)
|
||||
.setOption(isHideNotification(friend) ? SHOW_NOTIFICATIONS : HIDE_NOTIFICATIONS)
|
||||
.setType(MenuAction.RUNELITE)
|
||||
.setTarget(event.getTarget()) //Preserve color codes here
|
||||
.onClick(e ->
|
||||
{
|
||||
boolean hidden = isHideNotification(friend);
|
||||
setHideNotifications(friend, !hidden);
|
||||
chatMessageManager.queue(QueuedMessage.builder()
|
||||
.type(ChatMessageType.CONSOLE)
|
||||
.value("Login notifications for " + friend + " are now " + (hidden ? "shown." : "hidden."))
|
||||
.build());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Schedule(period = 5, unit = ChronoUnit.SECONDS)
|
||||
public void setHideNotifications()
|
||||
{
|
||||
for (Iterator<PendingLogin> it = client.getFriendContainer().getPendingLogins().iterator(); it.hasNext(); )
|
||||
{
|
||||
PendingLogin pendingLogin = it.next();
|
||||
if (isHideNotification(Text.toJagexName(pendingLogin.getName())))
|
||||
{
|
||||
log.debug("Removing login notification for {}", pendingLogin.getName());
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setFriendsListTitle(final String title)
|
||||
{
|
||||
Widget friendListTitleWidget = client.getWidget(WidgetInfo.FRIEND_CHAT_TITLE);
|
||||
@@ -173,4 +232,21 @@ public class FriendListPlugin extends Plugin
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setHideNotifications(String friend, boolean hide)
|
||||
{
|
||||
if (hide)
|
||||
{
|
||||
configManager.setConfiguration(FriendListConfig.GROUP, "hidenotification_" + friend, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
configManager.unsetConfiguration(FriendListConfig.GROUP, "hidenotification_" + friend);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isHideNotification(String friend)
|
||||
{
|
||||
return configManager.getConfiguration(FriendListConfig.GROUP, "hidenotification_" + friend, Boolean.class) == Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,9 +31,11 @@ import com.google.inject.testing.fieldbinder.BoundFieldModule;
|
||||
import net.runelite.api.ChatMessageType;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Friend;
|
||||
import net.runelite.api.FriendContainer;
|
||||
import net.runelite.api.MessageNode;
|
||||
import net.runelite.api.NameableContainer;
|
||||
import net.runelite.api.events.ChatMessage;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -54,6 +56,14 @@ public class FriendListPluginTest
|
||||
@Bind
|
||||
private FriendListConfig config;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private ConfigManager configManager;
|
||||
|
||||
@Mock
|
||||
@Bind
|
||||
private ChatMessageManager chatMessageManager;
|
||||
|
||||
@Inject
|
||||
private FriendListPlugin friendListPlugin;
|
||||
|
||||
@@ -78,7 +88,7 @@ public class FriendListPluginTest
|
||||
Friend friend = mock(Friend.class);
|
||||
when(friend.getWorld()).thenReturn(311);
|
||||
|
||||
NameableContainer<Friend> friendContainer = mock(NameableContainer.class);
|
||||
FriendContainer friendContainer = mock(FriendContainer.class);
|
||||
when(friendContainer.findByName("test\u00a0rsn")).thenReturn(friend);
|
||||
when(client.getFriendContainer()).thenReturn(friendContainer);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user