From 25a2bf581a64fdc9fe655ff5ce1d6d061fa27aee Mon Sep 17 00:00:00 2001 From: xKylee <48519776+xKylee@users.noreply.github.com> Date: Sun, 26 Jan 2020 23:48:05 +0000 Subject: [PATCH 1/2] mes: merge shiftwalk mes: merge shiftwalk --- .../MenuEntrySwapperConfig.java | 31 +- .../MenuEntrySwapperPlugin.java | 83 +++++- .../shiftwalker/ShiftWalkerConfig.java | 87 ------ .../shiftwalker/ShiftWalkerPlugin.java | 281 ------------------ 4 files changed, 106 insertions(+), 376 deletions(-) delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/shiftwalker/ShiftWalkerConfig.java delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/shiftwalker/ShiftWalkerPlugin.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 index 73030cbf92..eb69cd59c2 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 @@ -1974,7 +1974,6 @@ public interface MenuEntrySwapperConfig extends Config position = 2, section = "hotkeySwapping" ) - default boolean swapNpcContact() { return false; @@ -1987,7 +1986,6 @@ public interface MenuEntrySwapperConfig extends Config position = 3, section = "hotkeySwapping" ) - default boolean bankWieldItem() { return false; @@ -2000,7 +1998,6 @@ public interface MenuEntrySwapperConfig extends Config position = 4, section = "hotkeySwapping" ) - default boolean bankWearItem() { return false; @@ -2013,7 +2010,6 @@ public interface MenuEntrySwapperConfig extends Config position = 5, section = "hotkeySwapping" ) - default boolean bankEatItem() { return false; @@ -2026,7 +2022,6 @@ public interface MenuEntrySwapperConfig extends Config position = 6, section = "hotkeySwapping" ) - default boolean bankDrinkItem() { return false; @@ -2039,7 +2034,6 @@ public interface MenuEntrySwapperConfig extends Config position = 7, section = "hotkeySwapping" ) - default boolean bankEquipItem() { return false; @@ -2052,9 +2046,32 @@ public interface MenuEntrySwapperConfig extends Config position = 8, section = "hotkeySwapping" ) - default boolean bankInvigorateItem() { return false; } + + @ConfigItem( + keyName = "hotKeyWalk", + name = "Hotkey to Walk", + description = "For when you want Walk here as a priority", + position = 9, + section = "hotkeySwapping" + ) + default boolean hotKeyWalk() + { + return false; + } + + @ConfigItem( + keyName = "hotKeyLoot", + name = "Hotkey to Loot", + description = "For when people stand on your loot", + position = 10, + section = "hotkeySwapping" + ) + default boolean hotKeyLoot() + { + 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 0c2cecb932..cdbf93e691 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 @@ -149,6 +149,74 @@ public class MenuEntrySwapperPlugin extends Plugin "mazchna", "vannaka", "chaeldar", "nieve", "steve", "duradel", "krystilia", "konar", "murphy", "cyrisus", "smoggy", "ginea", "watson", "barbarian guard", "random" ); + + private static final AbstractComparableEntry WALK = new AbstractComparableEntry() + { + private final int hash = "WALK".hashCode() * 79 + getPriority(); + + @Override + public int hashCode() + { + return hash; + } + + @Override + public boolean equals(Object entry) + { + return entry.getClass() == this.getClass() && entry.hashCode() == this.hashCode(); + } + + @Override + public int getPriority() + { + return 99; + } + + @Override + public boolean matches(MenuEntry entry) + { + return + entry.getOpcode() == MenuOpcode.WALK.getId() || + entry.getOpcode() == MenuOpcode.WALK.getId() + MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET; + } + }; + + private static final AbstractComparableEntry TAKE = new AbstractComparableEntry() + { + private final int hash = "TAKE".hashCode() * 79 + getPriority(); + + @Override + public int hashCode() + { + return hash; + } + + @Override + public boolean equals(Object entry) + { + return entry.getClass() == this.getClass() && entry.hashCode() == this.hashCode(); + } + + @Override + public int getPriority() + { + return 100; + } + + @Override + public boolean matches(MenuEntry entry) + { + int opcode = entry.getOpcode(); + if (opcode > MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET) + { + opcode -= MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET; + } + + return + opcode >= MenuOpcode.GROUND_ITEM_FIRST_OPTION.getId() && + opcode <= MenuOpcode.GROUND_ITEM_FIFTH_OPTION.getId(); + } + }; private static final Splitter NEWLINE_SPLITTER = Splitter .on("\n") @@ -300,6 +368,8 @@ public class MenuEntrySwapperPlugin extends Plugin private boolean swapWildernessLever; private boolean swapJewelleryBox; private boolean getSwapOffer; + private boolean hotKeyLoot; + private boolean hotKeyWalk; private final HotkeyListener hotkey = new HotkeyListener(() -> this.hotkeyMod) { @Override @@ -1525,7 +1595,14 @@ public class MenuEntrySwapperPlugin extends Plugin { menuManager.addPriorityEntry("climb-up").setPriority(100); } - + if (this.hotKeyLoot) + { + menuManager.addPriorityEntry(TAKE); + } + if (this.hotKeyWalk) + { + menuManager.addPriorityEntry(WALK); + } if (this.swapNpcContact) { for (String npccontact : npcContact) @@ -1551,6 +1628,8 @@ public class MenuEntrySwapperPlugin extends Plugin menuManager.removePriorityEntry(new BankComparableEntry("equip", "", false)); menuManager.removePriorityEntry(new BankComparableEntry("invigorate", "", false)); menuManager.removePriorityEntry("climb-up"); + menuManager.removePriorityEntry(TAKE); + menuManager.removePriorityEntry(WALK); for (String npccontact : npcContact) { @@ -1796,6 +1875,8 @@ public class MenuEntrySwapperPlugin extends Plugin this.bankInvigorateItem = config.bankInvigorateItem(); this.swapNpcContact = config.swapNpcContact(); this.getSwapOffer = config.getSwapOffer(); + this.hotKeyWalk = config.hotKeyWalk(); + this.hotKeyLoot = config.hotKeyLoot(); } private void addBuySellEntries() diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/shiftwalker/ShiftWalkerConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/shiftwalker/ShiftWalkerConfig.java deleted file mode 100644 index 7f5d9baca9..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/shiftwalker/ShiftWalkerConfig.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2018, Plinko60 - * 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.shiftwalker; - -import net.runelite.client.config.Config; -import net.runelite.client.config.ConfigGroup; -import net.runelite.client.config.ConfigItem; - -@ConfigGroup("shiftwalkhere") -public interface ShiftWalkerConfig extends Config -{ - @ConfigItem( - keyName = "shiftWalk", - name = "Shift to Walk", - description = "For when you want Walk here as a priority" - ) - default boolean shiftWalk() - { - return false; - } - - @ConfigItem( - keyName = "shiftLoot", - name = "Shift to Loot", - description = "For when people stand on your loot" - ) - default boolean shiftLoot() - { - return false; - } -/* - - @ConfigItem( - keyName = "shiftWalkEverything", - name = "Walk Under Everything", - description = "Enable this option when you do not want to interact with anything while Shift is pressed. " + - "If Walk Here is an option it will be the action taken." - ) - default boolean shiftWalkEverything() - { - return true; - } - - @ConfigItem( - keyName = "shiftWalkBoxTraps", - name = "Walk Under Box Traps", - description = "Press \"Shift\" to be able to walk under instead of picking up a Box Trap." - ) - default boolean shiftWalkBoxTraps() - { - return true; - } - - @ConfigItem( - keyName = "shiftWalkAttackOption", - name = "Walk Under Attack Options", - description = "Press \"Shift\" to be able to walk instead of attacking. Make sure Left Click Attack is on." - ) - default boolean shiftWalkAttackOption() - { - return true; - } -*/ - -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/shiftwalker/ShiftWalkerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/shiftwalker/ShiftWalkerPlugin.java deleted file mode 100644 index 7e9858769c..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/shiftwalker/ShiftWalkerPlugin.java +++ /dev/null @@ -1,281 +0,0 @@ -/* - * Copyright (c) 2018, Plinko60 - * 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.shiftwalker; - -import com.google.inject.Provides; -import javax.inject.Inject; -import javax.inject.Singleton; -import lombok.AccessLevel; -import lombok.Setter; -import net.runelite.api.Client; -import net.runelite.api.GameState; -import net.runelite.api.MenuEntry; -import net.runelite.api.MenuOpcode; -import net.runelite.api.events.ClientTick; -import net.runelite.api.events.FocusChanged; -import net.runelite.api.events.GameStateChanged; -import net.runelite.client.config.ConfigManager; -import net.runelite.client.config.Keybind; -import net.runelite.client.eventbus.EventBus; -import net.runelite.client.eventbus.Subscribe; -import net.runelite.client.events.ConfigChanged; -import net.runelite.client.input.KeyManager; -import net.runelite.client.menus.AbstractComparableEntry; -import net.runelite.client.menus.MenuManager; -import net.runelite.client.plugins.Plugin; -import net.runelite.client.plugins.PluginDescriptor; -import net.runelite.client.plugins.PluginType; -import net.runelite.client.util.HotkeyListener; - -/** - * Shift Walker Plugin. Credit to MenuEntrySwapperPlugin for code some code structure used here. - */ -@PluginDescriptor( - name = "Shift Walk Under", - description = "Use Shift to toggle the Walk Here menu option. While pressed you will Walk rather than interact with objects.", - tags = {"npcs", "items", "objects"}, - type = PluginType.UTILITY, - enabledByDefault = false -) -@Singleton -public class ShiftWalkerPlugin extends Plugin -{ - - private static final AbstractComparableEntry WALK = new AbstractComparableEntry() - { - private final int hash = "WALK".hashCode() * 79 + getPriority(); - - @Override - public int hashCode() - { - return hash; - } - - @Override - public boolean equals(Object entry) - { - return entry.getClass() == this.getClass() && entry.hashCode() == this.hashCode(); - } - - @Override - public int getPriority() - { - return 99; - } - - @Override - public boolean matches(MenuEntry entry) - { - return - entry.getOpcode() == MenuOpcode.WALK.getId() || - entry.getOpcode() == MenuOpcode.WALK.getId() + MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET; - } - }; - - private static final AbstractComparableEntry TAKE = new AbstractComparableEntry() - { - private final int hash = "TAKE".hashCode() * 79 + getPriority(); - - @Override - public int hashCode() - { - return hash; - } - - @Override - public boolean equals(Object entry) - { - return entry.getClass() == this.getClass() && entry.hashCode() == this.hashCode(); - } - - @Override - public int getPriority() - { - return 100; - } - - @Override - public boolean matches(MenuEntry entry) - { - int opcode = entry.getOpcode(); - if (opcode > MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET) - { - opcode -= MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET; - } - - return - opcode >= MenuOpcode.GROUND_ITEM_FIRST_OPTION.getId() && - opcode <= MenuOpcode.GROUND_ITEM_FIFTH_OPTION.getId(); - } - }; - - private static final String EVENTBUS_THING = "shiftwalker shift"; - private static final String SHIFT_CHECK = "shiftwalker hotkey check"; - @Inject - private Client client; - @Inject - private ShiftWalkerConfig config; - @Inject - private MenuManager menuManager; - @Inject - private KeyManager keyManager; - @Inject - private EventBus eventBus; - @Setter(AccessLevel.PRIVATE) - private boolean hotkeyActive; - private boolean shiftWalk; - private boolean shiftLoot; - - @Provides - ShiftWalkerConfig provideConfig(ConfigManager configManager) - { - return configManager.getConfig(ShiftWalkerConfig.class); - } - - private final HotkeyListener shift = new HotkeyListener(() -> Keybind.SHIFT) - { - @Override - public void hotkeyPressed() - { - startPrioritizing(); - setHotkeyActive(true); - } - - @Override - public void hotkeyReleased() - { - stopPrioritizing(); - setHotkeyActive(false); - } - }; - - @Override - public void startUp() - { - this.shiftWalk = config.shiftWalk(); - this.shiftLoot = config.shiftLoot(); - if (client.getGameState() == GameState.LOGGED_IN) - { - keyManager.registerKeyListener(shift); - } - } - - @Override - public void shutDown() - { - keyManager.unregisterKeyListener(shift); - } - - @Subscribe - private void onGameStateChanged(GameStateChanged event) - { - if (event.getGameState() != GameState.LOGGED_IN) - { - keyManager.unregisterKeyListener(shift); - return; - } - keyManager.registerKeyListener(shift); - } - - @Subscribe - private void onFocusChanged(FocusChanged event) - { - if (!event.isFocused()) - { - stopPrioritizing(); - } - } - - @Subscribe - private void onConfigChanged(ConfigChanged event) - { - if (!event.getGroup().equals("shiftwalkhere")) - { - return; - } - - if ("shiftWalk".equals(event.getKey())) - { - this.shiftWalk = "true".equals(event.getNewValue()); - } - else - { - this.shiftLoot = "true".equals(event.getNewValue()); - } - } - - private void hotkeyCheck(ClientTick event) - { - if (hotkeyActive) - { - int i = 0; - for (boolean bol : client.getPressedKeys()) - { - if (bol) - { - i++; - } - } - if (i == 0) - { - stopPrioritizing(); - setHotkeyActive(false); - eventBus.unregister(SHIFT_CHECK); - } - } - } - - private void startPrioritizing() - { - eventBus.subscribe(ClientTick.class, EVENTBUS_THING, this::addEntries); - eventBus.subscribe(ClientTick.class, SHIFT_CHECK, this::hotkeyCheck); - } - - private void addEntries(ClientTick event) - { - if (this.shiftLoot) - { - menuManager.addPriorityEntry(TAKE); - } - if (this.shiftWalk) - { - menuManager.addPriorityEntry(WALK); - } - - eventBus.unregister(EVENTBUS_THING); - } - - private void stopPrioritizing() - { - eventBus.subscribe(ClientTick.class, EVENTBUS_THING, this::removeEntries); - } - - private void removeEntries(ClientTick event) - { - menuManager.removePriorityEntry(TAKE); - menuManager.removePriorityEntry(WALK); - eventBus.unregister(EVENTBUS_THING); - } -} From 9fc3f9f60bd38055ef718edc8984f8bc168f2218 Mon Sep 17 00:00:00 2001 From: Kyle <48519776+xKylee@users.noreply.github.com> Date: Mon, 27 Jan 2020 01:57:20 +0000 Subject: [PATCH 2/2] Update MenuEntrySwapperPlugin.java --- .../client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cdbf93e691..5a15504b65 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 @@ -368,7 +368,7 @@ public class MenuEntrySwapperPlugin extends Plugin private boolean swapWildernessLever; private boolean swapJewelleryBox; private boolean getSwapOffer; - private boolean hotKeyLoot; + private boolean hotKeyLoot; private boolean hotKeyWalk; private final HotkeyListener hotkey = new HotkeyListener(() -> this.hotkeyMod) {