api: add npc accessor to menuentry
This commit is contained in:
@@ -33,7 +33,6 @@ import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.MenuAction;
|
||||
import static net.runelite.api.MenuAction.CC_OP;
|
||||
import static net.runelite.api.MenuAction.RUNELITE;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
@@ -99,13 +98,7 @@ public class MenuManagerTest
|
||||
menuManager.addManagedCustomMenu(new WidgetMenuOption(second.getOption(), second.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null);
|
||||
menuManager.addManagedCustomMenu(new WidgetMenuOption(third.getOption(), third.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null);
|
||||
|
||||
menuManager.onMenuEntryAdded(new MenuEntryAdded(
|
||||
CANCEL.getOption(),
|
||||
CANCEL.getTarget(),
|
||||
CC_OP.getId(),
|
||||
CANCEL.getIdentifier(),
|
||||
CANCEL.getParam0(),
|
||||
CANCEL.getParam1()));
|
||||
menuManager.onMenuEntryAdded(new MenuEntryAdded(createMenuEntry("Cancel", "", MenuAction.CC_OP, MINIMAP_WORLDMAP_OPTIONS.getPackedId())));
|
||||
|
||||
verify(client, times(3)).createMenuEntry(anyInt());
|
||||
|
||||
|
||||
@@ -25,12 +25,13 @@
|
||||
package net.runelite.client.menus;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import javax.annotation.Nullable;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Setter;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@EqualsAndHashCode
|
||||
public class TestMenuEntry implements MenuEntry
|
||||
@@ -48,6 +49,8 @@ public class TestMenuEntry implements MenuEntry
|
||||
private int itemId = -1;
|
||||
@Setter
|
||||
private Widget widget;
|
||||
@Setter
|
||||
private NPC npc;
|
||||
|
||||
@Override
|
||||
public String getOption()
|
||||
@@ -197,4 +200,11 @@ public class TestMenuEntry implements MenuEntry
|
||||
{
|
||||
return widget;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public NPC getNpc()
|
||||
{
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ public class MenuEntrySwapperPluginTest
|
||||
@Inject
|
||||
MenuEntrySwapperPlugin menuEntrySwapperPlugin;
|
||||
|
||||
private NPC npc;
|
||||
private MenuEntry[] entries;
|
||||
|
||||
@Before
|
||||
@@ -96,10 +97,9 @@ public class MenuEntrySwapperPluginTest
|
||||
when(client.getGameState()).thenReturn(GameState.LOGGED_IN);
|
||||
when(client.getObjectDefinition(anyInt())).thenReturn(mock(ObjectComposition.class));
|
||||
|
||||
NPC npc = mock(NPC.class);
|
||||
npc = mock(NPC.class);
|
||||
NPCComposition composition = mock(NPCComposition.class);
|
||||
when(npc.getTransformedComposition()).thenReturn(composition);
|
||||
when(client.getCachedNPCs()).thenReturn(new NPC[] { npc });
|
||||
|
||||
when(client.getMenuEntries()).thenAnswer((Answer<MenuEntry[]>) invocationOnMock ->
|
||||
{
|
||||
@@ -117,18 +117,19 @@ public class MenuEntrySwapperPluginTest
|
||||
menuEntrySwapperPlugin.setupSwaps();
|
||||
}
|
||||
|
||||
private static MenuEntry menu(String option, String target, MenuAction menuAction)
|
||||
private MenuEntry menu(String option, String target, MenuAction menuAction)
|
||||
{
|
||||
return menu(option, target, menuAction, 0);
|
||||
}
|
||||
|
||||
private static MenuEntry menu(String option, String target, MenuAction menuAction, int identifier)
|
||||
private MenuEntry menu(String option, String target, MenuAction menuAction, int identifier)
|
||||
{
|
||||
MenuEntry menuEntry = new TestMenuEntry();
|
||||
TestMenuEntry menuEntry = new TestMenuEntry();
|
||||
menuEntry.setOption(option);
|
||||
menuEntry.setTarget(target);
|
||||
menuEntry.setType(menuAction);
|
||||
menuEntry.setIdentifier(identifier);
|
||||
menuEntry.setNpc(npc);
|
||||
return menuEntry;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.api.events.NpcChanged;
|
||||
@@ -107,11 +106,12 @@ public class NpcIndicatorsPluginTest
|
||||
when(npc.isDead()).thenReturn(true);
|
||||
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
|
||||
|
||||
when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0
|
||||
TestMenuEntry entry = new TestMenuEntry();
|
||||
entry.setTarget("Goblin");
|
||||
entry.setIdentifier(MenuAction.NPC_FIRST_OPTION.getId());
|
||||
entry.setNpc(npc);
|
||||
|
||||
MenuEntry entry = new TestMenuEntry();
|
||||
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{entry});
|
||||
MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1);
|
||||
MenuEntryAdded menuEntryAdded = new MenuEntryAdded(entry);
|
||||
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);
|
||||
|
||||
assertEquals("<col=ff0000>Goblin", entry.getTarget()); // red
|
||||
@@ -130,11 +130,12 @@ public class NpcIndicatorsPluginTest
|
||||
when(npc.getName()).thenReturn("Goblin");
|
||||
npcIndicatorsPlugin.onNpcSpawned(new NpcSpawned(npc));
|
||||
|
||||
when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0
|
||||
TestMenuEntry entry = new TestMenuEntry();
|
||||
entry.setTarget("Goblin");
|
||||
entry.setIdentifier(MenuAction.NPC_FIRST_OPTION.getId());
|
||||
entry.setNpc(npc);
|
||||
|
||||
MenuEntry entry = new TestMenuEntry();
|
||||
when(client.getMenuEntries()).thenReturn(new MenuEntry[]{entry});
|
||||
MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1);
|
||||
MenuEntryAdded menuEntryAdded = new MenuEntryAdded(entry);
|
||||
npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded);
|
||||
|
||||
assertEquals("<col=0000ff>Goblin", entry.getTarget()); // blue
|
||||
|
||||
Reference in New Issue
Block a user