Moved Climb-Up/Down plugin into MenuEntrySwapper

This commit is contained in:
Justin
2019-05-18 21:32:00 +10:00
parent af8ba0d884
commit 341ea528f7
5 changed files with 51 additions and 173 deletions

View File

@@ -1,111 +0,0 @@
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;
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;
@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);
}
}
}

View File

@@ -1,62 +0,0 @@
package net.runelite.client.plugins.climbupclimbdown;
import java.awt.event.KeyEvent;
import javax.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.input.KeyListener;
@Slf4j
public class ShiftCtrlInputListener implements KeyListener
{
@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;
}
}
}

View File

@@ -302,4 +302,14 @@ public interface MenuEntrySwapperConfig extends Config
{
return true;
}
@ConfigItem(
keyName = "swapClimbUpDown",
name = "Climb",
description = "Swap Climb-Up/Down depending on Shift or Control key "
)
default boolean swapClimbUpDown()
{
return false;
}
}

View File

@@ -128,9 +128,14 @@ public class MenuEntrySwapperPlugin extends Plugin
@Getter
private boolean configuringShiftClick = false;
@Getter
@Setter
private boolean shiftModifier = false;
@Getter
@Setter
private boolean controlModifier = false;
@Provides
MenuEntrySwapperConfig provideConfig(ConfigManager configManager)
{
@@ -452,6 +457,16 @@ public class MenuEntrySwapperPlugin extends Plugin
}
}
else if (option.equalsIgnoreCase("climb") && config.swapClimbUpDown()) {
if (controlModifier ^ shiftModifier) {
if (shiftModifier) {
stripExceptFor("climb-up");
}
if (controlModifier) {
stripExceptFor("climb-down");
}
}
}
else if (config.swapTravel() && option.equals("pass") && target.equals("energy barrier"))
{
swap(client, "pay-toll(2-ecto)", option, target, true);
@@ -603,6 +618,24 @@ public class MenuEntrySwapperPlugin extends Plugin
}
}
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);
}
}
@Subscribe
public void onPostItemComposition(PostItemComposition event)
{

View File

@@ -54,6 +54,10 @@ public class ShiftClickInputListener implements KeyListener
{
plugin.setShiftModifier(true);
}
if (event.getKeyCode() == KeyEvent.VK_CONTROL)
{
plugin.setControlModifier(true);
}
}
@Override
@@ -63,5 +67,9 @@ public class ShiftClickInputListener implements KeyListener
{
plugin.setShiftModifier(false);
}
if (event.getKeyCode() == KeyEvent.VK_CONTROL)
{
plugin.setControlModifier(false);
}
}
}