chat history: fix pm cycling deque max size

This commit is contained in:
TheStonedTurtle
2019-04-25 13:08:58 -07:00
committed by Adam
parent a38643f8e4
commit 678d868c03

View File

@@ -62,6 +62,7 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener
private static final String CLEAR_HISTORY = "Clear history"; private static final String CLEAR_HISTORY = "Clear history";
private static final String CLEAR_PRIVATE = "<col=ffff00>Private:"; private static final String CLEAR_PRIVATE = "<col=ffff00>Private:";
private static final int CYCLE_HOTKEY = KeyEvent.VK_TAB; private static final int CYCLE_HOTKEY = KeyEvent.VK_TAB;
private static final int FRIENDS_MAX_SIZE = 5;
private Queue<QueuedMessage> messageQueue; private Queue<QueuedMessage> messageQueue;
private Deque<String> friends; private Deque<String> friends;
@@ -91,7 +92,7 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener
protected void startUp() protected void startUp()
{ {
messageQueue = EvictingQueue.create(100); messageQueue = EvictingQueue.create(100);
friends = new ArrayDeque<>(5); friends = new ArrayDeque<>(FRIENDS_MAX_SIZE + 1);
keyManager.registerKeyListener(this); keyManager.registerKeyListener(this);
} }
@@ -134,7 +135,14 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener
case MODPRIVATECHAT: case MODPRIVATECHAT:
final String name = Text.removeTags(chatMessage.getName()); final String name = Text.removeTags(chatMessage.getName());
// Remove to ensure uniqueness & its place in history // Remove to ensure uniqueness & its place in history
friends.remove(name); if (!friends.remove(name))
{
// If the friend didn't previously exist ensure deque capacity doesn't increase by adding them
if (friends.size() >= FRIENDS_MAX_SIZE)
{
friends.remove();
}
}
friends.add(name); friends.add(name);
// intentional fall-through // intentional fall-through
case PUBLICCHAT: case PUBLICCHAT: