Merge pull request #230 from gazivodag/climbplugin
climb up climb down plugin using shift and ctrl
This commit is contained in:
@@ -0,0 +1,93 @@
|
|||||||
|
package net.runelite.client.plugins.climbupclimbdown;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.MenuEntry;
|
||||||
|
import net.runelite.api.events.MenuEntryAdded;
|
||||||
|
import net.runelite.client.eventbus.Subscribe;
|
||||||
|
import net.runelite.client.input.KeyManager;
|
||||||
|
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
|
||||||
|
)
|
||||||
|
@Slf4j
|
||||||
|
@Singleton
|
||||||
|
public class ClimbPlugin extends Plugin {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
Client client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
KeyManager keyManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ShiftCtrlInputListener inputListener;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private boolean isHoldingShift;
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private boolean isHoldingCtrl;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void startUp() throws Exception {
|
||||||
|
enableCustomization();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void shutDown() throws Exception {
|
||||||
|
disableCustomization();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
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) {
|
||||||
|
log.error("Uh oh!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void enableCustomization()
|
||||||
|
{
|
||||||
|
keyManager.registerKeyListener(inputListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disableCustomization()
|
||||||
|
{
|
||||||
|
keyManager.unregisterKeyListener(inputListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package net.runelite.client.plugins.climbupclimbdown;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ClimbPlugin plugin;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyTyped(KeyEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyPressed(KeyEvent e) {
|
||||||
|
switch (e.getKeyCode()) {
|
||||||
|
case KeyEvent.VK_SHIFT:
|
||||||
|
if (plugin.isHoldingShift()) return;
|
||||||
|
plugin.setHoldingShift(true);
|
||||||
|
break;
|
||||||
|
case KeyEvent.VK_CONTROL:
|
||||||
|
if (plugin.isHoldingCtrl()) return;
|
||||||
|
plugin.setHoldingCtrl(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e) {
|
||||||
|
switch (e.getKeyCode()) {
|
||||||
|
case KeyEvent.VK_SHIFT:
|
||||||
|
if (!plugin.isHoldingShift()) return;
|
||||||
|
plugin.setHoldingShift(false);
|
||||||
|
break;
|
||||||
|
case KeyEvent.VK_CONTROL:
|
||||||
|
if (!plugin.isHoldingCtrl()) return;
|
||||||
|
plugin.setHoldingCtrl(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user