From 01f134795d2b1834d4eb4d720a83ef5be6c75ed6 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 12 May 2020 11:45:38 -0400 Subject: [PATCH] npc indicators: verify compoistion id of tagged npcs This fixes npc tags for dynamic npcs sometimes erronously tagging the wrong npc if the npc index gets reused. This happens regularly when tagging bloat manually a few times, since the Verzik webs are all npcs and there are many of them, thus a high chance of index collision. --- .../npchighlight/NpcIndicatorsPlugin.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java index 489f06f458..4f91e2400c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java @@ -145,9 +145,9 @@ public class NpcIndicatorsPlugin extends Plugin private List highlights = new ArrayList<>(); /** - * NPC ids marked with the Tag option + * NPC ids marked with the Tag option, index -> composition id */ - private final Set npcTags = new HashSet<>(); + private final Map npcTags = new HashMap<>(); /** * Tagged NPCs that spawned this tick, which need to be verified that @@ -294,7 +294,7 @@ public class NpcIndicatorsPlugin extends Plugin } final int id = click.getId(); - final boolean removed = npcTags.remove(id); + final Integer removedId = npcTags.remove(id); final NPC[] cachedNPCs = client.getCachedNPCs(); final NPC npc = cachedNPCs[id]; @@ -303,7 +303,7 @@ public class NpcIndicatorsPlugin extends Plugin return; } - if (removed) + if (removedId != null) { highlightedNpcs.remove(npc); memorizedNpcs.remove(npc.getIndex()); @@ -311,7 +311,7 @@ public class NpcIndicatorsPlugin extends Plugin else { memorizeNpc(npc); - npcTags.add(id); + npcTags.put(id, npc.getId()); highlightedNpcs.add(npc); } @@ -329,7 +329,8 @@ public class NpcIndicatorsPlugin extends Plugin return; } - if (npcTags.contains(npc.getIndex())) + Integer taggedId = npcTags.get(npc.getIndex()); + if (taggedId != null && taggedId == npc.getId()) { memorizeNpc(npc); highlightedNpcs.add(npc); @@ -475,7 +476,8 @@ public class NpcIndicatorsPlugin extends Plugin continue; } - if (npcTags.contains(npc.getIndex())) + Integer taggedId = npcTags.get(npc.getIndex()); + if (taggedId != null && taggedId == npc.getId()) { highlightedNpcs.add(npc); continue;