api: add player accessor to menuentry

This commit is contained in:
Adam
2022-05-23 17:42:14 -04:00
parent 7a1d958ee0
commit 5367d225bf
6 changed files with 36 additions and 9 deletions

View File

@@ -129,4 +129,18 @@ public interface MenuEntry
*/ */
@Nullable @Nullable
NPC getNpc(); NPC getNpc();
/**
* Get the {@link Player} this menu entry is targeting, if any.
* @return
*/
@Nullable
Player getPlayer();
/**
* Get the {@link Actor} this menu entry is targeting, if any.
* @return
*/
@Nullable
Actor getActor();
} }

View File

@@ -185,9 +185,7 @@ public class HiscorePlugin extends Plugin
{ {
if (event.getMenuAction() == MenuAction.RUNELITE_PLAYER && event.getMenuOption().equals(LOOKUP)) if (event.getMenuAction() == MenuAction.RUNELITE_PLAYER && event.getMenuOption().equals(LOOKUP))
{ {
// The player id is included in the event, so we can use that to get the player name, Player player = event.getMenuEntry().getPlayer();
// which avoids having to parse out the combat level and any icons preceding the name.
Player player = client.getCachedPlayers()[event.getId()];
if (player == null) if (player == null)
{ {
return; return;

View File

@@ -713,7 +713,6 @@ public class MenuEntrySwapperPlugin extends Plugin
{ {
final MenuEntry entry = entries[idx]; final MenuEntry entry = entries[idx];
final MenuAction type = entry.getType(); final MenuAction type = entry.getType();
final int id = entry.getIdentifier();
if (type == MenuAction.EXAMINE_NPC) if (type == MenuAction.EXAMINE_NPC)
{ {

View File

@@ -28,9 +28,11 @@ import java.util.function.Consumer;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Setter; import lombok.Setter;
import net.runelite.api.Actor;
import net.runelite.api.MenuAction; 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.Player;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
@EqualsAndHashCode @EqualsAndHashCode
@@ -50,7 +52,7 @@ public class TestMenuEntry implements MenuEntry
@Setter @Setter
private Widget widget; private Widget widget;
@Setter @Setter
private NPC npc; private Actor actor;
@Override @Override
public String getOption() public String getOption()
@@ -205,6 +207,20 @@ public class TestMenuEntry implements MenuEntry
@Override @Override
public NPC getNpc() public NPC getNpc()
{ {
return npc; return actor instanceof NPC ? (NPC) actor : null;
}
@Nullable
@Override
public Player getPlayer()
{
return actor instanceof Player ? (Player) actor : null;
}
@Nullable
@Override
public Actor getActor()
{
return actor;
} }
} }

View File

@@ -129,7 +129,7 @@ public class MenuEntrySwapperPluginTest
menuEntry.setTarget(target); menuEntry.setTarget(target);
menuEntry.setType(menuAction); menuEntry.setType(menuAction);
menuEntry.setIdentifier(identifier); menuEntry.setIdentifier(identifier);
menuEntry.setNpc(npc); menuEntry.setActor(npc);
return menuEntry; return menuEntry;
} }

View File

@@ -109,7 +109,7 @@ public class NpcIndicatorsPluginTest
TestMenuEntry entry = new TestMenuEntry(); TestMenuEntry entry = new TestMenuEntry();
entry.setTarget("Goblin"); entry.setTarget("Goblin");
entry.setIdentifier(MenuAction.NPC_FIRST_OPTION.getId()); entry.setIdentifier(MenuAction.NPC_FIRST_OPTION.getId());
entry.setNpc(npc); entry.setActor(npc);
MenuEntryAdded menuEntryAdded = new MenuEntryAdded(entry); MenuEntryAdded menuEntryAdded = new MenuEntryAdded(entry);
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded); npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);
@@ -133,7 +133,7 @@ public class NpcIndicatorsPluginTest
TestMenuEntry entry = new TestMenuEntry(); TestMenuEntry entry = new TestMenuEntry();
entry.setTarget("Goblin"); entry.setTarget("Goblin");
entry.setIdentifier(MenuAction.NPC_FIRST_OPTION.getId()); entry.setIdentifier(MenuAction.NPC_FIRST_OPTION.getId());
entry.setNpc(npc); entry.setActor(npc);
MenuEntryAdded menuEntryAdded = new MenuEntryAdded(entry); MenuEntryAdded menuEntryAdded = new MenuEntryAdded(entry);
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded); npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);