From fcbd26bbc9531febaf7171b9c391530e088d17bc Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 11 Oct 2019 20:11:24 +0100 Subject: [PATCH] menu entry swapper: add shift click teleport spell swap Co-authored-by: Adam --- .../MenuEntrySwapperConfig.java | 10 ++++ .../MenuEntrySwapperPlugin.java | 32 +++++++++++ .../MenuEntrySwapperPluginTest.java | 54 +++++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperConfig.java index e687522286..13f780a823 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperConfig.java @@ -311,4 +311,14 @@ public interface MenuEntrySwapperConfig extends Config { return true; } + + @ConfigItem( + keyName = "swapTeleportSpell", + name = "Shift-click teleport spells", + description = "Swap teleport spells that have a second destination on shift" + ) + default boolean swapTeleportSpell() + { + return false; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java index d19b47455f..91fddefb66 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java @@ -604,6 +604,38 @@ public class MenuEntrySwapperPlugin extends Plugin { swap("use", option, target, index); } + + if (shiftModifier && config.swapTeleportSpell()) + { + if (target.equals("varrock teleport")) + { + swapTeleport(target, option, "grand exchange", index); + } + else if (target.equals("camelot teleport")) + { + swapTeleport(target, option, "seers'", index); + } + else if (target.equals("watchtower teleport")) + { + swapTeleport(target, option, "yanille", index); + } + else if (target.equals("teleport to house")) + { + swapTeleport(target, option, "outside", index); + } + } + } + + private void swapTeleport(String target, String option, String optionA, int index) + { + if (option.equals("cast")) + { + swap(optionA, option, target, index); + } + else if (option.equals(optionA)) + { + swap("cast", option, target, index); + } } private static boolean shouldSwapPickpocket(String target) diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java index d34331e209..19b101c931 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java @@ -42,6 +42,7 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import static org.mockito.ArgumentMatchers.any; import org.mockito.Mock; +import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -209,4 +210,57 @@ public class MenuEntrySwapperPluginTest menu("Pay (north)", "Kragen", MenuAction.NPC_THIRD_OPTION), }, argumentCaptor.getValue()); } + + @Test + public void testTeleport() + { + when(config.swapTeleportSpell()).thenReturn(true); + menuEntrySwapperPlugin.setShiftModifier(true); + + // Cast -> Grand Exchange + 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 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); + + // Grand Exchange -> Cast + 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()); + } } \ No newline at end of file