Merge remote-tracking branch 'upstream/master' into Cleanup

This commit is contained in:
Scott Burns
2019-05-16 01:49:51 +02:00
9 changed files with 270 additions and 288 deletions

View File

@@ -74,6 +74,7 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginType;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import static net.runelite.client.util.MenuUtil.swap;
import net.runelite.client.util.Text;
import org.apache.commons.lang3.ArrayUtils;
@@ -439,7 +440,7 @@ public class BAToolsPlugin extends Plugin implements KeyListener
if (config.swapLadder() && option.equals("climb-down") && target.equals("ladder"))
{
swap("quick-start", option, target, true);
swap(client, "quick-start", option, target, true);
}
else if (config.removeBA() && client.getVar(Varbits.IN_GAME_BA) == 1 && !option.contains("tell-"))//if in barbarian assault and menu isnt from a horn
{
@@ -722,23 +723,6 @@ public class BAToolsPlugin extends Plugin implements KeyListener
client.setMenuEntries(entries);
}
private void swap(String optionA, String optionB, String target, boolean strict)
{
MenuEntry[] entries = client.getMenuEntries();
int idxA = searchIndex(entries, optionA, target, strict);
int idxB = searchIndex(entries, optionB, target, strict);
if (idxA >= 0 && idxB >= 0)
{
MenuEntry entry = entries[idxA];
entries[idxA] = entries[idxB];
entries[idxB] = entry;
client.setMenuEntries(entries);
}
}
private int searchIndex(MenuEntry[] entries, String option, String target, boolean strict)
{
for (int i = entries.length - 1; i >= 0; i--)

View File

@@ -26,7 +26,11 @@ package net.runelite.client.plugins.easyscape;
import com.google.inject.Provides;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.*;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
import net.runelite.api.Player;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.widgets.Widget;
@@ -35,15 +39,11 @@ import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginManager;
import net.runelite.client.plugins.PluginType;
import static net.runelite.client.util.MenuUtil.swap;
import net.runelite.client.util.Text;
import org.apache.commons.lang3.ArrayUtils;
import javax.inject.Inject;
import java.util.*;
import static net.runelite.api.MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET;
import static net.runelite.api.MenuAction.WALK;
@@ -62,7 +62,6 @@ public class EasyscapePlugin extends Plugin {
private static final int PURO_PURO_REGION_ID = 10307;
private static final int HOUSE_REGION_ID = 7513;
private Set<Swapper> swapping;
private MenuEntry[] entries;
@Inject
@@ -79,7 +78,6 @@ public class EasyscapePlugin extends Plugin {
@Override
public void startUp() {
log.debug("Easyscape Started.");
swapping = new HashSet<>();
}
@Override
@@ -140,10 +138,10 @@ public class EasyscapePlugin extends Plugin {
client.setMenuEntries(entries);
}
else if (option.equalsIgnoreCase("examine")) {
swap("push-through", option, target);
swap(client, "push-through", option, target);
}
else if (option.equalsIgnoreCase("use")) {
swap("escape", option, target);
swap(client, "escape", option, target);
}
}
@@ -154,7 +152,7 @@ public class EasyscapePlugin extends Plugin {
client.setMenuEntries(entries);
}
swap("Build", option, target);
swap(client, "Build", option, target);
for (int i = entries.length - 1; i >= 0; i--) {
for (String item : config.getConstructionItems().split(",")) {
@@ -173,46 +171,46 @@ public class EasyscapePlugin extends Plugin {
if (config.getSwapShop() && !config.getSwappedItems().equals("")) {
for (String item : config.getSwappedItems().split(",")) {
if (target.equalsIgnoreCase(item.trim())) {
swap("Buy 50", option, target);
swap(client, "Buy 50", option, target);
}
}
}
if (config.getSwapSmithing()) {
if (option.equalsIgnoreCase("Smith 1")) {
swap("Smith All", option, target);
swap(client, "Smith All", option, target);
} else if (option.equalsIgnoreCase("Smith 1 Set")) {
swap("Smith All Sets", option, target);
swap(client, "Smith All Sets", option, target);
}
}
if (config.getSwapTanning() && option.equalsIgnoreCase("Tan 1")) {
swap("Tan All", option, target);
swap(client, "Tan All", option, target);
}
if (config.getSwapCrafting() && option.equalsIgnoreCase("Make-1")) {
swap("Make-All", option, target);
swap(client, "Make-All", option, target);
}
if (config.getSwapSawmill() && target.equalsIgnoreCase("Sawmill operator")) {
swap("Buy-plank", option, target);
swap(client, "Buy-plank", option, target);
}
if (config.getSwapSawmillPlanks() && option.equalsIgnoreCase("Buy 1")) {
swap("Buy All", option, target);
swap(client, "Buy All", option, target);
}
if (config.getSwapStairs() && option.equalsIgnoreCase("Climb Stairs")) {
swap("Climb Up Stairs", option, target);
swap(client, "Climb Up Stairs", option, target);
}
if (option.equalsIgnoreCase("Clear-All") && target.equalsIgnoreCase("Bank Filler")) {
swap("Clear", option, target);
swap(client, "Clear", option, target);
}
if (target.toLowerCase().contains("ardougne cloak") && config.getSwapArdougneCape()) {
swap("Kandarin Monastery", option, target);
swap("Monastery Teleport", option, target);
swap(client, "Kandarin Monastery", option, target);
swap(client, "Monastery Teleport", option, target);
}
if (config.getSwapEssencePouch()) {
@@ -221,16 +219,16 @@ public class EasyscapePlugin extends Plugin {
switch (config.getEssenceMode()) {
case RUNECRAFTING:
if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden()) {
swap("Empty", option, target);
swap(client, "Empty", option, target);
} else {
swap("Fill", option, target);
swap(client, "Fill", option, target);
}
break;
case ESSENCE_MINING:
if (widgetBankTitleBar == null || widgetBankTitleBar.isHidden()) {
swap("Fill", option, target);
swap(client, "Fill", option, target);
} else {
swap("Empty", option, target);
swap(client, "Empty", option, target);
}
break;
default:
@@ -243,19 +241,19 @@ public class EasyscapePlugin extends Plugin {
if (target.toLowerCase().contains("games necklace")) {
switch (config.getGamesNecklaceMode()) {
case BURTHORPE:
swap(GamesNecklaceMode.BURTHORPE.toString(), option, target);
swap(client, GamesNecklaceMode.BURTHORPE.toString(), option, target);
break;
case BARBARIAN_OUTPOST:
swap(GamesNecklaceMode.BARBARIAN_OUTPOST.toString(), option, target);
swap(client, GamesNecklaceMode.BARBARIAN_OUTPOST.toString(), option, target);
break;
case CORPOREAL_BEAST:
swap(GamesNecklaceMode.CORPOREAL_BEAST.toString(), option, target);
swap(client, GamesNecklaceMode.CORPOREAL_BEAST.toString(), option, target);
break;
case TEARS_OF_GUTHIX:
swap(GamesNecklaceMode.TEARS_OF_GUTHIX.toString(), option, target);
swap(client, GamesNecklaceMode.TEARS_OF_GUTHIX.toString(), option, target);
break;
case WINTERTODT:
swap(GamesNecklaceMode.WINTERTODT.toString(), option, target);
swap(client, GamesNecklaceMode.WINTERTODT.toString(), option, target);
break;
default:
break;
@@ -267,13 +265,13 @@ public class EasyscapePlugin extends Plugin {
if (target.toLowerCase().contains("ring of dueling")) {
switch (config.getDuelingRingMode()) {
case DUEL_ARENA:
swap(DuelingRingMode.DUEL_ARENA.toString(), option, target);
swap(client, DuelingRingMode.DUEL_ARENA.toString(), option, target);
break;
case CASTLE_WARS:
swap(DuelingRingMode.CASTLE_WARS.toString(), option, target);
swap(client, DuelingRingMode.CASTLE_WARS.toString(), option, target);
break;
case CLAN_WARS:
swap(DuelingRingMode.CLAN_WARS.toString(), option, target);
swap(client, DuelingRingMode.CLAN_WARS.toString(), option, target);
break;
default:
break;
@@ -285,16 +283,16 @@ public class EasyscapePlugin extends Plugin {
if (target.toLowerCase().contains("ring of wealth")) {
switch (config.getWealthRingMode()) {
case MISCELLANIA:
swap(WealthRingMode.MISCELLANIA.toString(), option, target);
swap(client, WealthRingMode.MISCELLANIA.toString(), option, target);
break;
case GRAND_EXCHANGE:
swap(WealthRingMode.GRAND_EXCHANGE.toString(), option, target);
swap(client, WealthRingMode.GRAND_EXCHANGE.toString(), option, target);
break;
case FALADOR:
swap(WealthRingMode.FALADOR.toString(), option, target);
swap(client, WealthRingMode.FALADOR.toString(), option, target);
break;
case DONDAKAN:
swap(WealthRingMode.DONDAKAN.toString(), option, target);
swap(client, WealthRingMode.DONDAKAN.toString(), option, target);
break;
default:
break;
@@ -306,16 +304,16 @@ public class EasyscapePlugin extends Plugin {
if (target.toLowerCase().contains("amulet of glory")) {
switch (config.getGloryMode()) {
case EDGEVILLE:
swap(GloryMode.EDGEVILLE.toString(), option, target);
swap(client, GloryMode.EDGEVILLE.toString(), option, target);
break;
case KARAMJA:
swap(GloryMode.KARAMJA.toString(), option, target);
swap(client, GloryMode.KARAMJA.toString(), option, target);
break;
case DRAYNOR_VILLAGE:
swap(GloryMode.DRAYNOR_VILLAGE.toString(), option, target);
swap(client, GloryMode.DRAYNOR_VILLAGE.toString(), option, target);
break;
case AL_KHARID:
swap(GloryMode.AL_KHARID.toString(), option, target);
swap(client, GloryMode.AL_KHARID.toString(), option, target);
break;
default:
break;
@@ -324,50 +322,14 @@ public class EasyscapePlugin extends Plugin {
}
if (target.toLowerCase().contains("crafting cape") && config.getSwapCraftingCape()) {
swap("Teleport", option, target);
swap(client, "Teleport", option, target);
}
if (target.toLowerCase().contains("construct. cape") && config.getSwapConstructionCape()) {
swap("Tele to poh", option, target);
swap(client, "Tele to poh", option, target);
}
startSwap();
performSwap();
}
private void swap(String optionA, String optionB, String target) {
swapping.add(new Swapper(target, optionA, optionB));
}
private void startSwap() {
int index = 0;
for (MenuEntry entry : entries) {
String target = Text.removeTags(entry.getTarget()).toLowerCase();
for (Swapper swap : swapping) {
if (swap.getTarget().equalsIgnoreCase(target)) {
if (entry.getOption().equalsIgnoreCase(swap.getOptionOne())) {
swap.setIndexOne(index);
} else if (entry.getOption().equalsIgnoreCase(swap.getOptionTwo())) {
swap.setIndexTwo(index);
}
}
}
index++;
}
}
private void performSwap() {
for (Swapper swap : swapping) {
if (swap.isReady()) {
MenuEntry entry = entries[swap.getIndexOne()];
entries[swap.getIndexOne()] = entries[swap.getIndexTwo()];
entries[swap.getIndexTwo()] = entry;
}
}
client.setMenuEntries(entries);
swapping.clear();
}
private void delete(int target) {

View File

@@ -1,60 +0,0 @@
/*
* Copyright (c) 2018, https://runelitepl.us
* 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.easyscape;
import lombok.Getter;
import lombok.Setter;
public class Swapper {
@Getter
private String target;
@Getter
private String optionOne;
@Getter
private String optionTwo;
@Getter
@Setter
private int indexOne;
@Getter
@Setter
private int indexTwo;
public Swapper(String target, String optionOne, String optionTwo) {
this.target = target;
this.optionOne = optionOne;
this.optionTwo = optionTwo;
this.indexOne = -1;
this.indexTwo = -1;
}
public boolean isReady() {
return this.indexOne != -1 && this.indexTwo != -1;
}
}

View File

@@ -55,6 +55,7 @@ import net.runelite.client.menus.MenuManager;
import net.runelite.client.menus.WidgetMenuOption;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import static net.runelite.client.util.MenuUtil.swap;
import net.runelite.client.util.Text;
import org.apache.commons.lang3.ArrayUtils;
@@ -375,105 +376,105 @@ public class MenuEntrySwapperPlugin extends Plugin
{
if (config.swapPickpocket() && target.contains("h.a.m."))
{
swap("pickpocket", option, target, true);
swap(client, "pickpocket", option, target, true);
}
if (config.swapAbyssTeleport() && target.contains("mage of zamorak"))
{
swap("teleport", option, target, true);
swap(client, "teleport", option, target, true);
}
if (config.swapBank())
{
swap("bank", option, target, true);
swap(client, "bank", option, target, true);
}
if (config.swapContract())
{
swap("contract", option, target, true);
swap(client, "contract", option, target, true);
}
if (config.swapExchange())
{
swap("exchange", option, target, true);
swap(client, "exchange", option, target, true);
}
if (config.swapDarkMage())
{
swap("repairs", option, target, true);
swap(client, "repairs", option, target, true);
}
// make sure assignment swap is higher priority than trade swap for slayer masters
if (config.swapAssignment())
{
swap("assignment", option, target, true);
swap(client, "assignment", option, target, true);
}
if (config.swapTrade())
{
swap("trade", option, target, true);
swap("trade-with", option, target, true);
swap(client, "trade", option, target, true);
swap(client, "trade-with", option, target, true);
}
if (config.claimSlime() && target.equals("robin"))
{
swap("claim-slime", option, target, true);
swap(client, "claim-slime", option, target, true);
}
if (config.swapTravel())
{
swap("travel", option, target, true);
swap("pay-fare", option, target, true);
swap("charter", option, target, true);
swap("take-boat", option, target, true);
swap("fly", option, target, true);
swap("jatizso", option, target, true);
swap("neitiznot", option, target, true);
swap("rellekka", option, target, true);
swap("follow", option, target, true);
swap("transport", option, target, true);
swap(client, "travel", option, target, true);
swap(client, "pay-fare", option, target, true);
swap(client, "charter", option, target, true);
swap(client, "take-boat", option, target, true);
swap(client, "fly", option, target, true);
swap(client, "jatizso", option, target, true);
swap(client, "neitiznot", option, target, true);
swap(client, "rellekka", option, target, true);
swap(client, "follow", option, target, true);
swap(client, "transport", option, target, true);
}
if (config.swapPay())
{
swap("pay", option, target, true);
swap("pay (", option, target, false);
swap(client, "pay", option, target, true);
swap(client, "pay (", option, target, false);
}
if (config.swapDecant())
{
swap("decant", option, target, true);
swap(client, "decant", option, target, true);
}
if (config.swapQuick())
{
swap("quick-travel", option, target, true);
swap(client, "quick-travel", option, target, true);
}
}
else if (config.swapTravel() && option.equals("pass") && target.equals("energy barrier"))
{
swap("pay-toll(2-ecto)", option, target, true);
swap(client, "pay-toll(2-ecto)", option, target, true);
}
else if (config.swapTravel() && option.equals("open") && target.equals("gate"))
{
swap("pay-toll(10gp)", option, target, true);
swap(client, "pay-toll(10gp)", option, target, true);
}
else if (config.swapTravel() && option.equals("inspect") && target.equals("trapdoor"))
{
swap("travel", option, target, true);
swap(client, "travel", option, target, true);
}
else if (config.swapHarpoon() && option.equals("cage"))
{
swap("harpoon", option, target, true);
swap(client, "harpoon", option, target, true);
}
else if (config.swapHarpoon() && (option.equals("big net") || option.equals("net")))
{
swap("harpoon", option, target, true);
swap(client, "harpoon", option, target, true);
}
else if (config.swapHomePortal() != HouseMode.ENTER && option.equals("enter"))
@@ -481,13 +482,13 @@ public class MenuEntrySwapperPlugin extends Plugin
switch (config.swapHomePortal())
{
case HOME:
swap("home", option, target, true);
swap(client, "home", option, target, true);
break;
case BUILD_MODE:
swap("build mode", option, target, true);
swap(client, "build mode", option, target, true);
break;
case FRIENDS_HOUSE:
swap("friend's house", option, target, true);
swap(client, "friend's house", option, target, true);
break;
}
}
@@ -496,80 +497,80 @@ public class MenuEntrySwapperPlugin extends Plugin
{
if (config.swapFairyRing() == FairyRingMode.LAST_DESTINATION)
{
swap("last-destination", option, target, false);
swap(client, "last-destination", option, target, false);
}
else if (config.swapFairyRing() == FairyRingMode.CONFIGURE)
{
swap("configure", option, target, false);
swap(client, "configure", option, target, false);
}
}
else if (config.swapFairyRing() == FairyRingMode.ZANARIS && option.equals("tree"))
{
swap("zanaris", option, target, false);
swap(client, "zanaris", option, target, false);
}
else if (config.swapBoxTrap() && (option.equals("check") || option.equals("dismantle")))
{
swap("reset", option, target, true);
swap(client, "reset", option, target, true);
}
else if (config.swapBoxTrap() && option.equals("take"))
{
swap("lay", option, target, true);
swap(client, "lay", option, target, true);
}
else if (config.swapChase() && option.equals("pick-up"))
{
swap("chase", option, target, true);
swap(client, "chase", option, target, true);
}
else if (config.swapBirdhouseEmpty() && option.equals("interact") && target.contains("birdhouse"))
{
swap("empty", option, target, true);
swap(client, "empty", option, target, true);
}
else if (config.swapQuick() && option.equals("ring"))
{
swap("quick-start", option, target, true);
swap(client, "quick-start", option, target, true);
}
else if (config.swapQuick() && option.equals("pass"))
{
swap("quick-pass", option, target, true);
swap("quick pass", option, target, true);
swap(client, "quick-pass", option, target, true);
swap(client, "quick pass", option, target, true);
}
else if (config.swapQuick() && option.equals("open"))
{
swap("quick-open", option, target, true);
swap(client, "quick-open", option, target, true);
}
else if (config.swapAdmire() && option.equals("admire"))
{
swap("teleport", option, target, true);
swap("spellbook", option, target, true);
swap("perks", option, target, true);
swap(client, "teleport", option, target, true);
swap(client, "spellbook", option, target, true);
swap(client, "perks", option, target, true);
}
else if (config.swapPrivate() && option.equals("shared"))
{
swap("private", option, target, true);
swap(client, "private", option, target, true);
}
else if (config.swapPick() && option.equals("pick"))
{
swap("pick-lots", option, target, true);
swap(client, "pick-lots", option, target, true);
}
else if (config.swapRogueschests() && target.contains("chest"))
{
swap("search for traps", option, target, true);
swap(client, "search for traps", option, target, true);
}
else if (config.rockCake() && option.equals("eat"))
{
swap("guzzle", option, target, true);
swap(client, "guzzle", option, target, true);
}
@@ -579,26 +580,26 @@ public class MenuEntrySwapperPlugin extends Plugin
if (customOption != null && customOption == -1)
{
swap("use", option, target, true);
swap(client, "use", option, target, true);
}
}
// Put all item-related swapping after shift-click
else if (config.swapTeleportItem() && option.equals("wear"))
{
swap("rub", option, target, true);
swap("teleport", option, target, true);
swap(client, "rub", option, target, true);
swap(client, "teleport", option, target, true);
}
else if (option.equals("wield"))
{
if (config.swapTeleportItem())
{
swap("teleport", option, target, true);
swap(client, "teleport", option, target, true);
}
}
else if (config.swapBones() && option.equals("bury"))
{
swap("use", option, target, true);
swap(client, "use", option, target, true);
}
}
@@ -650,23 +651,6 @@ public class MenuEntrySwapperPlugin extends Plugin
return -1;
}
private void swap(String optionA, String optionB, String target, boolean strict)
{
MenuEntry[] entries = client.getMenuEntries();
int idxA = searchIndex(entries, optionA, target, strict);
int idxB = searchIndex(entries, optionB, target, strict);
if (idxA >= 0 && idxB >= 0)
{
MenuEntry entry = entries[idxA];
entries[idxA] = entries[idxB];
entries[idxB] = entry;
client.setMenuEntries(entries);
}
}
private void removeShiftClickCustomizationMenus()
{
menuManager.removeManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE);

View File

@@ -416,6 +416,9 @@ public class PvpToolsPlugin extends Plugin
if (lastEntry.getOption().contains("attack".toLowerCase()))
{
ArrayUtils.shift(menuEntries, 1);
//ArrayUtils.add(menuEntries, menuEntries.length - 2);
//menuEntries = ArrayUtils.remove(menuEntries, menuEntries.length - 1);
//menuEntrySwapperPlugin.swap("attack", option, mtarget, false); TODO: Make sure to use menuutil when uncommenting this
}
if (lastEntry.getOption().equals("Attack"))
{

View File

@@ -60,6 +60,7 @@ import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
import static net.runelite.client.util.MenuUtil.swap;
import net.runelite.client.util.Text;
@PluginDescriptor(
@@ -170,12 +171,12 @@ public class RunecraftPlugin extends Plugin
{
if (option.equals("deposit-all") && type == 57 && id == 2)
{
swap("fill", option, target);
swap("cancel", option, "", target);
swap(client, "fill", option, target);
swap(client, "cancel", option, "", target);
}
else if (option.equals("fill") && id != 9)
{
swap("empty", option, target);
swap(client, "empty", option, target);
}
}
@@ -183,11 +184,11 @@ public class RunecraftPlugin extends Plugin
{
if (target.contains("7") || target.contains("5") || target.contains("3") || target.contains("1"))
{
swap("castle wars", option, target);
swap(client, "castle wars", option, target);
}
else if (wearingBindingNeck())
{
swap("duel arena", option, target);
swap(client, "duel arena", option, target);
}
}
@@ -201,28 +202,6 @@ public class RunecraftPlugin extends Plugin
}
}
private void swap(String opA, String opB, String target)
{
swap(opA, opB, target, target);
}
private void swap(String opA, String opB, String targetA, String targetB)
{
MenuEntry[] entries = client.getMenuEntries();
int idxA = searchIndex(entries, opA, targetA);
int idxB = searchIndex(entries, opB, targetB);
if (idxA >= 0 && idxB >= 0)
{
MenuEntry entry = entries[idxA];
entries[idxA] = entries[idxB];
entries[idxB] = entry;
client.setMenuEntries(entries);
}
}
private void hide(String option, String target, boolean contains)
{
final MenuEntry[] entries = client.getMenuEntries();

View File

@@ -147,10 +147,9 @@ public class ShiftWalkerPlugin extends Plugin
MenuEntry walkkHereEntry = null;
for (MenuEntry entry : client.getMenuEntries()) {
switch (entry.getOption()) {
case "Walk here":
walkkHereEntry = entry;
break;
if ("Walk here".equals(entry.getOption()))
{
walkkHereEntry = entry;
}
}
if (walkkHereEntry != null) {
@@ -164,7 +163,7 @@ public class ShiftWalkerPlugin extends Plugin
* Swaps menu entries if the entries could be found. This places Walk Here where the top level menu option was.
* @param pOptionToReplace The String containing the Menu Option that needs to be replaced. IE: "Attack", "Chop Down".
*/
private void swap(String pOptionToReplace)
private void swap(String pOptionToReplace) // Swap isn't currently used, and I don't know what's going on here so leaving for now
{
MenuEntry[] entries = client.getMenuEntries();

View File

@@ -205,33 +205,32 @@ public class SpellbookPlugin extends Plugin
str = removeFlyingComma(str).toLowerCase();
spell = spell.toLowerCase();
if (mode == WordFilterMode.CONTAINS)
switch (mode)
{
if (spell.contains(str))
{
return true;
}
}
else if (mode == WordFilterMode.STARTSWITH)
{
if (spell.startsWith(str))
{
return true;
}
}
else if (mode == WordFilterMode.ENDSWITH)
{
if (spell.endsWith(str))
{
return true;
}
}
else if (mode == WordFilterMode.EQUALS)
{
if (spell.equals(str))
{
return true;
}
case CONTAINS:
if (spell.contains(str))
{
return true;
}
break;
case STARTSWITH:
if (spell.startsWith(str))
{
return true;
}
break;
case ENDSWITH:
if (spell.endsWith(str))
{
return true;
}
break;
case EQUALS:
if (spell.equals(str))
{
return true;
}
break;
}
}

View File

@@ -0,0 +1,132 @@
/*
* Copyright (c) 2019, Lucas <https://github.com/Lucwousin>
* 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.util;
import com.google.common.collect.Lists;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.MenuEntry;
@Slf4j
public class MenuUtil
{
public static void swap(Client client, MenuEntry entry1, MenuEntry entry2)
{
List<MenuEntry> entries = Arrays.asList(client.getMenuEntries());
if (!entries.contains(entry1) || !entries.contains(entry2))
{
log.warn("Can't swap {} with {} as one or both menuentries aren't present", entry1, entry2);
return;
}
int idxA = entries.indexOf(entry1);
int idxB = entries.indexOf(entry2);
entries.set(idxA, entry2);
entries.set(idxB, entry1);
client.setMenuEntries(entries.toArray(new MenuEntry[0]));
}
public static void swap(Client client, String option1, String option2, String target1, String target2, boolean strict)
{
if (strict)
{
swap(client, option1, option2, target1, target2);
}
else
{
swapNotStrict(client, option1, option2, target1, target2);
}
}
public static void swap(Client client, String option1, String option2, String target1, String target2)
{
MenuEntry entry1 = findOptionTarget(getMenuStream(client), Text.standardize(option1), Text.standardize(target1));
MenuEntry entry2 = findOptionTarget(getMenuStream(client), Text.standardize(option2), Text.standardize(target2));
if (entry1 != null && entry2 != null)
{
swap(client, entry1, entry2);
}
}
private static void swapNotStrict(Client client, String option1, String option2, String target1, String target2)
{
MenuEntry entry1 = findOptionTargetLenient(getMenuStream(client), Text.standardize(option1), Text.standardize(target1));
MenuEntry entry2 = findOptionTargetLenient(getMenuStream(client), Text.standardize(option2), Text.standardize(target2));
if (entry1 != null && entry2 != null)
{
swap(client, entry1, entry2);
}
}
public static void swap(Client client, String option1, String option2, String targetforboth)
{
swap(client, option1, option2, targetforboth, targetforboth);
}
public static void swap(Client client, String option1, String option2, String targetforboth, boolean strict)
{
if (strict)
{
swap(client, option1, option2, targetforboth, targetforboth);
}
else
{
swapNotStrict(client, option1, option2, targetforboth, targetforboth);
}
}
private static MenuEntry findOptionTarget(Stream<MenuEntry> stream, String option, String target)
{
Optional<MenuEntry> maybeEntry = stream.filter(e -> Text.standardize(e.getOption()).equals(option) &&
Text.standardize(e.getTarget()).equals(target))
/* autism */ .findFirst();
return maybeEntry.orElse(null);
}
private static MenuEntry findOptionTargetLenient(Stream<MenuEntry> stream, String option, String target)
{
Optional<MenuEntry> maybeEntry = stream.filter(e -> Text.standardize(e.getOption()).contains(option) &&
Text.standardize(e.getTarget()).contains(target))
/* autism */ .findFirst();
return maybeEntry.orElse(null);
}
private static Stream<MenuEntry> getMenuStream(Client client)
{
List<MenuEntry> entries = Arrays.asList(client.getMenuEntries());
return Lists.reverse(entries).stream();
}
}