mes: merge shiftwalk

mes: merge shiftwalk
This commit is contained in:
xKylee
2020-01-26 23:48:05 +00:00
parent 68ed7eaba3
commit 25a2bf581a
4 changed files with 106 additions and 376 deletions

View File

@@ -1974,7 +1974,6 @@ public interface MenuEntrySwapperConfig extends Config
position = 2, position = 2,
section = "hotkeySwapping" section = "hotkeySwapping"
) )
default boolean swapNpcContact() default boolean swapNpcContact()
{ {
return false; return false;
@@ -1987,7 +1986,6 @@ public interface MenuEntrySwapperConfig extends Config
position = 3, position = 3,
section = "hotkeySwapping" section = "hotkeySwapping"
) )
default boolean bankWieldItem() default boolean bankWieldItem()
{ {
return false; return false;
@@ -2000,7 +1998,6 @@ public interface MenuEntrySwapperConfig extends Config
position = 4, position = 4,
section = "hotkeySwapping" section = "hotkeySwapping"
) )
default boolean bankWearItem() default boolean bankWearItem()
{ {
return false; return false;
@@ -2013,7 +2010,6 @@ public interface MenuEntrySwapperConfig extends Config
position = 5, position = 5,
section = "hotkeySwapping" section = "hotkeySwapping"
) )
default boolean bankEatItem() default boolean bankEatItem()
{ {
return false; return false;
@@ -2026,7 +2022,6 @@ public interface MenuEntrySwapperConfig extends Config
position = 6, position = 6,
section = "hotkeySwapping" section = "hotkeySwapping"
) )
default boolean bankDrinkItem() default boolean bankDrinkItem()
{ {
return false; return false;
@@ -2039,7 +2034,6 @@ public interface MenuEntrySwapperConfig extends Config
position = 7, position = 7,
section = "hotkeySwapping" section = "hotkeySwapping"
) )
default boolean bankEquipItem() default boolean bankEquipItem()
{ {
return false; return false;
@@ -2052,9 +2046,32 @@ public interface MenuEntrySwapperConfig extends Config
position = 8, position = 8,
section = "hotkeySwapping" section = "hotkeySwapping"
) )
default boolean bankInvigorateItem() default boolean bankInvigorateItem()
{ {
return false; return false;
} }
@ConfigItem(
keyName = "hotKeyWalk",
name = "Hotkey to Walk",
description = "For when you want Walk here as a priority",
position = 9,
section = "hotkeySwapping"
)
default boolean hotKeyWalk()
{
return false;
}
@ConfigItem(
keyName = "hotKeyLoot",
name = "Hotkey to Loot",
description = "For when people stand on your loot",
position = 10,
section = "hotkeySwapping"
)
default boolean hotKeyLoot()
{
return false;
}
} }

View File

