diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java index 08a0a3aab7..607861bfd8 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java @@ -29,14 +29,13 @@ package net.runelite.client.plugins.banktags; import com.google.common.collect.Lists; import com.google.common.primitives.Shorts; import com.google.inject.Provides; -import java.awt.event.KeyEvent; import java.awt.event.MouseWheelEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.Set; import java.util.TreeSet; -import java.util.List; import java.util.function.Consumer; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -46,13 +45,12 @@ import net.runelite.api.InventoryID; import net.runelite.api.Item; import net.runelite.api.ItemComposition; import net.runelite.api.ItemContainer; +import net.runelite.api.KeyCode; import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; import net.runelite.api.VarClientInt; import net.runelite.api.VarClientStr; -import net.runelite.client.events.ConfigChanged; import net.runelite.api.events.DraggingWidgetChanged; -import net.runelite.api.events.FocusChanged; import net.runelite.api.events.GameTick; import net.runelite.api.events.GrandExchangeSearched; import net.runelite.api.events.MenuEntryAdded; @@ -66,11 +64,11 @@ import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.callback.ClientThread; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.events.ConfigChanged; import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemVariationMapping; import net.runelite.client.game.SpriteManager; import net.runelite.client.game.chatbox.ChatboxPanelManager; -import net.runelite.client.input.KeyListener; import net.runelite.client.input.KeyManager; import net.runelite.client.input.MouseManager; import net.runelite.client.input.MouseWheelListener; @@ -90,7 +88,7 @@ import net.runelite.client.util.Text; tags = {"searching", "tagging"} ) @PluginDependency(ClueScrollPlugin.class) -public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyListener +public class BankTagsPlugin extends Plugin implements MouseWheelListener { public static final String CONFIG_GROUP = "banktags"; public static final String TAG_SEARCH = "tag:"; @@ -144,8 +142,6 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis @Inject private ConfigManager configManager; - private boolean shiftPressed = false; - @Provides BankTagsConfig getConfig(ConfigManager configManager) { @@ -186,7 +182,6 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis public void startUp() { cleanConfig(); - keyManager.registerKeyListener(this); mouseManager.registerMouseWheelListener(this); clientThread.invokeLater(tabInterface::init); spriteManager.addSpriteOverrides(TabSprites.values()); @@ -248,12 +243,9 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis @Override public void shutDown() { - keyManager.unregisterKeyListener(this); mouseManager.unregisterMouseWheelListener(this); clientThread.invokeLater(tabInterface::destroy); spriteManager.removeSpriteOverrides(TabSprites.values()); - - shiftPressed = false; } @Subscribe @@ -467,6 +459,7 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis @Subscribe public void onDraggingWidgetChanged(DraggingWidgetChanged event) { + final boolean shiftPressed = client.isKeyPressed(KeyCode.KC_SHIFT); tabInterface.handleDrag(event.isDraggingWidget(), shiftPressed); } @@ -479,42 +472,10 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyLis } } - @Subscribe - public void onFocusChanged(FocusChanged event) - { - if (!event.isFocused()) - { - shiftPressed = false; - } - } - @Override public MouseWheelEvent mouseWheelMoved(MouseWheelEvent event) { tabInterface.handleWheel(event); return event; } - - @Override - public void keyTyped(KeyEvent e) - { - } - - @Override - public void keyPressed(KeyEvent e) - { - if (e.getKeyCode() == KeyEvent.VK_SHIFT) - { - shiftPressed = true; - } - } - - @Override - public void keyReleased(KeyEvent e) - { - if (e.getKeyCode() == KeyEvent.VK_SHIFT) - { - shiftPressed = false; - } - } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerInputListener.java b/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerInputListener.java deleted file mode 100644 index a097d47d29..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerInputListener.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2018, TheLonelyDev - * 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.groundmarkers; - -import java.awt.event.KeyEvent; -import javax.inject.Inject; -import net.runelite.client.input.KeyListener; - -public class GroundMarkerInputListener implements KeyListener -{ - private static final int HOTKEY = KeyEvent.VK_SHIFT; - - private final GroundMarkerPlugin plugin; - - @Inject - private GroundMarkerInputListener(GroundMarkerPlugin plugin) - { - this.plugin = plugin; - } - - @Override - public void keyTyped(KeyEvent e) - { - - } - - @Override - public void keyPressed(KeyEvent e) - { - if (e.getKeyCode() == HOTKEY) - { - plugin.setHotKeyPressed(true); - } - } - - @Override - public void keyReleased(KeyEvent e) - { - if (e.getKeyCode() == HOTKEY) - { - plugin.setHotKeyPressed(false); - } - } -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerPlugin.java index af3dae8f87..e0f37dbb4a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerPlugin.java @@ -38,16 +38,15 @@ import java.util.stream.Collectors; import javax.inject.Inject; import lombok.AccessLevel; import lombok.Getter; -import lombok.Setter; import lombok.extern.slf4j.Slf4j; import net.runelite.api.Client; import net.runelite.api.GameState; +import net.runelite.api.KeyCode; import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; import net.runelite.api.Tile; import net.runelite.api.coords.LocalPoint; import net.runelite.api.coords.WorldPoint; -import net.runelite.api.events.FocusChanged; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.MenuOptionClicked; @@ -74,10 +73,6 @@ public class GroundMarkerPlugin extends Plugin private static final Gson GSON = new Gson(); - @Getter(AccessLevel.PACKAGE) - @Setter(AccessLevel.PACKAGE) - private boolean hotKeyPressed; - @Getter(AccessLevel.PACKAGE) private final List points = new ArrayList<>(); @@ -87,9 +82,6 @@ public class GroundMarkerPlugin extends Plugin @Inject private GroundMarkerConfig config; - @Inject - private GroundMarkerInputListener inputListener; - @Inject private ConfigManager configManager; @@ -195,18 +187,10 @@ public class GroundMarkerPlugin extends Plugin loadPoints(); } - @Subscribe - public void onFocusChanged(FocusChanged focusChanged) - { - if (!focusChanged.isFocused()) - { - hotKeyPressed = false; - } - } - @Subscribe public void onMenuEntryAdded(MenuEntryAdded event) { + final boolean hotKeyPressed = client.isKeyPressed(KeyCode.KC_SHIFT); if (hotKeyPressed && event.getOption().equals(WALK_HERE)) { final Tile selectedSceneTile = client.getSelectedSceneTile(); @@ -254,7 +238,6 @@ public class GroundMarkerPlugin extends Plugin { overlayManager.add(overlay); overlayManager.add(minimapOverlay); - keyManager.registerKeyListener(inputListener); loadPoints(); } @@ -263,7 +246,6 @@ public class GroundMarkerPlugin extends Plugin { overlayManager.remove(overlay); overlayManager.remove(minimapOverlay); - keyManager.unregisterKeyListener(inputListener); points.clear(); } 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 23cd79d44e..1ea8ca1383 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 @@ -42,15 +42,14 @@ import java.util.function.Predicate; import java.util.function.Supplier; import javax.inject.Inject; import lombok.Getter; -import lombok.Setter; import net.runelite.api.Client; import net.runelite.api.GameState; import net.runelite.api.ItemComposition; +import net.runelite.api.KeyCode; import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; import net.runelite.api.NPC; import net.runelite.api.events.ClientTick; -import net.runelite.api.events.FocusChanged; import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.MenuOpened; import net.runelite.api.events.MenuOptionClicked; @@ -131,9 +130,6 @@ public class MenuEntrySwapperPlugin extends Plugin @Inject private MenuEntrySwapperConfig config; - @Inject - private ShiftClickInputListener inputListener; - @Inject private ConfigManager configManager; @@ -149,9 +145,6 @@ public class MenuEntrySwapperPlugin extends Plugin @Getter private boolean configuringShiftClick = false; - @Setter - private boolean shiftModifier = false; - private final Multimap swaps = LinkedHashMultimap.create(); private final ArrayListMultimap optionIndexes = ArrayListMultimap.create(); @@ -299,39 +292,39 @@ public class MenuEntrySwapperPlugin extends Plugin swap("pick", "pick-lots", config::swapPick); - swap("view offer", "abort offer", () -> shiftModifier && config.swapGEAbort()); + swap("view offer", "abort offer", () -> shiftModifier() && config.swapGEAbort()); - swap("cast", "npc contact", "honest jimmy", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "bert the sandman", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "advisor ghrim", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "dark mage", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "lanthus", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "turael", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "mazchna", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "vannaka", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "chaeldar", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "nieve", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "steve", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "duradel", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "krystilia", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "konar", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "murphy", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "cyrisus", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "smoggy", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "ginea", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "watson", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "barbarian guard", () -> shiftModifier && config.swapNpcContact()); - swap("cast", "npc contact", "random", () -> shiftModifier && config.swapNpcContact()); + swap("cast", "npc contact", "honest jimmy", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "bert the sandman", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "advisor ghrim", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "dark mage", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "lanthus", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "turael", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "mazchna", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "vannaka", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "chaeldar", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "nieve", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "steve", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "duradel", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "krystilia", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "konar", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "murphy", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "cyrisus", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "smoggy", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "ginea", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "watson", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "barbarian guard", () -> shiftModifier() && config.swapNpcContact()); + swap("cast", "npc contact", "random", () -> shiftModifier() && config.swapNpcContact()); - swap("value", "buy 1", () -> shiftModifier && config.shopBuy() == BuyMode.BUY_1); - swap("value", "buy 5", () -> shiftModifier && config.shopBuy() == BuyMode.BUY_5); - swap("value", "buy 10", () -> shiftModifier && config.shopBuy() == BuyMode.BUY_10); - swap("value", "buy 50", () -> shiftModifier && config.shopBuy() == BuyMode.BUY_50); + swap("value", "buy 1", () -> shiftModifier() && config.shopBuy() == BuyMode.BUY_1); + swap("value", "buy 5", () -> shiftModifier() && config.shopBuy() == BuyMode.BUY_5); + swap("value", "buy 10", () -> shiftModifier() && config.shopBuy() == BuyMode.BUY_10); + swap("value", "buy 50", () -> shiftModifier() && config.shopBuy() == BuyMode.BUY_50); - swap("value", "sell 1", () -> shiftModifier && config.shopSell() == SellMode.SELL_1); - swap("value", "sell 5", () -> shiftModifier && config.shopSell() == SellMode.SELL_5); - swap("value", "sell 10", () -> shiftModifier && config.shopSell() == SellMode.SELL_10); - swap("value", "sell 50", () -> shiftModifier && config.shopSell() == SellMode.SELL_50); + swap("value", "sell 1", () -> shiftModifier() && config.shopSell() == SellMode.SELL_1); + swap("value", "sell 5", () -> shiftModifier() && config.shopSell() == SellMode.SELL_5); + swap("value", "sell 10", () -> shiftModifier() && config.shopSell() == SellMode.SELL_10); + swap("value", "sell 50", () -> shiftModifier() && config.shopSell() == SellMode.SELL_50); swap("wear", "rub", config::swapTeleportItem); swap("wear", "teleport", config::swapTeleportItem); @@ -382,8 +375,8 @@ public class MenuEntrySwapperPlugin extends Plugin private void swapTeleport(String option, String swappedOption) { - swap("cast", option, swappedOption, () -> shiftModifier && config.swapTeleportSpell()); - swap(swappedOption, option, "cast", () -> shiftModifier && config.swapTeleportSpell()); + swap("cast", option, swappedOption, () -> shiftModifier() && config.swapTeleportSpell()); + swap(swappedOption, option, "cast", () -> shiftModifier() && config.swapTeleportSpell()); } @Subscribe @@ -438,7 +431,6 @@ public class MenuEntrySwapperPlugin extends Plugin private void enableCustomization() { - keyManager.registerKeyListener(inputListener); refreshShiftClickCustomizationMenus(); // set shift click action index on the item compositions clientThread.invoke(this::resetItemCompositionCache); @@ -446,7 +438,6 @@ public class MenuEntrySwapperPlugin extends Plugin private void disableCustomization() { - keyManager.unregisterKeyListener(inputListener); removeShiftClickCustomizationMenus(); configuringShiftClick = false; // flush item compositions to reset the shift click action index @@ -536,7 +527,7 @@ public class MenuEntrySwapperPlugin extends Plugin // Swap to shift-click deposit behavior // Deposit- op 1 is the current withdraw amount 1/5/10/x for deposit box interface // Deposit- op 2 is the current withdraw amount 1/5/10/x for bank interface - if (shiftModifier && config.bankDepositShiftClick() != ShiftDepositMode.OFF + if (shiftModifier() && config.bankDepositShiftClick() != ShiftDepositMode.OFF && menuEntryAdded.getType() == MenuAction.CC_OP.getId() && (menuEntryAdded.getIdentifier() == 2 || menuEntryAdded.getIdentifier() == 1) && menuEntryAdded.getOption().startsWith("Deposit-")) { @@ -548,7 +539,7 @@ public class MenuEntrySwapperPlugin extends Plugin // Swap to shift-click withdraw behavior // Deposit- op 1 is the current withdraw amount 1/5/10/x - if (shiftModifier && config.bankWithdrawShiftClick() != ShiftWithdrawMode.OFF + if (shiftModifier() && config.bankWithdrawShiftClick() != ShiftWithdrawMode.OFF && menuEntryAdded.getType() == MenuAction.CC_OP.getId() && menuEntryAdded.getIdentifier() == 1 && menuEntryAdded.getOption().startsWith("Withdraw-")) { @@ -645,7 +636,7 @@ public class MenuEntrySwapperPlugin extends Plugin return; } - if (shiftModifier && (menuAction == MenuAction.ITEM_FIRST_OPTION + if (shiftModifier() && (menuAction == MenuAction.ITEM_FIRST_OPTION || menuAction == MenuAction.ITEM_SECOND_OPTION || menuAction == MenuAction.ITEM_THIRD_OPTION || menuAction == MenuAction.ITEM_FOURTH_OPTION @@ -730,15 +721,6 @@ public class MenuEntrySwapperPlugin extends Plugin } } - @Subscribe - public void onFocusChanged(FocusChanged event) - { - if (!event.isFocused()) - { - shiftModifier = false; - } - } - private boolean swap(String option, String target, int index, boolean strict) { MenuEntry[] menuEntries = client.getMenuEntries(); @@ -853,4 +835,9 @@ public class MenuEntrySwapperPlugin extends Plugin menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE); } } + + private boolean shiftModifier() + { + return client.isKeyPressed(KeyCode.KC_SHIFT); + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/ShiftClickInputListener.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/ShiftClickInputListener.java deleted file mode 100644 index f7dde77e00..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/ShiftClickInputListener.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2018, Kamiel - * 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 java.awt.event.KeyEvent; -import javax.inject.Inject; -import net.runelite.api.Client; -import net.runelite.client.callback.ClientThread; -import net.runelite.client.input.KeyListener; - -public class ShiftClickInputListener implements KeyListener -{ - @Inject - private ClientThread clientThread; - - @Inject - private Client client; - - @Inject - private MenuEntrySwapperPlugin plugin; - - @Override - public void keyTyped(KeyEvent event) - { - - } - - @Override - public void keyPressed(KeyEvent event) - { - if (event.getKeyCode() == KeyEvent.VK_SHIFT) - { - plugin.setShiftModifier(true); - } - } - - @Override - public void keyReleased(KeyEvent event) - { - if (event.getKeyCode() == KeyEvent.VK_SHIFT) - { - plugin.setShiftModifier(false); - } - } -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsInput.java b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsInput.java deleted file mode 100644 index a744208264..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsInput.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2018, Seth - * 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.npchighlight; - -import java.awt.event.KeyEvent; -import javax.inject.Inject; -import net.runelite.client.input.KeyListener; - -public class NpcIndicatorsInput implements KeyListener -{ - private static final int HOTKEY = KeyEvent.VK_SHIFT; - - @Inject - private NpcIndicatorsPlugin plugin; - - @Override - public void keyTyped(KeyEvent e) - { - - } - - @Override - public void keyPressed(KeyEvent e) - { - if (e.getKeyCode() == HOTKEY) - { - plugin.setHotKeyPressed(true); - } - } - - @Override - public void keyReleased(KeyEvent e) - { - if (e.getKeyCode() == HOTKEY) - { - plugin.setHotKeyPressed(false); - } - } -} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java index 77abdd41f3..107bb58cbd 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java @@ -41,18 +41,17 @@ import java.util.Set; import javax.inject.Inject; import lombok.AccessLevel; import lombok.Getter; -import lombok.Setter; import lombok.extern.slf4j.Slf4j; import net.runelite.api.Client; import net.runelite.api.GameState; import net.runelite.api.GraphicID; import net.runelite.api.GraphicsObject; +import net.runelite.api.KeyCode; import net.runelite.api.MenuAction; import static net.runelite.api.MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET; import net.runelite.api.MenuEntry; import net.runelite.api.NPC; import net.runelite.api.coords.WorldPoint; -import net.runelite.api.events.FocusChanged; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameTick; import net.runelite.api.events.GraphicsObjectCreated; @@ -105,18 +104,12 @@ public class NpcIndicatorsPlugin extends Plugin @Inject private NpcMinimapOverlay npcMinimapOverlay; - @Inject - private NpcIndicatorsInput inputListener; - @Inject private KeyManager keyManager; @Inject private ClientThread clientThread; - @Setter(AccessLevel.PACKAGE) - private boolean hotKeyPressed = false; - /** * NPCs to highlight */ @@ -191,7 +184,6 @@ public class NpcIndicatorsPlugin extends Plugin { overlayManager.add(npcSceneOverlay); overlayManager.add(npcMinimapOverlay); - keyManager.registerKeyListener(inputListener); highlights = getHighlights(); clientThread.invoke(() -> { @@ -212,7 +204,6 @@ public class NpcIndicatorsPlugin extends Plugin teleportGraphicsObjectSpawnedThisTick.clear(); npcTags.clear(); highlightedNpcs.clear(); - keyManager.unregisterKeyListener(inputListener); } @Subscribe @@ -241,15 +232,6 @@ public class NpcIndicatorsPlugin extends Plugin rebuildAllNpcs(); } - @Subscribe - public void onFocusChanged(FocusChanged focusChanged) - { - if (!focusChanged.isFocused()) - { - hotKeyPressed = false; - } - } - @Subscribe public void onMenuEntryAdded(MenuEntryAdded event) { @@ -286,7 +268,7 @@ public class NpcIndicatorsPlugin extends Plugin client.setMenuEntries(menuEntries); } } - else if (hotKeyPressed && menuAction == MenuAction.EXAMINE_NPC) + else if (menuAction == MenuAction.EXAMINE_NPC && client.isKeyPressed(KeyCode.KC_SHIFT)) { // Add tag option MenuEntry[] menuEntries = client.getMenuEntries(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java index 8c9e326310..dc028cb0c0 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java @@ -30,7 +30,6 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.google.inject.Provides; import java.awt.Color; -import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -49,6 +48,7 @@ import net.runelite.api.DecorativeObject; import net.runelite.api.GameObject; import net.runelite.api.GameState; import net.runelite.api.GroundObject; +import net.runelite.api.KeyCode; import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; import net.runelite.api.ObjectComposition; @@ -59,7 +59,6 @@ import net.runelite.api.WallObject; import net.runelite.api.coords.WorldPoint; import net.runelite.api.events.DecorativeObjectDespawned; import net.runelite.api.events.DecorativeObjectSpawned; -import net.runelite.api.events.FocusChanged; import net.runelite.api.events.GameObjectDespawned; import net.runelite.api.events.GameObjectSpawned; import net.runelite.api.events.GameStateChanged; @@ -72,7 +71,6 @@ import net.runelite.api.events.WallObjectDespawned; import net.runelite.api.events.WallObjectSpawned; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; -import net.runelite.client.input.KeyListener; import net.runelite.client.input.KeyManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; @@ -85,7 +83,7 @@ import net.runelite.client.ui.overlay.OverlayManager; enabledByDefault = false ) @Slf4j -public class ObjectIndicatorsPlugin extends Plugin implements KeyListener +public class ObjectIndicatorsPlugin extends Plugin { private static final String CONFIG_GROUP = "objectindicators"; private static final String MARK = "Mark object"; @@ -95,7 +93,6 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener @Getter(AccessLevel.PACKAGE) private final List objects = new ArrayList<>(); private final Map> points = new HashMap<>(); - private boolean hotKeyPressed; @Inject private Client client; @@ -125,50 +122,14 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener protected void startUp() { overlayManager.add(overlay); - keyManager.registerKeyListener(this); } @Override protected void shutDown() { overlayManager.remove(overlay); - keyManager.unregisterKeyListener(this); points.clear(); objects.clear(); - hotKeyPressed = false; - } - - @Override - public void keyTyped(KeyEvent e) - { - - } - - @Override - public void keyPressed(KeyEvent e) - { - if (e.getKeyCode() == KeyEvent.VK_SHIFT) - { - hotKeyPressed = true; - } - } - - @Override - public void keyReleased(KeyEvent e) - { - if (e.getKeyCode() == KeyEvent.VK_SHIFT) - { - hotKeyPressed = false; - } - } - - @Subscribe - public void onFocusChanged(final FocusChanged event) - { - if (!event.isFocused()) - { - hotKeyPressed = false; - } } @Subscribe @@ -258,7 +219,7 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener @Subscribe public void onMenuEntryAdded(MenuEntryAdded event) { - if (!hotKeyPressed || event.getType() != MenuAction.EXAMINE_OBJECT.getId()) + if (event.getType() != MenuAction.EXAMINE_OBJECT.getId() || !client.isKeyPressed(KeyCode.KC_SHIFT)) { return; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/party/PartyPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/party/PartyPlugin.java index 1f94f976ee..80b97dd61c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/party/PartyPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/party/PartyPlugin.java @@ -27,7 +27,6 @@ package net.runelite.client.plugins.party; import com.google.inject.Binder; import com.google.inject.Provides; import java.awt.Color; -import java.awt.event.KeyEvent; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collections; @@ -42,6 +41,7 @@ import lombok.Getter; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; import net.runelite.api.GameState; +import net.runelite.api.KeyCode; import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; import net.runelite.api.Skill; @@ -49,7 +49,6 @@ import net.runelite.api.SoundEffectID; import net.runelite.api.Tile; import net.runelite.api.coords.WorldPoint; import net.runelite.api.events.CommandExecuted; -import net.runelite.api.events.FocusChanged; import net.runelite.api.events.GameTick; import net.runelite.api.events.MenuOptionClicked; import net.runelite.client.callback.ClientThread; @@ -61,7 +60,6 @@ import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.events.OverlayMenuClicked; import net.runelite.client.events.PartyChanged; -import net.runelite.client.input.KeyListener; import net.runelite.client.input.KeyManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; @@ -86,7 +84,7 @@ import net.runelite.http.api.ws.messages.party.UserSync; name = "Party", description = "Shows useful information about current party" ) -public class PartyPlugin extends Plugin implements KeyListener +public class PartyPlugin extends Plugin { @Inject private Client client; @@ -135,7 +133,7 @@ public class PartyPlugin extends Plugin implements KeyListener private final List pendingTilePings = Collections.synchronizedList(new ArrayList<>()); private int lastHp, lastPray; - private boolean hotkeyDown, doSync; + private boolean doSync; private boolean sendAlert; @Override @@ -152,7 +150,6 @@ public class PartyPlugin extends Plugin implements KeyListener wsClient.registerMessage(SkillUpdate.class); wsClient.registerMessage(TilePing.class); wsClient.registerMessage(LocationUpdate.class); - keyManager.registerKeyListener(this); doSync = true; // Delay sync so eventbus can process correctly. } @@ -167,8 +164,6 @@ public class PartyPlugin extends Plugin implements KeyListener wsClient.unregisterMessage(SkillUpdate.class); wsClient.unregisterMessage(TilePing.class); wsClient.unregisterMessage(LocationUpdate.class); - keyManager.unregisterKeyListener(this); - hotkeyDown = false; doSync = false; sendAlert = false; } @@ -208,7 +203,7 @@ public class PartyPlugin extends Plugin implements KeyListener @Subscribe public void onMenuOptionClicked(MenuOptionClicked event) { - if (!hotkeyDown || client.isMenuOpen() || party.getMembers().isEmpty() || !config.pings()) + if (!client.isKeyPressed(KeyCode.KC_SHIFT) || client.isMenuOpen() || party.getMembers().isEmpty() || !config.pings()) { return; } @@ -503,39 +498,6 @@ public class PartyPlugin extends Plugin implements KeyListener }); } - @Subscribe - public void onFocusChanged(FocusChanged event) - { - if (!event.isFocused()) - { - hotkeyDown = false; - } - } - - @Override - public void keyTyped(KeyEvent keyEvent) - { - - } - - @Override - public void keyPressed(KeyEvent keyEvent) - { - if (keyEvent.getKeyCode() == KeyEvent.VK_SHIFT) - { - hotkeyDown = true; - } - } - - @Override - public void keyReleased(KeyEvent keyEvent) - { - if (keyEvent.getKeyCode() == KeyEvent.VK_SHIFT) - { - hotkeyDown = false; - } - } - private void sendInstructionMessage() { final String helpMessage = new ChatMessageBuilder() 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 b1f77c708a..fadbf0a28b 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 @@ -30,6 +30,7 @@ import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.BoundFieldModule; import net.runelite.api.Client; import net.runelite.api.GameState; +import net.runelite.api.KeyCode; import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; import net.runelite.api.events.ClientTick; @@ -224,7 +225,7 @@ public class MenuEntrySwapperPluginTest public void testTeleport() { when(config.swapTeleportSpell()).thenReturn(true); - menuEntrySwapperPlugin.setShiftModifier(true); + when(client.isKeyPressed(KeyCode.KC_SHIFT)).thenReturn(true); // Cast -> Grand Exchange entries = new MenuEntry[]{ @@ -307,7 +308,7 @@ public class MenuEntrySwapperPluginTest public void testShiftWithdraw() { when(config.bankDepositShiftClick()).thenReturn(ShiftDepositMode.EXTRA_OP); - menuEntrySwapperPlugin.setShiftModifier(true); + when(client.isKeyPressed(KeyCode.KC_SHIFT)).thenReturn(true); entries = new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), @@ -338,7 +339,7 @@ public class MenuEntrySwapperPluginTest public void testShiftDeposit() { when(config.bankDepositShiftClick()).thenReturn(ShiftDepositMode.DEPOSIT_ALL); - menuEntrySwapperPlugin.setShiftModifier(true); + when(client.isKeyPressed(KeyCode.KC_SHIFT)).thenReturn(true); entries = new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL),