npchighlight: Don't iterate npcs off the client thread

This commit is contained in:
Max Weber
2020-07-10 19:29:59 -06:00
committed by Adam
parent f0a8b67820
commit 4308d433a2
2 changed files with 16 additions and 18 deletions

View File

@@ -187,7 +187,6 @@ public class NpcIndicatorsPlugin extends Plugin
{ {
overlayManager.add(npcSceneOverlay); overlayManager.add(npcSceneOverlay);
overlayManager.add(npcMinimapOverlay); overlayManager.add(npcMinimapOverlay);
highlights = getHighlights();
clientThread.invoke(() -> clientThread.invoke(() ->
{ {
skipNextSpawnCheck = true; skipNextSpawnCheck = true;
@@ -200,13 +199,16 @@ public class NpcIndicatorsPlugin extends Plugin
{ {
overlayManager.remove(npcSceneOverlay); overlayManager.remove(npcSceneOverlay);
overlayManager.remove(npcMinimapOverlay); overlayManager.remove(npcMinimapOverlay);
deadNpcsToDisplay.clear(); clientThread.invoke(() ->
memorizedNpcs.clear(); {
spawnedNpcsThisTick.clear(); deadNpcsToDisplay.clear();
despawnedNpcsThisTick.clear(); memorizedNpcs.clear();
teleportGraphicsObjectSpawnedThisTick.clear(); spawnedNpcsThisTick.clear();
npcTags.clear(); despawnedNpcsThisTick.clear();
highlightedNpcs.clear(); teleportGraphicsObjectSpawnedThisTick.clear();
npcTags.clear();
highlightedNpcs.clear();
});
} }
@Subscribe @Subscribe
@@ -231,8 +233,7 @@ public class NpcIndicatorsPlugin extends Plugin
return; return;
} }
highlights = getHighlights(); clientThread.invoke(this::rebuildAllNpcs);
rebuildAllNpcs();
} }
@Subscribe @Subscribe
@@ -516,8 +517,10 @@ public class NpcIndicatorsPlugin extends Plugin
return Text.fromCSV(configNpcs); return Text.fromCSV(configNpcs);
} }
private void rebuildAllNpcs() @VisibleForTesting
void rebuildAllNpcs()
{ {
highlights = getHighlights();
highlightedNpcs.clear(); highlightedNpcs.clear();
if (client.getGameState() != GameState.LOGGED_IN && if (client.getGameState() != GameState.LOGGED_IN &&

View File

@@ -38,7 +38,6 @@ import net.runelite.api.MenuEntry;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.NpcSpawned; import net.runelite.api.events.NpcSpawned;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import org.junit.Before; import org.junit.Before;
@@ -97,9 +96,7 @@ public class NpcIndicatorsPluginTest
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin"); when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("goblin");
when(npcIndicatorsConfig.deadNpcMenuColor()).thenReturn(Color.RED); when(npcIndicatorsConfig.deadNpcMenuColor()).thenReturn(Color.RED);
ConfigChanged configChanged = new ConfigChanged(); npcIndicatorsPlugin.rebuildAllNpcs();
configChanged.setGroup("npcindicators");
npcIndicatorsPlugin.onConfigChanged(configChanged);
NPC npc = mock(NPC.class); NPC npc = mock(NPC.class);
when(npc.getName()).thenReturn("Goblin"); when(npc.getName()).thenReturn("Goblin");
@@ -124,9 +121,7 @@ public class NpcIndicatorsPluginTest
when(npcIndicatorsConfig.highlightMenuNames()).thenReturn(true); when(npcIndicatorsConfig.highlightMenuNames()).thenReturn(true);
when(npcIndicatorsConfig.getHighlightColor()).thenReturn(Color.BLUE); when(npcIndicatorsConfig.getHighlightColor()).thenReturn(Color.BLUE);
ConfigChanged configChanged = new ConfigChanged(); npcIndicatorsPlugin.rebuildAllNpcs();
configChanged.setGroup("npcindicators");
npcIndicatorsPlugin.onConfigChanged(configChanged);
NPC npc = mock(NPC.class); NPC npc = mock(NPC.class);
when(npc.getName()).thenReturn("Goblin"); when(npc.getName()).thenReturn("Goblin");