From 0ab5db6c2ee4c01530d016c1c56904a38c473cb4 Mon Sep 17 00:00:00 2001 From: XrioBtw <33559295+XrioBtw@users.noreply.github.com> Date: Sun, 18 Feb 2018 20:55:22 +0100 Subject: [PATCH] Add menu entry swapper plugin --- .../MenuEntrySwapperConfig.java | 169 +++++++++++++++++ .../MenuEntrySwapperPlugin.java | 176 ++++++++++++++++++ 2 files changed, 345 insertions(+) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperConfig.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java 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 new file mode 100644 index 0000000000..e44e1d3656 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperConfig.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2018, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.menuentryswapper; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; + +@ConfigGroup( + keyName = "menuentryswapper", + name = "Menu Entry Swapper", + description = "Swap menu entry options" +) +public interface MenuEntrySwapperConfig extends Config +{ + @ConfigItem( + position = 0, + keyName = "swapPickpocket", + name = "Pickpocket", + description = "Swap Talk-to with Pickpocket on NPC
Example: Man, Woman" + ) + default boolean swapPickpocket() + { + return true; + } + + @ConfigItem( + position = 1, + keyName = "swapBanker", + name = "Bank", + description = "Swap Talk-to with Bank on Bank NPC
Example: Banker" + ) + default boolean swapBank() + { + return true; + } + + @ConfigItem( + position = 2, + keyName = "swapExchange", + name = "Exchange", + description = "Swap Talk-to with Exchange on NPC
Example: Grand Exchange Clerk, Tool Leprechaun, Void Knight" + ) + default boolean swapExchange() + { + return true; + } + + @ConfigItem( + position = 3, + keyName = "swapHarpoon", + name = "Harpoon", + description = "Swap Cage, Net with Harpoon on Fishing spot" + ) + default boolean swapHarpoon() + { + return true; + } + + @ConfigItem( + position = 4, + keyName = "swapTrade", + name = "Trade", + description = "Swap Talk-to with Trade on NPC
Example: Shop keeper, Shop assistant" + ) + default boolean swapTrade() + { + return true; + } + + @ConfigItem( + position = 5, + keyName = "swapTravel", + name = "Travel", + description = "Swap Talk-to with Travel, Take-boat, Pay-fare, Charter on NPC
Example: Squire, Monk of Entrana, Customs officer, Trader Crewmember" + ) + default boolean swapTravel() + { + return true; + } + + @ConfigItem( + position = 6, + keyName = "swapPay", + name = "Pay", + description = "Swap Talk-to with Pay on NPC
Example: Elstan, Heskel, Fayeth" + ) + default boolean swapPay() + { + return true; + } + + @ConfigItem( + position = 7, + keyName = "swapHome", + name = "Home", + description = "Swap Enter with Home on Portal" + ) + default boolean swapHome() + { + return true; + } + + @ConfigItem( + position = 8, + keyName = "swapLastDestination", + name = "Last-destination (XXX)", + description = "Swap Zanaris with Last-destination on Fairy ring" + ) + default boolean swapLastDestination() + { + return true; + } + + @ConfigItem( + position = 9, + keyName = "swapBoxTrap", + name = "Reset", + description = "Swap Check with Reset on box trap" + ) + default boolean swapBoxTrap() + { + return true; + } + + @ConfigItem( + position = 10, + keyName = "swapCatacombEntrance", + name = "Catacomb entrance", + description = "Swap Read with Investigate on Catacombs of Kourend entrance" + ) + default boolean swapCatacombEntrance() + { + return true; + } + + @ConfigItem( + position = 11, + keyName = "swapTeleportItem", + name = "Teleport item", + description = "Swap Wear, Wield with Rub, Teleport on teleport item
Example: Amulet of glory, Ardougne cloak, Chronicle" + ) + default boolean swapTeleportItem() + { + return true; + } +} 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 new file mode 100644 index 0000000000..7ebfb658b9 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2018, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.menuentryswapper; + +import com.google.common.eventbus.Subscribe; +import com.google.inject.Provides; +import javax.inject.Inject; +import net.runelite.api.Client; +import net.runelite.api.GameState; +import net.runelite.api.MenuEntry; +import net.runelite.api.events.MenuEntryAdded; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.plugins.Plugin; +import net.runelite.client.plugins.PluginDescriptor; + +@PluginDescriptor( + name = "Menu entry swapper plugin", + enabledByDefault = false +) +public class MenuEntrySwapperPlugin extends Plugin +{ + @Inject + private Client client; + + @Inject + private MenuEntrySwapperConfig config; + + @Provides + MenuEntrySwapperConfig provideConfig(ConfigManager configManager) + { + return configManager.getConfig(MenuEntrySwapperConfig.class); + } + + @Subscribe + public void onMenuEntryAdded(MenuEntryAdded event) + { + if (client.getGameState() != GameState.LOGGED_IN) + { + return; + } + + String option = event.getOption().toLowerCase(); + String target = event.getTarget(); + + if (option.equals("talk-to")) + { + if (config.swapPickpocket()) + { + swap("pickpocket", option, target, true); + } + + if (config.swapBank()) + { + swap("bank", option, target, true); + } + + if (config.swapExchange()) + { + swap("exchange", option, target, true); + } + + if (config.swapTrade()) + { + swap("trade", option, target, true); + } + + if (config.swapTravel()) + { + swap("travel", option, target, true); + swap("pay-fare", option, target, true); + swap("charter", option, target, true); + swap("take-boat", option, target, true); + } + + if (config.swapPay()) + { + swap("pay", option, target, true); + } + } + else if (config.swapHarpoon() && option.equals("cage")) + { + swap("harpoon", option, target, true); + } + else if (config.swapHarpoon() && option.equals("net")) + { + swap("harpoon", option, target, true); + } + else if (config.swapHome() && option.equals("enter")) + { + swap("home", option, target, true); + } + else if (config.swapLastDestination() && option.equals("zanaris")) + { + swap("last-destination (", option, target, false); + } + else if (config.swapBoxTrap() && option.equals("check")) + { + swap("reset", option, target, true); + } + else if (config.swapCatacombEntrance() && option.equals("read")) + { + swap("investigate", option, target, true); + } + else if (config.swapTeleportItem() && option.equals("wear")) + { + swap("rub", option, target, true); + swap("teleport", option, target, true); + } + else if (config.swapTeleportItem() && option.equals("wield")) + { + swap("teleport", option, target, true); + } + } + + private int searchIndex(MenuEntry[] entries, String option, String target, boolean strict) + { + for (int i = entries.length - 1; i >= 0; i--) + { + MenuEntry entry = entries[i]; + if (strict) + { + if (entry.getOption().toLowerCase().equals(option) && entry.getTarget().equals(target)) + { + return i; + } + } + else + { + if (entry.getOption().toLowerCase().contains(option) && entry.getTarget().equals(target)) + { + return i; + } + } + } + return -1; + } + + private void swap(String optionA, String optionB, String target, boolean strict) + { + MenuEntry[] entries = client.getMenuEntries(); + + int idxA = searchIndex(entries, optionA, target, strict); + int idxB = searchIndex(entries, optionB, target, strict); + + if (idxA >= 0 && idxB >= 0) + { + MenuEntry entry = entries[idxA]; + entries[idxA] = entries[idxB]; + entries[idxB] = entry; + + client.setMenuEntries(entries); + } + } +}