MenuEntrySwapperPlugin extends Plugin { @Subscribe public void onClientTick(ClientTick clientTick) { if (client.getGameState() != GameState.LOGGED_IN || client.isMenuOpen()) { return; } MenuEntry[] menuEntries = client.getMenuEntries(); int idx = 0; optionIndexes.clear(); for (MenuEntry entry : menuEntries) { String option = Text.removeTags(entry.getOption()).toLowerCase(); optionIndexes.put(option, idx++); } idx = 0; for (MenuEntry entry : menuEntries) { swapMenuEntry(idx++, entry); } }  @Override void startUp(); @Override void shutDown(); @Subscribe void onConfigChanged(ConfigChanged event); @Subscribe void onWidgetMenuOptionClicked(WidgetMenuOptionClicked event); @Subscribe void onMenuOpened(MenuOpened event); @Subscribe void onMenuEntryAdded(MenuEntryAdded menuEntryAdded); @Subscribe void onMenuOptionClicked(MenuOptionClicked event); @Subscribe void onClientTick(ClientTick clientTick); @Subscribe void onPostItemComposition(PostItemComposition event);  }
@Test public void testSlayerMaster() { lenient().when(config.swapTrade()).thenReturn(true); when(config.swapAssignment()).thenReturn(true); entries = new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Rewards", "Duradel", MenuAction.NPC_FIFTH_OPTION), menu("Trade", "Duradel", MenuAction.NPC_FOURTH_OPTION), menu("Assignment", "Duradel", MenuAction.NPC_THIRD_OPTION), menu("Talk-to", "Duradel", MenuAction.NPC_FIRST_OPTION), }; menuEntrySwapperPlugin.onClientTick(new ClientTick()); ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class); verify(client).setMenuEntries(argumentCaptor.capture()); assertArrayEquals(new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Rewards", "Duradel", MenuAction.NPC_FIFTH_OPTION), menu("Trade", "Duradel", MenuAction.NPC_FOURTH_OPTION), menu("Talk-to", "Duradel", MenuAction.NPC_FIRST_OPTION), menu("Assignment", "Duradel", MenuAction.NPC_THIRD_OPTION), }, argumentCaptor.getValue()); }
@Test public void testBankers() { when(config.swapBank()).thenReturn(true); entries = new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Examine", "Gnome banker", MenuAction.EXAMINE_NPC), menu("Examine", "Gnome banker", MenuAction.EXAMINE_NPC), menu("Walk here", "", MenuAction.WALK), menu("Collect", "Gnome banker", MenuAction.NPC_FOURTH_OPTION), menu("Bank", "Gnome banker", MenuAction.NPC_THIRD_OPTION), menu("Talk-to", "Gnome banker", MenuAction.NPC_FIRST_OPTION), menu("Collect", "Gnome banker", MenuAction.NPC_FOURTH_OPTION), menu("Bank", "Gnome banker", MenuAction.NPC_THIRD_OPTION), menu("Talk-to", "Gnome banker", MenuAction.NPC_FIRST_OPTION), }; menuEntrySwapperPlugin.onClientTick(new ClientTick()); ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class); verify(client, times(2)).setMenuEntries(argumentCaptor.capture()); assertArrayEquals(new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Examine", "Gnome banker", MenuAction.EXAMINE_NPC), menu("Examine", "Gnome banker", MenuAction.EXAMINE_NPC), menu("Walk here", "", MenuAction.WALK), menu("Collect", "Gnome banker", MenuAction.NPC_FOURTH_OPTION), menu("Talk-to", "Gnome banker", MenuAction.NPC_FIRST_OPTION), menu("Bank", "Gnome banker", MenuAction.NPC_THIRD_OPTION), menu("Collect", "Gnome banker", MenuAction.NPC_FOURTH_OPTION), menu("Talk-to", "Gnome banker", MenuAction.NPC_FIRST_OPTION), menu("Bank", "Gnome banker", MenuAction.NPC_THIRD_OPTION), }, argumentCaptor.getValue()); }
@Test public void testContains() { when(config.swapPay()).thenReturn(true); entries = new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Examine", "Kragen", MenuAction.EXAMINE_NPC), menu("Walk here", "", MenuAction.WALK), menu("Pay (south)", "Kragen", MenuAction.NPC_FOURTH_OPTION), menu("Pay (north)", "Kragen", MenuAction.NPC_THIRD_OPTION), menu("Talk-to", "Kragen", MenuAction.NPC_FIRST_OPTION), }; menuEntrySwapperPlugin.onClientTick(new ClientTick()); ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class); verify(client).setMenuEntries(argumentCaptor.capture()); assertArrayEquals(new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Examine", "Kragen", MenuAction.EXAMINE_NPC), menu("Walk here", "", MenuAction.WALK), menu("Pay (south)", "Kragen", MenuAction.NPC_FOURTH_OPTION), menu("Talk-to", "Kragen", MenuAction.NPC_FIRST_OPTION), menu("Pay (north)", "Kragen", MenuAction.NPC_THIRD_OPTION), }, argumentCaptor.getValue()); }
@Test public void testTeleport() { when(config.swapTeleportSpell()).thenReturn(true); when(client.isKeyPressed(KeyCode.KC_SHIFT)).thenReturn(true); entries = new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Configure", "Varrock Teleport", MenuAction.WIDGET_THIRD_OPTION), menu("Grand Exchange", "Varrock Teleport", MenuAction.WIDGET_SECOND_OPTION), menu("Cast", "Varrock Teleport", MenuAction.WIDGET_FIRST_OPTION), }; menuEntrySwapperPlugin.onClientTick(new ClientTick()); ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class); verify(client).setMenuEntries(argumentCaptor.capture()); assertArrayEquals(new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Configure", "Varrock Teleport", MenuAction.WIDGET_THIRD_OPTION), menu("Cast", "Varrock Teleport", MenuAction.WIDGET_FIRST_OPTION), menu("Grand Exchange", "Varrock Teleport", MenuAction.WIDGET_SECOND_OPTION), }, argumentCaptor.getValue()); clearInvocations(client); entries = new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Configure", "Varrock Teleport", MenuAction.WIDGET_THIRD_OPTION), menu("Cast", "Varrock Teleport", MenuAction.WIDGET_SECOND_OPTION), menu("Grand Exchange", "Varrock Teleport", MenuAction.WIDGET_FIRST_OPTION), }; menuEntrySwapperPlugin.onClientTick(new ClientTick()); argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class); verify(client).setMenuEntries(argumentCaptor.capture()); assertArrayEquals(new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Configure", "Varrock Teleport", MenuAction.WIDGET_THIRD_OPTION), menu("Grand Exchange", "Varrock Teleport", MenuAction.WIDGET_FIRST_OPTION), menu("Cast", "Varrock Teleport", MenuAction.WIDGET_SECOND_OPTION), }, argumentCaptor.getValue()); }
@Test public void testTobDoor() { when(config.swapQuick()).thenReturn(true); entries = new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Examine", "Formidable Passage", MenuAction.EXAMINE_OBJECT), menu("Walk here", "", MenuAction.WALK), menu("Quick-Enter", "Formidable Passage", MenuAction.GAME_OBJECT_SECOND_OPTION), menu("Enter", "Formidable Passage", MenuAction.GAME_OBJECT_FIRST_OPTION), }; menuEntrySwapperPlugin.onClientTick(new ClientTick()); ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class); verify(client).setMenuEntries(argumentCaptor.capture()); assertArrayEquals(new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Examine", "Formidable Passage", MenuAction.EXAMINE_OBJECT), menu("Walk here", "", MenuAction.WALK), menu("Enter", "Formidable Passage", MenuAction.GAME_OBJECT_FIRST_OPTION), menu("Quick-Enter", "Formidable Passage", MenuAction.GAME_OBJECT_SECOND_OPTION), }, argumentCaptor.getValue()); }
@Test public void testBirdhouse() { when(config.swapBirdhouseEmpty()).thenReturn(true); entries = new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Examine", "Redwood birdhouse", MenuAction.EXAMINE_OBJECT), menu("Walk here", "", MenuAction.WALK), menu("Empty", "Redwood birdhouse", MenuAction.GAME_OBJECT_THIRD_OPTION), menu("Seeds", "Redwood birdhouse", MenuAction.GAME_OBJECT_SECOND_OPTION), menu("Interact", "Redwood birdhouse", MenuAction.GAME_OBJECT_FIRST_OPTION), }; menuEntrySwapperPlugin.onClientTick(new ClientTick()); ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class); verify(client).setMenuEntries(argumentCaptor.capture()); assertArrayEquals(new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Examine", "Redwood birdhouse", MenuAction.EXAMINE_OBJECT), menu("Walk here", "", MenuAction.WALK), menu("Interact", "Redwood birdhouse", MenuAction.GAME_OBJECT_FIRST_OPTION), menu("Seeds", "Redwood birdhouse", MenuAction.GAME_OBJECT_SECOND_OPTION), menu("Empty", "Redwood birdhouse", MenuAction.GAME_OBJECT_THIRD_OPTION), }, argumentCaptor.getValue()); }
@Test public void testZanarisFairyRing() { when(config.swapFairyRing()).thenReturn(FairyRingMode.ZANARIS); entries = new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Examine", "Fairy ring", MenuAction.EXAMINE_OBJECT), menu("Walk here", "", MenuAction.WALK), menu("Last-destination (AIQ)", "Fairy ring", MenuAction.GAME_OBJECT_SECOND_OPTION), menu("Configure", "Fairy ring", MenuAction.GAME_OBJECT_FIRST_OPTION), }; menuEntrySwapperPlugin.onClientTick(new ClientTick()); ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class); verify(client).setMenuEntries(argumentCaptor.capture()); assertArrayEquals(new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Examine", "Fairy ring", MenuAction.EXAMINE_OBJECT), menu("Walk here", "", MenuAction.WALK), menu("Configure", "Fairy ring", MenuAction.GAME_OBJECT_FIRST_OPTION), menu("Last-destination (AIQ)", "Fairy ring", MenuAction.GAME_OBJECT_SECOND_OPTION), }, argumentCaptor.getValue()); }