chathistory: small cleanups of clear history

This commit is contained in:
Adam
2020-05-24 17:12:23 -04:00
parent 8d62ba9416
commit 8e06e398ee
2 changed files with 12 additions and 12 deletions

View File

@@ -268,10 +268,9 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener
@Subscribe @Subscribe
public void onMenuEntryAdded(MenuEntryAdded entry) public void onMenuEntryAdded(MenuEntryAdded entry)
{ {
final String option = Text.removeTags(entry.getOption());
final ChatboxTab tab = ChatboxTab.of(entry.getActionParam1()); final ChatboxTab tab = ChatboxTab.of(entry.getActionParam1());
if (!config.clearHistory() || tab == null || !option.equals(tab.getAfter())) if (tab == null || !config.clearHistory() || !Text.removeTags(entry.getOption()).equals(tab.getAfter()))
{ {
return; return;
} }
@@ -310,7 +309,7 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener
friends.clear(); friends.clear();
} }
messageQueue.removeIf(e -> tab.getMessageTypes().contains(e.getType())); messageQueue.removeIf(e -> ArrayUtils.contains(tab.getMessageTypes(), e.getType()));
} }
private void clearChatboxHistory(ChatboxTab tab) private void clearChatboxHistory(ChatboxTab tab)
@@ -343,8 +342,9 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener
if (removed) if (removed)
{ {
clientThread.invoke(() -> client.runScript(ScriptID.BUILD_CHATBOX)); clientThread.invoke(() -> client.runScript(ScriptID.BUILD_CHATBOX));
clearMessageQueue(tab);
} }
clearMessageQueue(tab);
} }
/** /**

View File

@@ -24,9 +24,7 @@
*/ */
package net.runelite.client.plugins.chathistory; package net.runelite.client.plugins.chathistory;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import lombok.Getter; import lombok.Getter;
@@ -63,28 +61,30 @@ enum ChatboxTab
ChatMessageType.TRADE_SENT, ChatMessageType.TRADEREQ, ChatMessageType.TRADE, ChatMessageType.CHALREQ_TRADE), ChatMessageType.TRADE_SENT, ChatMessageType.TRADEREQ, ChatMessageType.TRADE, ChatMessageType.CHALREQ_TRADE),
; ;
private static final Map<Integer, ChatboxTab> TAB_MESSAGE_TYPES = new HashMap<>(); private static final Map<Integer, ChatboxTab> TAB_MESSAGE_TYPES;
private final String name;
@Nullable @Nullable
private final String after; private final String after;
private final String name;
private final int widgetId; private final int widgetId;
private final List<ChatMessageType> messageTypes; private final ChatMessageType[] messageTypes;
ChatboxTab(String name, String after, WidgetInfo widgetId, ChatMessageType... messageTypes) ChatboxTab(String name, String after, WidgetInfo widgetId, ChatMessageType... messageTypes)
{ {
this.name = name; this.name = name;
this.after = after; this.after = after;
this.widgetId = widgetId.getId(); this.widgetId = widgetId.getId();
this.messageTypes = ImmutableList.copyOf(messageTypes); this.messageTypes = messageTypes;
} }
static static
{ {
ImmutableMap.Builder<Integer, ChatboxTab> builder = ImmutableMap.builder();
for (ChatboxTab t : values()) for (ChatboxTab t : values())
{ {
TAB_MESSAGE_TYPES.put(t.widgetId, t); builder.put(t.widgetId, t);
} }
TAB_MESSAGE_TYPES = builder.build();
} }
static ChatboxTab of(int widgetId) static ChatboxTab of(int widgetId)