api: add npc accessor to menuentry

This commit is contained in:
Adam
2022-05-23 17:15:22 -04:00
parent c64fc72f9e
commit 7a1d958ee0
16 changed files with 78 additions and 82 deletions

View File

@@ -118,9 +118,8 @@ public class CrowdsourcingThieving
{
if (event.getMenuOption().equals("Pickpocket") || event.getMenuOption().equals("Knock-Out"))
{
NPC[] cachedNPCs = client.getCachedNPCs();
NPC npc = cachedNPCs[event.getId()];
lastPickpocketTarget = npc.getId();
NPC npc = event.getMenuEntry().getNpc();
lastPickpocketTarget = npc != null ? npc.getId() : -1;
}
}
}

View File

@@ -472,7 +472,8 @@ public class DevToolsPlugin extends Plugin
if (action == MenuAction.EXAMINE_NPC)
{
NPC npc = client.getCachedNPCs()[identifier];
NPC npc = entry.getNpc();
assert npc != null;
info += npc.getId();
}
else

View File

@@ -114,8 +114,7 @@ class InteractHighlightOverlay extends Overlay
case NPC_FIFTH_OPTION:
case EXAMINE_NPC:
{
int id = entry.getIdentifier();
NPC npc = plugin.findNpc(id);
NPC npc = entry.getNpc();
if (npc != null && config.npcShowHover() && (npc != plugin.getInteractedTarget() || !config.npcShowInteract()))
{
Color highlightColor = menuAction == MenuAction.NPC_SECOND_OPTION

View File

@@ -167,9 +167,8 @@ public class InteractHighlightPlugin extends Plugin
case NPC_FOURTH_OPTION:
case NPC_FIFTH_OPTION:
{
int id = menuOptionClicked.getId();
interactedObject = null;
interactedNpc = findNpc(id);
interactedNpc = menuOptionClicked.getMenuEntry().getNpc();
attacked = menuOptionClicked.getMenuAction() == MenuAction.NPC_SECOND_OPTION ||
menuOptionClicked.getMenuAction() == MenuAction.WIDGET_TARGET_ON_NPC && WidgetInfo.TO_GROUP(client.getSelectedWidget().getId()) == WidgetID.SPELLBOOK_GROUP_ID;
clickTick = client.getTickCount();
@@ -242,11 +241,6 @@ public class InteractHighlightPlugin extends Plugin
return null;
}
NPC findNpc(int id)
{
return client.getCachedNPCs()[id];
}
@Nullable
Actor getInteractedTarget()
{

View File

@@ -717,7 +717,8 @@ public class MenuEntrySwapperPlugin extends Plugin
if (type == MenuAction.EXAMINE_NPC)
{
final NPC npc = client.getCachedNPCs()[id];
final NPC npc = entry.getNpc();
assert npc != null;
final NPCComposition composition = npc.getTransformedComposition();
final String[] actions = composition.getActions();
@@ -967,7 +968,8 @@ public class MenuEntrySwapperPlugin extends Plugin
if (NPC_MENU_TYPES.contains(menuAction))
{
final NPC npc = client.getCachedNPCs()[eventId];
final NPC npc = menuEntry.getNpc();
assert npc != null;
final NPCComposition composition = npc.getTransformedComposition();
Integer customOption = getNpcSwapConfig(composition.getId());

View File

@@ -26,7 +26,6 @@
package net.runelite.client.plugins.npchighlight;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Provides;
import java.awt.Color;
import java.time.Instant;
@@ -48,7 +47,6 @@ import net.runelite.api.GraphicID;
import net.runelite.api.GraphicsObject;
import net.runelite.api.KeyCode;
import net.runelite.api.MenuAction;
import static net.runelite.api.MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET;
import net.runelite.api.MenuEntry;
import net.runelite.api.NPC;
import net.runelite.api.coords.WorldPoint;
@@ -89,10 +87,6 @@ public class NpcIndicatorsPlugin extends Plugin
private static final String TAG_ALL = "Tag-All";
private static final String UNTAG_ALL = "Un-tag-All";
private static final Set<MenuAction> NPC_MENU_ACTIONS = ImmutableSet.of(MenuAction.NPC_FIRST_OPTION, MenuAction.NPC_SECOND_OPTION,
MenuAction.NPC_THIRD_OPTION, MenuAction.NPC_FOURTH_OPTION, MenuAction.NPC_FIFTH_OPTION, MenuAction.WIDGET_TARGET_ON_NPC,
MenuAction.ITEM_USE_ON_NPC);
@Inject
private Client client;
@@ -239,46 +233,19 @@ public class NpcIndicatorsPlugin extends Plugin
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
int type = event.getType();
final MenuEntry menuEntry = event.getMenuEntry();
final MenuAction menuAction = menuEntry.getType();
final NPC npc = menuEntry.getNpc();
if (type >= MENU_ACTION_DEPRIORITIZE_OFFSET)
if (npc == null)
{
type -= MENU_ACTION_DEPRIORITIZE_OFFSET;
return;
}
final MenuAction menuAction = MenuAction.of(type);
if (NPC_MENU_ACTIONS.contains(menuAction))
{
NPC npc = client.getCachedNPCs()[event.getIdentifier()];
Color color = null;
if (npc.isDead())
{
color = config.deadNpcMenuColor();
}
if (color == null && highlightedNpcs.containsKey(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs()))
{
color = config.highlightColor();
}
if (color != null)
{
MenuEntry[] menuEntries = client.getMenuEntries();
final MenuEntry menuEntry = menuEntries[menuEntries.length - 1];
final String target = ColorUtil.prependColorTag(Text.removeTags(event.getTarget()), color);
menuEntry.setTarget(target);
}
}
else if (menuAction == MenuAction.EXAMINE_NPC && client.isKeyPressed(KeyCode.KC_SHIFT))
if (menuAction == MenuAction.EXAMINE_NPC && client.isKeyPressed(KeyCode.KC_SHIFT))
{
// Add tag and tag-all options
final int id = event.getIdentifier();
final NPC[] cachedNPCs = client.getCachedNPCs();
final NPC npc = cachedNPCs[id];
if (npc == null || npc.getName() == null)
if (npc.getName() == null)
{
return;
}
@@ -306,6 +273,25 @@ public class NpcIndicatorsPlugin extends Plugin
.setType(MenuAction.RUNELITE)
.onClick(this::tag);
}
else
{
Color color = null;
if (npc.isDead())
{
color = config.deadNpcMenuColor();
}
if (color == null && highlightedNpcs.containsKey(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs()))
{
color = config.highlightColor();
}
if (color != null)
{
final String target = ColorUtil.prependColorTag(Text.removeTags(event.getTarget()), color);
menuEntry.setTarget(target);
}
}
}
private void tag(MenuEntry entry)

View File

@@ -159,8 +159,7 @@ public class OpponentInfoPlugin extends Plugin
return;
}
int npcIndex = menuEntryAdded.getIdentifier();
NPC npc = client.getCachedNPCs()[npcIndex];
NPC npc = menuEntryAdded.getMenuEntry().getNpc();
if (npc == null)
{
return;

View File

@@ -160,7 +160,7 @@ public class RandomEventPlugin extends Plugin
&& event.getType() <= MenuAction.NPC_FIFTH_OPTION.getId()
&& EVENT_OPTIONS.contains(event.getOption()))
{
NPC npc = client.getCachedNPCs()[event.getIdentifier()];
NPC npc = event.getMenuEntry().getNpc();
if (npc != null && EVENT_NPCS.contains(npc.getId()) && npc != currentRandomEvent && config.removeMenuOptions())
{
client.setMenuEntries(Arrays.copyOf(client.getMenuEntries(), client.getMenuEntries().length - 1));

View File

@@ -279,7 +279,8 @@ public class WikiPlugin extends Plugin
case WIDGET_TARGET_ON_NPC:
{
type = "npc";
NPC npc = client.getCachedNPCs()[ev.getId()];
NPC npc = ev.getMenuEntry().getNpc();
assert npc != null;
NPCComposition nc = npc.getTransformedComposition();
id = nc.getId();
name = nc.getName();