From d39d103bc255e55a631cf508d0226ffd0c7a38d5 Mon Sep 17 00:00:00 2001 From: Scott Burns Date: Thu, 16 May 2019 00:43:22 +0200 Subject: [PATCH] Refactor climbplugin --- .../plugins/climbupclimbdown/ClimbPlugin.java | 54 ++++++++++++------- .../ShiftCtrlInputListener.java | 48 ++++++++++------- 2 files changed, 66 insertions(+), 36 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/climbupclimbdown/ClimbPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/climbupclimbdown/ClimbPlugin.java index 858419ce58..4bc899a5e4 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/climbupclimbdown/ClimbPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/climbupclimbdown/ClimbPlugin.java @@ -1,5 +1,7 @@ package net.runelite.client.plugins.climbupclimbdown; +import javax.inject.Inject; +import javax.inject.Singleton; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -12,18 +14,16 @@ import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginType; -import javax.inject.Inject; -import javax.inject.Singleton; - @PluginDescriptor( - name = "Climb Up Climb Down", - description = "Hold Shift to Climb up, Ctrl to Climb down", - tags = {"climb", "stairs", "ladder", "swap", "key", "input"}, - type = PluginType.UTILITY + name = "Climb Up Climb Down", + description = "Hold Shift to Climb up, Ctrl to Climb down", + tags = {"climb", "stairs", "ladder", "swap", "key", "input"}, + type = PluginType.UTILITY ) @Slf4j @Singleton -public class ClimbPlugin extends Plugin { +public class ClimbPlugin extends Plugin +{ @Inject Client client; @@ -37,32 +37,45 @@ public class ClimbPlugin extends Plugin { @Getter @Setter private boolean isHoldingShift; + @Getter @Setter private boolean isHoldingCtrl; @Override - protected void startUp() throws Exception { + protected void startUp() throws Exception + { enableCustomization(); } @Override - protected void shutDown() throws Exception { + protected void shutDown() throws Exception + { disableCustomization(); } @Subscribe - public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded) { - try { - if (menuEntryAdded.getOption().equalsIgnoreCase("climb")) { - if (isHoldingCtrl ^ isHoldingShift) { + public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded) + { + try + { + if (menuEntryAdded.getOption().equalsIgnoreCase("climb")) + { + if (isHoldingCtrl ^ isHoldingShift) + { if (isHoldingShift) + { stripExceptFor("climb-up"); + } if (isHoldingCtrl) + { stripExceptFor("climb-down"); + } } } - } catch (Exception e) { + } + catch (Exception e) + { log.error("Uh oh!", e); } } @@ -78,16 +91,21 @@ public class ClimbPlugin extends Plugin { keyManager.unregisterKeyListener(inputListener); } - private void stripExceptFor(String option) { + private void stripExceptFor(String option) + { MenuEntry[] newEntries = new MenuEntry[1]; for (MenuEntry entry : client.getMenuEntries()) + { if (entry.getOption().equalsIgnoreCase(option)) + { newEntries[0] = entry; + } + } if (newEntries[0] != null) + { client.setMenuEntries(newEntries); + } } - - } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/climbupclimbdown/ShiftCtrlInputListener.java b/runelite-client/src/main/java/net/runelite/client/plugins/climbupclimbdown/ShiftCtrlInputListener.java index 8a1b47e680..4535c116ba 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/climbupclimbdown/ShiftCtrlInputListener.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/climbupclimbdown/ShiftCtrlInputListener.java @@ -1,48 +1,60 @@ package net.runelite.client.plugins.climbupclimbdown; +import java.awt.event.KeyEvent; +import javax.inject.Inject; import lombok.extern.slf4j.Slf4j; -import net.runelite.api.Client; import net.runelite.client.input.KeyListener; -import javax.inject.Inject; -import java.awt.event.KeyEvent; - @Slf4j -public class ShiftCtrlInputListener implements KeyListener { - - @Inject - Client client; - +public class ShiftCtrlInputListener implements KeyListener +{ @Inject ClimbPlugin plugin; @Override - public void keyTyped(KeyEvent e) { + public void keyTyped(KeyEvent e) + { } @Override - public void keyPressed(KeyEvent e) { - switch (e.getKeyCode()) { + public void keyPressed(KeyEvent e) + { + switch (e.getKeyCode()) + { case KeyEvent.VK_SHIFT: - if (plugin.isHoldingShift()) return; + if (plugin.isHoldingShift()) + { + return; + } plugin.setHoldingShift(true); break; case KeyEvent.VK_CONTROL: - if (plugin.isHoldingCtrl()) return; + if (plugin.isHoldingCtrl()) + { + return; + } plugin.setHoldingCtrl(true); break; } } @Override - public void keyReleased(KeyEvent e) { - switch (e.getKeyCode()) { + public void keyReleased(KeyEvent e) + { + switch (e.getKeyCode()) + { case KeyEvent.VK_SHIFT: - if (!plugin.isHoldingShift()) return; + if (!plugin.isHoldingShift()) + { + return; + } plugin.setHoldingShift(false); break; case KeyEvent.VK_CONTROL: - if (!plugin.isHoldingCtrl()) return; + if (!plugin.isHoldingCtrl()) + { + return; + } plugin.setHoldingCtrl(false); break; }