Refactor climbplugin

This commit is contained in:
Scott Burns
2019-05-16 00:43:22 +02:00
parent 15c22ccf0c
commit d39d103bc2
2 changed files with 66 additions and 36 deletions

View File

@@ -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);
}
}
}

View File

@@ -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;
}