@@ -149,6 +149,74 @@ public class MenuEntrySwapperPlugin extends Plugin
"mazchna", "vannaka", "chaeldar", "nieve", "steve", "duradel", "krystilia", "konar", "mazchna", "vannaka", "chaeldar", "nieve", "steve", "duradel", "krystilia", "konar",
"murphy", "cyrisus", "smoggy", "ginea", "watson", "barbarian guard", "random" "murphy", "cyrisus", "smoggy", "ginea", "watson", "barbarian guard", "random"
); );
private static final AbstractComparableEntry WALK = new AbstractComparableEntry()
{
private final int hash = "WALK".hashCode() * 79 + getPriority();
@Override
public int hashCode()
{
return hash;
}
@Override
public boolean equals(Object entry)
{
return entry.getClass() == this.getClass() && entry.hashCode() == this.hashCode();
}
@Override
public int getPriority()
{
return 99;
}
@Override
public boolean matches(MenuEntry entry)
{
return
entry.getOpcode() == MenuOpcode.WALK.getId() ||
entry.getOpcode() == MenuOpcode.WALK.getId() + MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET;
}
};
private static final AbstractComparableEntry TAKE = new AbstractComparableEntry()
{
private final int hash = "TAKE".hashCode() * 79 + getPriority();
@Override
public int hashCode()
{
return hash;
}
@Override
public boolean equals(Object entry)
{
return entry.getClass() == this.getClass() && entry.hashCode() == this.hashCode();
}
@Override
public int getPriority()
{
return 100;
}
@Override
public boolean matches(MenuEntry entry)
{
int opcode = entry.getOpcode();
if (opcode > MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET)
{
opcode -= MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET;
}
return
opcode >= MenuOpcode.GROUND_ITEM_FIRST_OPTION.getId() &&
opcode <= MenuOpcode.GROUND_ITEM_FIFTH_OPTION.getId();
}
};
private static final Splitter NEWLINE_SPLITTER = Splitter private static final Splitter NEWLINE_SPLITTER = Splitter
.on("\n") .on("\n")
@@ -300,6 +368,8 @@ public class MenuEntrySwapperPlugin extends Plugin
private boolean swapWildernessLever; private boolean swapWildernessLever;
private boolean swapJewelleryBox; private boolean swapJewelleryBox;
private boolean getSwapOffer; private boolean getSwapOffer;
private boolean hotKeyLoot;
private boolean hotKeyWalk;
private final HotkeyListener hotkey = new HotkeyListener(() -> this.hotkeyMod) private final HotkeyListener hotkey = new HotkeyListener(() -> this.hotkeyMod)
{ {
@Override @Override
@@ -1525,7 +1595,14 @@ public class MenuEntrySwapperPlugin extends Plugin
{ {
menuManager.addPriorityEntry("climb-up").setPriority(100); menuManager.addPriorityEntry("climb-up").setPriority(100);
} }
if (this.hotKeyLoot)
{
menuManager.addPriorityEntry(TAKE);
}
if (this.hotKeyWalk)
{
menuManager.addPriorityEntry(WALK);
}
if (this.swapNpcContact) if (this.swapNpcContact)
{ {
for (String npccontact : npcContact) for (String npccontact : npcContact)
@@ -1551,6 +1628,8 @@ public class MenuEntrySwapperPlugin extends Plugin
menuManager.removePriorityEntry(new BankComparableEntry("equip", "", false)); menuManager.removePriorityEntry(new BankComparableEntry("equip", "", false));
menuManager.removePriorityEntry(new BankComparableEntry("invigorate", "", false)); menuManager.removePriorityEntry(new BankComparableEntry("invigorate", "", false));
menuManager.removePriorityEntry("climb-up"); menuManager.removePriorityEntry("climb-up");
menuManager.removePriorityEntry(TAKE);
menuManager.removePriorityEntry(WALK);
for (String npccontact : npcContact) for (String npccontact : npcContact)
{ {
@@ -1796,6 +1875,8 @@ public class MenuEntrySwapperPlugin extends Plugin
this.bankInvigorateItem = config.bankInvigorateItem(); this.bankInvigorateItem = config.bankInvigorateItem();
this.swapNpcContact = config.swapNpcContact(); this.swapNpcContact = config.swapNpcContact();
this.getSwapOffer = config.getSwapOffer(); this.getSwapOffer = config.getSwapOffer();
this.hotKeyWalk = config.hotKeyWalk();
this.hotKeyLoot = config.hotKeyLoot();
} }
private void addBuySellEntries() private void addBuySellEntries()

View File

@@ -1,87 +0,0 @@
/*
* Copyright (c) 2018, Plinko60
* 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.shiftwalker;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup("shiftwalkhere")
public interface ShiftWalkerConfig extends Config
{
@ConfigItem(
keyName = "shiftWalk",
name = "Shift to Walk",
description = "For when you want Walk here as a priority"
)
default boolean shiftWalk()
{
return false;
}
@ConfigItem(
keyName = "shiftLoot",
name = "Shift to Loot",
description = "For when people stand on your loot"
)
default boolean shiftLoot()
{
return false;
}
/*
@ConfigItem(
keyName = "shiftWalkEverything",
name = "Walk Under Everything",
description = "Enable this option when you do not want to interact with anything while Shift is pressed. " +
"If Walk Here is an option it will be the action taken."
)
default boolean shiftWalkEverything()
{
return true;
}
@ConfigItem(
keyName = "shiftWalkBoxTraps",
name = "Walk Under Box Traps",
description = "Press \"Shift\" to be able to walk under instead of picking up a Box Trap."
)
default boolean shiftWalkBoxTraps()
{
return true;
}
@ConfigItem(
keyName = "shiftWalkAttackOption",
name = "Walk Under Attack Options",
description = "Press \"Shift\" to be able to walk instead of attacking. Make sure Left Click Attack is on."
)
default boolean shiftWalkAttackOption()
{
return true;
}
*/
}

View File

@@ -1,281 +0,0 @@
/*
* Copyright (c) 2018, Plinko60
* 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.shiftwalker;
import com.google.inject.Provides;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.AccessLevel;
import lombok.Setter;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.MenuEntry;
import net.runelite.api.MenuOpcode;
import net.runelite.api.events.ClientTick;
import net.runelite.api.events.FocusChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.config.Keybind;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.input.KeyManager;
import net.runelite.client.menus.AbstractComparableEntry;
import net.runelite.client.menus.MenuManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginType;
import net.runelite.client.util.HotkeyListener;
/**
* Shift Walker Plugin. Credit to MenuEntrySwapperPlugin for code some code structure used here.
*/
@PluginDescriptor(
name = "Shift Walk Under",
description = "Use Shift to toggle the Walk Here menu option. While pressed you will Walk rather than interact with objects.",
tags = {"npcs", "items", "objects"},
type = PluginType.UTILITY,
enabledByDefault = false
)
@Singleton
public class ShiftWalkerPlugin extends Plugin
{
private static final AbstractComparableEntry WALK = new AbstractComparableEntry()
{
private final int hash = "WALK".hashCode() * 79 + getPriority();
@Override
public int hashCode()
{
return hash;
}
@Override
public boolean equals(Object entry)
{
return entry.getClass() == this.getClass() && entry.hashCode() == this.hashCode();
}
@Override
public int getPriority()
{
return 99;
}
@Override
public boolean matches(MenuEntry entry)
{
return
entry.getOpcode() == MenuOpcode.WALK.getId() ||
entry.getOpcode() == MenuOpcode.WALK.getId() + MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET;
}
};
private static final AbstractComparableEntry TAKE = new AbstractComparableEntry()
{
private final int hash = "TAKE".hashCode() * 79 + getPriority();
@Override
public int hashCode()
{
return hash;
}
@Override
public boolean equals(Object entry)
{
return entry.getClass() == this.getClass() && entry.hashCode() == this.hashCode();
}
@Override
public int getPriority()
{
return 100;
}
@Override
public boolean matches(MenuEntry entry)
{
int opcode = entry.getOpcode();
if (opcode > MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET)
{
opcode -= MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET;
}
return
opcode >= MenuOpcode.GROUND_ITEM_FIRST_OPTION.getId() &&
opcode <= MenuOpcode.GROUND_ITEM_FIFTH_OPTION.getId();
}
};
private static final String EVENTBUS_THING = "shiftwalker shift";
private static final String SHIFT_CHECK = "shiftwalker hotkey check";
@Inject
private Client client;
@Inject
private ShiftWalkerConfig config;
@Inject
private MenuManager menuManager;
@Inject
private KeyManager keyManager;
@Inject
private EventBus eventBus;
@Setter(AccessLevel.PRIVATE)
private boolean hotkeyActive;
private boolean shiftWalk;
private boolean shiftLoot;
@Provides
ShiftWalkerConfig provideConfig(ConfigManager configManager)
{
return configManager.getConfig(ShiftWalkerConfig.class);
}
private final HotkeyListener shift = new HotkeyListener(() -> Keybind.SHIFT)
{
@Override
public void hotkeyPressed()
{
startPrioritizing();
setHotkeyActive(true);
}
@Override
public void hotkeyReleased()
{
stopPrioritizing();
setHotkeyActive(false);
}
};
@Override
public void startUp()
{
this.shiftWalk = config.shiftWalk();
this.shiftLoot = config.shiftLoot();
if (client.getGameState() == GameState.LOGGED_IN)
{
keyManager.registerKeyListener(shift);
}
}
@Override
public void shutDown()
{
keyManager.unregisterKeyListener(shift);
}
@Subscribe
private void onGameStateChanged(GameStateChanged event)
{
if (event.getGameState() != GameState.LOGGED_IN)
{
keyManager.unregisterKeyListener(shift);
return;
}
keyManager.registerKeyListener(shift);
}
@Subscribe
private void onFocusChanged(FocusChanged event)
{
if (!event.isFocused())
{
stopPrioritizing();
}
}
@Subscribe
private void onConfigChanged(ConfigChanged event)
{
if (!event.getGroup().equals("shiftwalkhere"))
{
return;
}
if ("shiftWalk".equals(event.getKey()))
{
this.shiftWalk = "true".equals(event.getNewValue());
}
else
{
this.shiftLoot = "true".equals(event.getNewValue());
}
}
private void hotkeyCheck(ClientTick event)
{
if (hotkeyActive)
{
int i = 0;
for (boolean bol : client.getPressedKeys())
{
if (bol)
{
i++;
}
}
if (i == 0)
{
stopPrioritizing();
setHotkeyActive(false);
eventBus.unregister(SHIFT_CHECK);
}
}
}
private void startPrioritizing()
{
eventBus.subscribe(ClientTick.class, EVENTBUS_THING, this::addEntries);
eventBus.subscribe(ClientTick.class, SHIFT_CHECK, this::hotkeyCheck);
}
private void addEntries(ClientTick event)
{
if (this.shiftLoot)
{
menuManager.addPriorityEntry(TAKE);
}
if (this.shiftWalk)
{
menuManager.addPriorityEntry(WALK);
}
eventBus.unregister(EVENTBUS_THING);
}
private void stopPrioritizing()
{
eventBus.subscribe(ClientTick.class, EVENTBUS_THING, this::removeEntries);
}
private void removeEntries(ClientTick event)
{
menuManager.removePriorityEntry(TAKE);
menuManager.removePriorityEntry(WALK);
eventBus.unregister(EVENTBUS_THING);
}
}