npchighlight: Apply correct highlights to changed NPCs
This commit is contained in:
@@ -57,6 +57,7 @@ import net.runelite.api.events.GameTick;
|
|||||||
import net.runelite.api.events.GraphicsObjectCreated;
|
import net.runelite.api.events.GraphicsObjectCreated;
|
||||||
import net.runelite.api.events.MenuEntryAdded;
|
import net.runelite.api.events.MenuEntryAdded;
|
||||||
import net.runelite.api.events.MenuOptionClicked;
|
import net.runelite.api.events.MenuOptionClicked;
|
||||||
|
import net.runelite.api.events.NpcChanged;
|
||||||
import net.runelite.api.events.NpcDespawned;
|
import net.runelite.api.events.NpcDespawned;
|
||||||
import net.runelite.api.events.NpcSpawned;
|
import net.runelite.api.events.NpcSpawned;
|
||||||
import net.runelite.client.callback.ClientThread;
|
import net.runelite.client.callback.ClientThread;
|
||||||
@@ -409,6 +410,26 @@ public class NpcIndicatorsPlugin extends Plugin
|
|||||||
highlightedNpcs.remove(npc);
|
highlightedNpcs.remove(npc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onNpcChanged(NpcChanged event)
|
||||||
|
{
|
||||||
|
final NPC npc = event.getNpc();
|
||||||
|
final String npcName = npc.getName();
|
||||||
|
|
||||||
|
highlightedNpcs.remove(npc);
|
||||||
|
|
||||||
|
if (npcName == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (npcTags.contains(npc.getIndex())
|
||||||
|
|| highlightMatchesNPCName(npcName))
|
||||||
|
{
|
||||||
|
highlightedNpcs.add(npc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGraphicsObjectCreated(GraphicsObjectCreated event)
|
public void onGraphicsObjectCreated(GraphicsObjectCreated event)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,9 +37,12 @@ import net.runelite.api.MenuAction;
|
|||||||
import net.runelite.api.MenuEntry;
|
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.NpcChanged;
|
||||||
import net.runelite.api.events.NpcSpawned;
|
import net.runelite.api.events.NpcSpawned;
|
||||||
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 static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -137,4 +140,42 @@ public class NpcIndicatorsPluginTest
|
|||||||
target.setTarget("<col=0000ff>Goblin"); // blue
|
target.setTarget("<col=0000ff>Goblin"); // blue
|
||||||
verify(client).setMenuEntries(new MenuEntry[]{target});
|
verify(client).setMenuEntries(new MenuEntry[]{target});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void taggedNpcChanges()
|
||||||
|
{
|
||||||
|
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("Joseph");
|
||||||
|
|
||||||
|
npcIndicatorsPlugin.rebuildAllNpcs();
|
||||||
|
|
||||||
|
NPC npc = mock(NPC.class);
|
||||||
|
when(npc.getName()).thenReturn("Joseph");
|
||||||
|
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
|
||||||
|
|
||||||
|
assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
|
||||||
|
|
||||||
|
when(npc.getName()).thenReturn("Werewolf");
|
||||||
|
npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null));
|
||||||
|
|
||||||
|
assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void npcChangesToTagged()
|
||||||
|
{
|
||||||
|
when(npcIndicatorsConfig.getNpcToHighlight()).thenReturn("Werewolf");
|
||||||
|
|
||||||
|
npcIndicatorsPlugin.rebuildAllNpcs();
|
||||||
|
|
||||||
|
NPC npc = mock(NPC.class);
|
||||||
|
when(npc.getName()).thenReturn("Joseph");
|
||||||
|
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
|
||||||
|
|
||||||
|
assertFalse(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
|
||||||
|
|
||||||
|
when(npc.getName()).thenReturn("Werewolf");
|
||||||
|
npcIndicatorsPlugin.onNpcChanged(new NpcChanged(npc, null));
|
||||||
|
|
||||||
|
assertTrue(npcIndicatorsPlugin.getHighlightedNpcs().contains(npc));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user