npc mixin: transform npc in getName/getCombatLevel/getId

This commit is contained in:
Adam
2018-04-23 19:38:09 -04:00
parent 0edfbb59b6
commit 3caf182b0b
4 changed files with 19 additions and 42 deletions

View File

@@ -34,7 +34,6 @@ import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.NPCComposition;
import net.runelite.api.Point; import net.runelite.api.Point;
import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayLayer;
@@ -68,13 +67,8 @@ public class NpcClickboxOverlay extends Overlay
for (NPC npc : plugin.getTaggedNpcs()) for (NPC npc : plugin.getTaggedNpcs())
{ {
NPCComposition composition = plugin.getComposition(npc); String npcName = npc.getName();
renderNpcOverlay(graphics, npc, npcName, config.getTagColor());
if (composition == null || composition.getName() == null)
continue;
String name = composition.getName().replace('\u00A0', ' ');
renderNpcOverlay(graphics, npc, name, config.getTagColor());
} }
return null; return null;

View File

@@ -41,7 +41,6 @@ import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.NPC; import net.runelite.api.NPC;
import net.runelite.api.NPCComposition;
import net.runelite.api.events.FocusChanged; import net.runelite.api.events.FocusChanged;
import net.runelite.api.events.GameTick; import net.runelite.api.events.GameTick;
import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.MenuOptionClicked;
@@ -149,12 +148,8 @@ public class NpcIndicatorsPlugin extends Plugin
} }
for (NPC npc : client.getNpcs()) for (NPC npc : client.getNpcs())
{ {
if (npcTags.contains(npc.getIndex())) if (npcTags.contains(npc.getIndex()) && npc.getName() != null)
{ {
NPCComposition composition = getComposition(npc);
if (composition == null || composition.getName() == null)
continue;
taggedNpcs.add(npc); taggedNpcs.add(npc);
} }
} }
@@ -177,17 +172,13 @@ public class NpcIndicatorsPlugin extends Plugin
for (NPC npc : client.getNpcs()) for (NPC npc : client.getNpcs())
{ {
NPCComposition composition = getComposition(npc); String npcName = npc.getName();
if (npc == null || composition == null || composition.getName() == null)
continue;
for (String highlight : highlightedNpcs) for (String highlight : highlightedNpcs)
{ {
String name = composition.getName().replace('\u00A0', ' '); if (WildcardMatcher.matches(highlight, npcName))
if (WildcardMatcher.matches(highlight, name))
{ {
npcMap.put(npc, name); npcMap.put(npc, npcName);
} }
} }
} }
@@ -195,26 +186,6 @@ public class NpcIndicatorsPlugin extends Plugin
return npcMap; return npcMap;
} }
/**
* Get npc composition, account for imposters
*
* @param npc
* @return
*/
protected NPCComposition getComposition(NPC npc)
{
if (npc == null)
return null;
NPCComposition composition = npc.getComposition();
if (composition != null && composition.getConfigs() != null)
{
composition = composition.transform();
}
return composition;
}
void updateNpcMenuOptions(boolean pressed) void updateNpcMenuOptions(boolean pressed)
{ {
if (!config.isTagEnabled()) if (!config.isTagEnabled())

View File

@@ -438,7 +438,7 @@ public class SlayerPlugin extends Plugin
if (composition == null || composition.getName() == null) if (composition == null || composition.getName() == null)
continue; continue;
String name = composition.getName().replace('\u00A0', ' '); String name = npc.getName();
for (String highlight : highlightedNpcs) for (String highlight : highlightedNpcs)
{ {
if (name.toLowerCase().contains(highlight.toLowerCase()) if (name.toLowerCase().contains(highlight.toLowerCase())

View File

@@ -48,6 +48,10 @@ public abstract class RSNPCMixin implements RSNPC
public int getId() public int getId()
{ {
RSNPCComposition composition = getComposition(); RSNPCComposition composition = getComposition();
if (composition != null && composition.getConfigs() != null)
{
composition = composition.transform();
}
return composition == null ? -1 : composition.getId(); return composition == null ? -1 : composition.getId();
} }
@@ -56,6 +60,10 @@ public abstract class RSNPCMixin implements RSNPC
public String getName() public String getName()
{ {
RSNPCComposition composition = getComposition(); RSNPCComposition composition = getComposition();
if (composition != null && composition.getConfigs() != null)
{
composition = composition.transform();
}
return composition == null ? null : composition.getName().replace('\u00A0', ' '); return composition == null ? null : composition.getName().replace('\u00A0', ' ');
} }
@@ -64,6 +72,10 @@ public abstract class RSNPCMixin implements RSNPC
public int getCombatLevel() public int getCombatLevel()
{ {
RSNPCComposition composition = getComposition(); RSNPCComposition composition = getComposition();
if (composition != null && composition.getConfigs() != null)
{
composition = composition.transform();
}
return composition == null ? -1 : composition.getCombatLevel(); return composition == null ? -1 : composition.getCombatLevel();
} }