Merge pull request #1619 from Lucwousin/menu-entry-oh-no-withdraw-buy-sell-yes

MenuEntrySwapper: Cleanup/fixes (buy/sell/withdraw/tan/planks/removed/misc)
This commit is contained in:
Owain van Brakel
2019-09-21 14:21:02 +02:00
committed by GitHub
14 changed files with 509 additions and 290 deletions

View File

@@ -28,7 +28,6 @@ import lombok.AccessLevel;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.Setter;
import net.runelite.api.util.Text;
/**
* A menu entry in a right-click menu.
@@ -83,7 +82,6 @@ public class MenuEntry
this.param0 = param0;
this.param1 = param1;
this.forceLeftClick = forceLeftClick;
this.standardizedTarget = Text.standardize(target, true);
}
public static MenuEntry copy(MenuEntry src)
@@ -102,8 +100,5 @@ public class MenuEntry
public void setTarget(String target)
{
this.target = target;
this.standardizedTarget = Text.standardize(target, true);
}
private String standardizedTarget;
}

View File

@@ -686,7 +686,9 @@ public enum Varbits
/**
* 1 is true, 0 is false.
*/
GAUNTLET_ENTERED(9178);
GAUNTLET_ENTERED(9178),
WITHDRAW_X_AMOUNT(3960);
/**
* The raw varbit ID.

View File

@@ -42,7 +42,7 @@ public class BaseComparableEntry extends AbstractComparableEntry
public BaseComparableEntry(String option, String target, int id, int type, boolean strictOption, boolean strictTarget)
{
super.option = Text.standardize(option);
super.option = option.trim().toLowerCase();
super.target = Text.standardize(target);
super.id = id;
super.type = type;
@@ -61,7 +61,7 @@ public class BaseComparableEntry extends AbstractComparableEntry
if (strictTarget || !Strings.isNullOrEmpty(target))
{
String tgt = entry.getStandardizedTarget();
String tgt = Text.standardize(entry.getTarget(), true);
if (strictTarget && !tgt.equals(target) || !strictTarget && !tgt.contains(target))
{

View File

@@ -1,7 +1,7 @@
package net.runelite.client.menus;
import net.runelite.api.Client;
import net.runelite.client.plugins.menuentryswapper.BankComparableEntry;
import net.runelite.client.plugins.menuentryswapper.comparables.BankComparableEntry;
public interface ComparableEntries
{

View File

@@ -460,11 +460,7 @@ public class MenuManager
}
}
String target = event.getTarget();
// removes tags and level from player names for example:
// <col=ffffff>username<col=40ff00> (level-42) or <col=ffffff><img=2>username</col>
String username = Text.removeTags(target).split("[(]")[0].trim();
String username = Text.removeTags(event.getTarget(), true);
PlayerMenuOptionClicked playerMenuOptionClicked = new PlayerMenuOptionClicked();
playerMenuOptionClicked.setMenuOption(event.getOption());
@@ -509,7 +505,7 @@ public class MenuManager
*/
public AbstractComparableEntry addPriorityEntry(String option, String target)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
target = Text.standardize(target);
AbstractComparableEntry entry = newBaseComparableEntry(option, target);
@@ -521,7 +517,7 @@ public class MenuManager
public void removePriorityEntry(String option, String target)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
target = Text.standardize(target);
AbstractComparableEntry entry = newBaseComparableEntry(option, target);
@@ -536,7 +532,7 @@ public class MenuManager
*/
public AbstractComparableEntry addPriorityEntry(String option)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
AbstractComparableEntry entry = newBaseComparableEntry(option, "", false);
@@ -547,7 +543,7 @@ public class MenuManager
public AbstractComparableEntry addPriorityEntry(String option, boolean strictOption)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
AbstractComparableEntry entry =
newBaseComparableEntry(option, "", -1, -1, false, strictOption);
@@ -571,7 +567,7 @@ public class MenuManager
public void removePriorityEntry(String option)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
AbstractComparableEntry entry = newBaseComparableEntry(option, "", false);
@@ -580,7 +576,7 @@ public class MenuManager
public void removePriorityEntry(String option, boolean strictOption)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
AbstractComparableEntry entry =
newBaseComparableEntry(option, "", -1, -1, false, strictOption);
@@ -606,10 +602,10 @@ public class MenuManager
*/
public void addSwap(String option, String target, String option2, String target2, boolean strictOption, boolean strictTarget)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
target = Text.standardize(target);
option2 = Text.standardize(option2);
option2 = option2.trim().toLowerCase();
target2 = Text.standardize(target2);
AbstractComparableEntry swapFrom = newBaseComparableEntry(option, target, -1, -1, strictOption, strictTarget);
@@ -627,10 +623,10 @@ public class MenuManager
public void removeSwap(String option, String target, String option2, String target2, boolean strictOption, boolean strictTarget)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
target = Text.standardize(target);
option2 = Text.standardize(option2);
option2 = option2.trim().toLowerCase();
target2 = Text.standardize(target2);
AbstractComparableEntry swapFrom = newBaseComparableEntry(option, target, -1, -1, strictOption, strictTarget);
@@ -672,10 +668,10 @@ public class MenuManager
*/
public void addSwap(String option, String target, int id, int type, String option2, String target2, int id2, int type2)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
target = Text.standardize(target);
option2 = Text.standardize(option2);
option2 = option2.trim().toLowerCase();
target2 = Text.standardize(target2);
AbstractComparableEntry swapFrom = newBaseComparableEntry(option, target, id, type, false, false);
@@ -692,10 +688,10 @@ public class MenuManager
public void removeSwap(String option, String target, int id, int type, String option2, String target2, int id2, int type2)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
target = Text.standardize(target);
option2 = Text.standardize(option2);
option2 = option2.trim().toLowerCase();
target2 = Text.standardize(target2);
AbstractComparableEntry swapFrom = newBaseComparableEntry(option, target, id, type, false, false);
@@ -724,7 +720,7 @@ public class MenuManager
*/
public void addHiddenEntry(String option, String target)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
target = Text.standardize(target);
AbstractComparableEntry entry = newBaseComparableEntry(option, target);
@@ -734,7 +730,7 @@ public class MenuManager
public void removeHiddenEntry(String option, String target)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
target = Text.standardize(target);
AbstractComparableEntry entry = newBaseComparableEntry(option, target);
@@ -748,7 +744,7 @@ public class MenuManager
*/
public void addHiddenEntry(String option)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
AbstractComparableEntry entry = newBaseComparableEntry(option, "", false);
@@ -757,7 +753,7 @@ public class MenuManager
public void removeHiddenEntry(String option)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
AbstractComparableEntry entry = newBaseComparableEntry(option, "", false);
@@ -769,7 +765,7 @@ public class MenuManager
*/
public void addHiddenEntry(String option, String target, boolean strictOption, boolean strictTarget)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
target = Text.standardize(target);
AbstractComparableEntry entry = newBaseComparableEntry(option, target, -1, -1, strictOption, strictTarget);
@@ -779,7 +775,7 @@ public class MenuManager
public void removeHiddenEntry(String option, String target, boolean strictOption, boolean strictTarget)
{
option = Text.standardize(option);
option = option.trim().toLowerCase();
target = Text.standardize(target);
AbstractComparableEntry entry = newBaseComparableEntry(option, target, -1, -1, strictOption, strictTarget);

View File

@@ -38,6 +38,7 @@ import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.util.Text;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.EventBus;
import net.runelite.client.menus.AbstractComparableEntry;
@@ -181,7 +182,7 @@ public class BlackjackPlugin extends Plugin
public boolean matches(MenuEntry entry)
{
return
entry.getStandardizedTarget().equals(this.getTarget()) &&
Text.removeTags(entry.getTarget(), true).equalsIgnoreCase(this.getTarget()) &&
entry.getOption().equalsIgnoreCase(this.getOption());
}
}

View File

@@ -263,20 +263,6 @@ public interface MenuEntrySwapperConfig extends Config
return false;
}
@ConfigItem(
keyName = "withdrawXAmount",
name = "Amount",
description = "",
position = 7,
section = "bankingSection",
hidden = true,
unhide = "withdrawX"
)
default String getWithdrawXAmount()
{
return "";
}
@ConfigItem(
keyName = "withdrawXItems",
name = "Items",

View File

@@ -58,6 +58,7 @@ import net.runelite.api.NPC;
import net.runelite.api.Player;
import net.runelite.api.Varbits;
import static net.runelite.api.Varbits.BUILDING_MODE;
import static net.runelite.api.Varbits.WITHDRAW_X_AMOUNT;
import net.runelite.api.WorldType;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.ClientTick;
@@ -82,6 +83,11 @@ import net.runelite.client.plugins.PluginDependency;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.PluginManager;
import net.runelite.client.plugins.PluginType;
import net.runelite.client.plugins.menuentryswapper.comparables.BankComparableEntry;
import net.runelite.client.plugins.menuentryswapper.comparables.EquipmentComparableEntry;
import net.runelite.client.plugins.menuentryswapper.comparables.InventoryComparableEntry;
import net.runelite.client.plugins.menuentryswapper.comparables.ShopComparableEntry;
import net.runelite.client.plugins.menuentryswapper.comparables.WithdrawComparableEntry;
import net.runelite.client.plugins.menuentryswapper.util.BurningAmuletMode;
import net.runelite.client.plugins.menuentryswapper.util.CharterOption;
import net.runelite.client.plugins.menuentryswapper.util.CombatBraceletMode;
@@ -108,8 +114,6 @@ import net.runelite.client.plugins.pvptools.PvpToolsConfig;
import net.runelite.client.plugins.pvptools.PvpToolsPlugin;
import net.runelite.client.util.HotkeyListener;
import static net.runelite.client.util.MenuUtil.swap;
import net.runelite.client.util.MiscUtils;
import org.apache.commons.lang3.StringUtils;
@PluginDescriptor(
name = "Menu Entry Swapper",
@@ -122,7 +126,6 @@ import org.apache.commons.lang3.StringUtils;
@PluginDependency(PvpToolsPlugin.class)
public class MenuEntrySwapperPlugin extends Plugin
{
private static final String CONFIG_GROUP = "shiftclick";
private static final String HOTKEY = "menuentryswapper hotkey";
private static final String CONTROL = "menuentryswapper control";
private static final String HOTKEY_CHECK = "menuentryswapper hotkey check";
@@ -171,6 +174,15 @@ public class MenuEntrySwapperPlugin extends Plugin
private final Map<AbstractComparableEntry, Integer> customSwaps = new HashMap<>();
private final Map<AbstractComparableEntry, Integer> customShiftSwaps = new HashMap<>();
private final Map<AbstractComparableEntry, AbstractComparableEntry> dePrioSwaps = new HashMap<>();
// 1, 5, 10, 50
private final AbstractComparableEntry[][] buyEntries = new AbstractComparableEntry[4][];
private final AbstractComparableEntry[][] sellEntries = new AbstractComparableEntry[4][];
// 1, 5, 10, X, All
private final AbstractComparableEntry[][] withdrawEntries = new AbstractComparableEntry[5][];
private String[] removedObjects;
private List<String> bankItemNames = new ArrayList<>();
private BurningAmuletMode getBurningAmuletMode;
private CharterOption charterOption;
@@ -198,21 +210,6 @@ public class MenuEntrySwapperPlugin extends Plugin
private SlayerRingMode getSlayerRingMode;
private String configCustomShiftSwaps;
private String configCustomSwaps;
private String getBuyFiftyItems;
private String getBuyFiveItems;
private String getBuyOneItems;
private String getBuyTenItems;
private String getRemovedObjects;
private String getSellFiftyItems;
private String getSellFiveItems;
private String getSellOneItems;
private String getSellTenItems;
private String getWithdrawAllItems;
private String getWithdrawFiveItems;
private String getWithdrawOneItems;
private String getWithdrawTenItems;
private String getWithdrawXAmount;
private String getWithdrawXItems;
private XericsTalismanMode getXericsTalismanMode;
private boolean getBurningAmulet;
private boolean getCombatBracelet;
@@ -222,15 +219,10 @@ public class MenuEntrySwapperPlugin extends Plugin
private boolean getGamesNecklace;
private boolean getGlory;
private boolean getNecklaceofPassage;
private boolean getRemoveObjects;
private boolean getRingofWealth;
private boolean getSkillsNecklace;
private boolean getSlayerRing;
private boolean getSwapArdougneCape;
private boolean getSwapBuyFifty;
private boolean getSwapBuyFive;
private boolean getSwapBuyOne;
private boolean getSwapBuyTen;
private boolean getSwapConstructionCape;
private boolean getSwapCraftingCape;
private boolean getSwapExplorersRing;
@@ -238,16 +230,7 @@ public class MenuEntrySwapperPlugin extends Plugin
private boolean getSwapPuro;
private boolean getSwapSawmill;
private boolean getSwapSawmillPlanks;
private boolean getSwapSellFifty;
private boolean getSwapSellFive;
private boolean getSwapSellOne;
private boolean getSwapSellTen;
private boolean getSwapTanning;
private boolean getWithdrawAll;
private boolean getWithdrawFive;
private boolean getWithdrawOne;
private boolean getWithdrawTen;
private boolean getWithdrawX;
private boolean getXericsTalisman;
private boolean hideBait;
private boolean hideCastCoX;
@@ -316,6 +299,15 @@ public class MenuEntrySwapperPlugin extends Plugin
addSwaps();
loadConstructionItems();
loadCustomSwaps(config.customSwaps(), customSwaps);
updateBuySellEntries();
addBuySellEntries();
updateWithdrawEntries();
addWithdrawEntries();
updateRemovedObjects();
keyManager.registerKeyListener(ctrlHotkey);
keyManager.registerKeyListener(hotkey);
if (client.getGameState() == GameState.LOGGED_IN)
@@ -331,6 +323,11 @@ public class MenuEntrySwapperPlugin extends Plugin
loadCustomSwaps("", customSwaps); // Removes all custom swaps
removeSwaps();
removeBuySellEntries();
removeWithdrawEntries();
removedObjects = null;
keyManager.unregisterKeyListener(ctrlHotkey);
keyManager.unregisterKeyListener(hotkey);
if (client.getGameState() == GameState.LOGGED_IN)
@@ -370,42 +367,57 @@ public class MenuEntrySwapperPlugin extends Plugin
addSwaps();
loadConstructionItems();
if (!CONFIG_GROUP.equals(event.getGroup()))
switch (event.getKey())
{
if (event.getKey().equals("customSwaps"))
{
case "customSwaps":
loadCustomSwaps(this.configCustomSwaps, customSwaps);
}
return;
case "hideCastToB":
case "hideCastIgnoredToB":
if (this.hideCastToB)
{
setCastOptions(true);
}
else
{
resetCastOptions();
}
return;
case "hideCastCoX":
case "hideCastIgnoredCoX":
if (this.hideCastCoX)
{
setCastOptions(true);
}
else
{
resetCastOptions();
}
return;
case "removeObjects":
case "removedObjects":
updateRemovedObjects();
return;
}
else if ((event.getKey().equals("hideCastToB") || event.getKey().equals("hideCastIgnoredToB")))
if (event.getKey().startsWith("swapSell") || event.getKey().startsWith("swapBuy") ||
(event.getKey().startsWith("sell") || event.getKey().startsWith("buy")) && event.getKey().endsWith("Items"))
{
if (this.hideCastToB)
{
setCastOptions(true);
}
else
{
resetCastOptions();
}
removeBuySellEntries();
updateBuySellEntries();
addBuySellEntries();
}
else if ((event.getKey().equals("hideCastCoX") || event.getKey().equals("hideCastIgnoredCoX")))
else if (event.getKey().startsWith("withdraw") || event.getKey().startsWith("deposit"))
{
if (this.hideCastCoX)
{
setCastOptions(true);
}
else
{
resetCastOptions();
}
removeWithdrawEntries();
updateWithdrawEntries();
addWithdrawEntries();
}
}
private void onGameStateChanged(GameStateChanged event)
{
if (client.getGameState() != GameState.LOGGED_IN)
if (event.getGameState() != GameState.LOGGED_IN)
{
return;
}
@@ -416,6 +428,7 @@ public class MenuEntrySwapperPlugin extends Plugin
private void onVarbitChanged(VarbitChanged event)
{
buildingMode = client.getVar(BUILDING_MODE) == 1;
WithdrawComparableEntry.setX(client.getVar(WITHDRAW_X_AMOUNT));
setCastOptions(false);
}
@@ -429,12 +442,6 @@ public class MenuEntrySwapperPlugin extends Plugin
return;
}
// TODO: Remove this? This makes everything here only work in wildy lol
if (!(MiscUtils.getWildernessLevelFrom(client, localPlayer.getWorldLocation()) >= 0))
{
return;
}
List<MenuEntry> menu_entries = new ArrayList<>();
for (MenuEntry entry : event.getMenuEntries())
@@ -527,30 +534,19 @@ public class MenuEntrySwapperPlugin extends Plugin
final int eventId = event.getIdentifier();
final String option = event.getOption().toLowerCase();
final String target = event.getMenuEntry().getStandardizedTarget();
final String target = Text.standardize(event.getTarget(), true);
final NPC hintArrowNpc = client.getHintArrowNpc();
if (this.getRemoveObjects && !this.getRemovedObjects.equals(""))
if (removedObjects != null)
{
// TODO: CACHE THIS
for (String removed : Text.fromCSV(this.getRemovedObjects))
final boolean hasArrow = target.contains("->");
final int targetLength = target.length();
for (final String object : removedObjects)
{
removed = Text.standardize(removed);
if (target.equals(removed))
{
client.setMenuOptionCount(client.getMenuOptionCount() - 1);
return;
}
else if (target.contains("->"))
{
String trimmed = target.split("->")[1].trim();
if (trimmed.length() >= removed.length() && trimmed.substring(0, removed.length()).equalsIgnoreCase(removed))
{
client.setMenuOptionCount(client.getMenuOptionCount() - 1);
return;
}
}
else if (target.length() >= removed.length() && StringUtils.startsWithIgnoreCase(target, removed))
if (target.equals(object)
|| hasArrow && target.endsWith(object)
|| targetLength > object.length() && target.startsWith(object))
{
client.setMenuOptionCount(client.getMenuOptionCount() - 1);
return;
@@ -758,94 +754,9 @@ public class MenuEntrySwapperPlugin extends Plugin
menuManager.addSwap(a, b);
}
if (this.getWithdrawOne)
{
Text.fromCSV(this.getWithdrawOneItems).forEach(item ->
{
menuManager.addPriorityEntry(newBankComparableEntry("Withdraw-1", item)).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Deposit-1", item)).setPriority(10);
});
}
if (this.getWithdrawFive)
{
Text.fromCSV(this.getWithdrawFiveItems).forEach(item ->
{
menuManager.addPriorityEntry(newBankComparableEntry("Withdraw-5", item)).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Deposit-5", item)).setPriority(10);
});
}
if (this.getWithdrawTen)
{
Text.fromCSV(this.getWithdrawTenItems).forEach(item ->
{
menuManager.addPriorityEntry(newBankComparableEntry("Withdraw-10", item)).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Deposit-10", item)).setPriority(10);
});
}
if (this.getWithdrawX)
{
Text.fromCSV(this.getWithdrawXItems).forEach(item ->
{
menuManager.addPriorityEntry(newBankComparableEntry("Withdraw-" + this.getWithdrawXAmount, item)).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Deposit-" + this.getWithdrawXAmount, item)).setPriority(10);
});
}
if (this.getWithdrawAll)
{
Text.fromCSV(this.getWithdrawAllItems).forEach(item ->
{
menuManager.addPriorityEntry(newBankComparableEntry("Withdraw-All", item)).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Deposit-All", item)).setPriority(10);
});
}
if (this.getSwapBuyOne)
{
Text.fromCSV(this.getBuyOneItems).forEach(item -> menuManager.addPriorityEntry("Buy 1", item).setPriority(100));
}
if (this.getSwapBuyFive)
{
Text.fromCSV(this.getBuyFiveItems).forEach(item -> menuManager.addPriorityEntry("Buy 5", item).setPriority(100));
}
if (this.getSwapBuyTen)
{
Text.fromCSV(this.getBuyTenItems).forEach(item -> menuManager.addPriorityEntry("Buy 10", item).setPriority(100));
}
if (this.getSwapBuyFifty)
{
Text.fromCSV(this.getBuyFiftyItems).forEach(item -> menuManager.addPriorityEntry("Buy 50", item).setPriority(100));
}
if (this.getSwapSellOne)
{
Text.fromCSV(this.getSellOneItems).forEach(item -> menuManager.addPriorityEntry("Sell 1", item).setPriority(100));
}
if (this.getSwapSellFive)
{
Text.fromCSV(this.getSellFiveItems).forEach(item -> menuManager.addPriorityEntry("Sell 5", item).setPriority(100));
}
if (this.getSwapSellTen)
{
Text.fromCSV(this.getSellTenItems).forEach(item -> menuManager.addPriorityEntry("Sell 10", item).setPriority(100));
}
if (this.getSwapSellFifty)
{
Text.fromCSV(this.getSellFiftyItems).forEach(item -> menuManager.addPriorityEntry("Sell 50", item).setPriority(100));
}
if (this.getSwapTanning)
{
menuManager.addPriorityEntry("Tan All");
menuManager.addPriorityEntry("Tan <col=ff7000>All");
}
if (this.getSwapSawmill)
@@ -856,7 +767,7 @@ public class MenuEntrySwapperPlugin extends Plugin
if (this.getSwapSawmillPlanks)
{
//Not much we can do for this one, Buy all is the only thing, there is no target.
menuManager.addPriorityEntry("Buy All").setPriority(10);
menuManager.addPriorityEntry("Buy <col=ff7000>All").setPriority(10);
}
if (this.getSwapArdougneCape)
@@ -1250,43 +1161,11 @@ public class MenuEntrySwapperPlugin extends Plugin
menuManager.removeSwap(e.getKey(), e.getValue());
dePrioIter.remove();
});
Text.fromCSV(this.getWithdrawOneItems).forEach(item ->
{
menuManager.removePriorityEntry(newBankComparableEntry("Withdraw-1", item));
menuManager.removePriorityEntry(newBankComparableEntry("Deposit-1", item));
});
Text.fromCSV(this.getWithdrawFiveItems).forEach(item ->
{
menuManager.removePriorityEntry(newBankComparableEntry("Withdraw-5", item));
menuManager.removePriorityEntry(newBankComparableEntry("Deposit-5", item));
});
Text.fromCSV(this.getWithdrawTenItems).forEach(item ->
{
menuManager.removePriorityEntry(newBankComparableEntry("Withdraw-10", item));
menuManager.removePriorityEntry(newBankComparableEntry("Deposit-10", item));
});
Text.fromCSV(this.getWithdrawXItems).forEach(item ->
{
menuManager.removePriorityEntry(newBankComparableEntry("Withdraw-" + this.getWithdrawXAmount, item));
menuManager.removePriorityEntry(newBankComparableEntry("Deposit-" + this.getWithdrawXAmount, item));
});
Text.fromCSV(this.getWithdrawAllItems).forEach(item ->
{
menuManager.removePriorityEntry(newBankComparableEntry("Withdraw-All", item));
menuManager.removePriorityEntry(newBankComparableEntry("Deposit-All", item));
});
Text.fromCSV(this.getBuyOneItems).forEach(item -> menuManager.removePriorityEntry("Buy 1", item));
Text.fromCSV(this.getBuyFiveItems).forEach(item -> menuManager.removePriorityEntry("Buy 5", item));
Text.fromCSV(this.getBuyTenItems).forEach(item -> menuManager.removePriorityEntry("Buy 10", item));
Text.fromCSV(this.getBuyFiftyItems).forEach(item -> menuManager.removePriorityEntry("Buy 50", item));
Text.fromCSV(this.getSellOneItems).forEach(item -> menuManager.removePriorityEntry("Sell 1", item));
Text.fromCSV(this.getSellFiveItems).forEach(item -> menuManager.removePriorityEntry("Sell 5", item));
Text.fromCSV(this.getSellTenItems).forEach(item -> menuManager.removePriorityEntry("Sell 10", item));
Text.fromCSV(this.getSellFiftyItems).forEach(item -> menuManager.removePriorityEntry("Sell 50", item));
menuManager.removePriorityEntry("Activate", "Box trap");
menuManager.removePriorityEntry("Assignment");
menuManager.removePriorityEntry("Bank");
menuManager.removePriorityEntry("Buy All");
menuManager.removePriorityEntry("Buy <col=ff7000>All");
menuManager.removePriorityEntry("Buy-plank");
menuManager.removePriorityEntry("Buy-plank", "Sawmill operator");
menuManager.removePriorityEntry("Charter");
@@ -1352,7 +1231,7 @@ public class MenuEntrySwapperPlugin extends Plugin
menuManager.removePriorityEntry("Story");
menuManager.removePriorityEntry("Stun", "Hoop snake");
menuManager.removePriorityEntry("Take-boat");
menuManager.removePriorityEntry("Tan All");
menuManager.removePriorityEntry("Tan <col=ff7000>All");
menuManager.removePriorityEntry("Teleport menu", "Portal nexus");
menuManager.removePriorityEntry("Teleport", "Crafting cape");
menuManager.removePriorityEntry("Teleport", "Crafting cape(t)");
@@ -1660,10 +1539,6 @@ public class MenuEntrySwapperPlugin extends Plugin
this.constructionCapeMode = config.constructionCapeMode();
this.getBurningAmulet = config.getBurningAmulet();
this.getBurningAmuletMode = config.getBurningAmuletMode();
this.getBuyFiftyItems = config.getBuyFiftyItems();
this.getBuyFiveItems = config.getBuyFiveItems();
this.getBuyOneItems = config.getBuyOneItems();
this.getBuyTenItems = config.getBuyTenItems();
this.getCombatBracelet = config.getCombatBracelet();
this.getCombatBraceletMode = config.getCombatBraceletMode();
this.getConstructionMode = config.getConstructionMode();
@@ -1678,23 +1553,13 @@ public class MenuEntrySwapperPlugin extends Plugin
this.getGloryMode = config.getGloryMode();
this.getNecklaceofPassage = config.getNecklaceofPassage();
this.getNecklaceofPassageMode = config.getNecklaceofPassageMode();
this.getRemoveObjects = config.getRemoveObjects();
this.getRemovedObjects = config.getRemovedObjects();
this.getRingofWealth = config.getRingofWealth();
this.getRingofWealthMode = config.getRingofWealthMode();
this.getSellFiftyItems = config.getSellFiftyItems();
this.getSellFiveItems = config.getSellFiveItems();
this.getSellOneItems = config.getSellOneItems();
this.getSellTenItems = config.getSellTenItems();
this.getSkillsNecklace = config.getSkillsNecklace();
this.getSkillsNecklaceMode = config.getSkillsNecklaceMode();
this.getSlayerRing = config.getSlayerRing();
this.getSlayerRingMode = config.getSlayerRingMode();
this.getSwapArdougneCape = config.getSwapArdougneCape();
this.getSwapBuyFifty = config.getSwapBuyFifty();
this.getSwapBuyFive = config.getSwapBuyFive();
this.getSwapBuyOne = config.getSwapBuyOne();
this.getSwapBuyTen = config.getSwapBuyTen();
this.getSwapConstructionCape = config.getSwapConstructionCape();
this.getSwapCraftingCape = config.getSwapCraftingCape();
this.getSwapExplorersRing = config.getSwapExplorersRing();
@@ -1702,22 +1567,7 @@ public class MenuEntrySwapperPlugin extends Plugin
this.getSwapPuro = config.getSwapPuro();
this.getSwapSawmill = config.getSwapSawmill();
this.getSwapSawmillPlanks = config.getSwapSawmillPlanks();
this.getSwapSellFifty = config.getSwapSellFifty();
this.getSwapSellFive = config.getSwapSellFive();
this.getSwapSellOne = config.getSwapSellOne();
this.getSwapSellTen = config.getSwapSellTen();
this.getSwapTanning = config.getSwapTanning();
this.getWithdrawAll = config.getWithdrawAll();
this.getWithdrawAllItems = config.getWithdrawAllItems();
this.getWithdrawFive = config.getWithdrawFive();
this.getWithdrawFiveItems = config.getWithdrawFiveItems();
this.getWithdrawOne = config.getWithdrawOne();
this.getWithdrawOneItems = config.getWithdrawOneItems();
this.getWithdrawTen = config.getWithdrawTen();
this.getWithdrawTenItems = config.getWithdrawTenItems();
this.getWithdrawX = config.getWithdrawX();
this.getWithdrawXAmount = config.getWithdrawXAmount();
this.getWithdrawXItems = config.getWithdrawXItems();
this.getXericsTalisman = config.getXericsTalisman();
this.getXericsTalismanMode = config.getXericsTalismanMode();
this.hideBait = config.hideBait();
@@ -1784,6 +1634,259 @@ public class MenuEntrySwapperPlugin extends Plugin
this.swapHouseAdMode = config.swapHouseAdMode();
}
private void addBuySellEntries()
{
for (int i = 0; i < 4; i++)
{
if (buyEntries[i] != null)
{
for (AbstractComparableEntry entry : buyEntries[i])
{
menuManager.addPriorityEntry(entry);
}
}
if (sellEntries[i] != null)
{
for (AbstractComparableEntry entry : sellEntries[i])
{
menuManager.addPriorityEntry(entry);
}
}
}
}
private void removeBuySellEntries()
{
for (int i = 0; i < 4; i++)
{
if (buyEntries[i] != null)
{
for (AbstractComparableEntry entry : buyEntries[i])
{
menuManager.removePriorityEntry(entry);
}
}
if (sellEntries[i] != null)
{
for (AbstractComparableEntry entry : sellEntries[i])
{
menuManager.removePriorityEntry(entry);
}
}
}
}
/**
* Fills the buy/sell entry arrays
*/
private void updateBuySellEntries()
{
List<String> tmp;
if (config.getSwapBuyOne())
{
tmp = Text.fromCSV(config.getBuyOneItems());
buyEntries[0] = new AbstractComparableEntry[tmp.size()];
ShopComparableEntry.populateArray(buyEntries[0], tmp, true, 1);
}
else
{
buyEntries[0] = null;
}
if (config.getSwapBuyFive())
{
tmp = Text.fromCSV(config.getBuyFiveItems());
buyEntries[1] = new AbstractComparableEntry[tmp.size()];
ShopComparableEntry.populateArray(buyEntries[1], tmp, true, 5);
}
else
{
buyEntries[1] = null;
}
if (config.getSwapBuyTen())
{
tmp = Text.fromCSV(config.getBuyTenItems());
buyEntries[2] = new AbstractComparableEntry[tmp.size()];
ShopComparableEntry.populateArray(buyEntries[2], tmp, true, 10);
}
else
{
buyEntries[2] = null;
}
if (config.getSwapBuyFifty())
{
tmp = Text.fromCSV(config.getBuyFiftyItems());
buyEntries[3] = new AbstractComparableEntry[tmp.size()];
ShopComparableEntry.populateArray(buyEntries[3], tmp, true, 50);
}
else
{
buyEntries[3] = null;
}
if (config.getSwapSellOne())
{
tmp = Text.fromCSV(config.getSellOneItems());
sellEntries[0] = new AbstractComparableEntry[tmp.size()];
ShopComparableEntry.populateArray(sellEntries[0], tmp, false, 1);
}
else
{
sellEntries[0] = null;
}
if (config.getSwapSellFive())
{
tmp = Text.fromCSV(config.getSellFiveItems());
sellEntries[1] = new AbstractComparableEntry[tmp.size()];
ShopComparableEntry.populateArray(sellEntries[1], tmp, false, 5);
}
else
{
sellEntries[1] = null;
}
if (config.getSwapSellTen())
{
tmp = Text.fromCSV(config.getSellTenItems());
sellEntries[2] = new AbstractComparableEntry[tmp.size()];
ShopComparableEntry.populateArray(sellEntries[2], tmp, false, 10);
}
else
{
sellEntries[2] = null;
}
if (config.getSwapSellFifty())
{
tmp = Text.fromCSV(config.getSellFiftyItems());
sellEntries[3] = new AbstractComparableEntry[tmp.size()];
ShopComparableEntry.populateArray(sellEntries[3], tmp, false, 50);
}
else
{
sellEntries[3] = null;
}
}
private void addWithdrawEntries()
{
for (int i = 0; i < 5; i++)
{
if (withdrawEntries[i] != null)
{
for (AbstractComparableEntry entry : withdrawEntries[i])
{
menuManager.addPriorityEntry(entry);
}
}
}
}
private void removeWithdrawEntries()
{
for (int i = 0; i < 5; i++)
{
if (withdrawEntries[i] != null)
{
for (AbstractComparableEntry entry : withdrawEntries[i])
{
menuManager.removePriorityEntry(entry);
}
}
}
}
private void updateWithdrawEntries()
{
List<String> tmp;
if (config.getWithdrawOne())
{
tmp = Text.fromCSV(config.getWithdrawOneItems());
withdrawEntries[0] = new AbstractComparableEntry[tmp.size()];
WithdrawComparableEntry.populateArray(withdrawEntries[0], tmp, WithdrawComparableEntry.Amount.ONE);
}
else
{
withdrawEntries[0] = null;
}
if (config.getWithdrawFive())
{
tmp = Text.fromCSV(config.getWithdrawFiveItems());
withdrawEntries[1] = new AbstractComparableEntry[tmp.size()];
WithdrawComparableEntry.populateArray(withdrawEntries[1], tmp, WithdrawComparableEntry.Amount.FIVE);
}
else
{
withdrawEntries[1] = null;
}
if (config.getWithdrawTen())
{
tmp = Text.fromCSV(config.getWithdrawTenItems());
withdrawEntries[2] = new AbstractComparableEntry[tmp.size()];
WithdrawComparableEntry.populateArray(withdrawEntries[2], tmp, WithdrawComparableEntry.Amount.TEN);
}
else
{
withdrawEntries[2] = null;
}
if (config.getWithdrawX())
{
tmp = Text.fromCSV(config.getWithdrawXItems());
withdrawEntries[3] = new AbstractComparableEntry[tmp.size()];
WithdrawComparableEntry.populateArray(withdrawEntries[3], tmp, WithdrawComparableEntry.Amount.X);
}
else
{
withdrawEntries[3] = null;
}
if (config.getWithdrawAll())
{
tmp = Text.fromCSV(config.getWithdrawAllItems());
withdrawEntries[4] = new AbstractComparableEntry[tmp.size()];
WithdrawComparableEntry.populateArray(withdrawEntries[4], tmp, WithdrawComparableEntry.Amount.ALL);
}
else
{
withdrawEntries[4] = null;
}
}
private void updateRemovedObjects()
{
if (config.getRemoveObjects())
{
removedObjects = Text.fromCSV(
Text.removeTags(config.getRemovedObjects().toLowerCase())
).toArray(new String[0]);
}
else
{
removedObjects = null;
}
}
/**
* Migrates old custom swaps config
* This should be removed after a reasonable amount of time.

View File

@@ -1,4 +1,4 @@
package net.runelite.client.plugins.menuentryswapper;
package net.runelite.client.plugins.menuentryswapper.comparables;
import lombok.EqualsAndHashCode;
import net.runelite.api.MenuEntry;
@@ -20,9 +20,7 @@ public class BankComparableEntry extends AbstractComparableEntry
public boolean matches(MenuEntry entry)
{
final int groupId = WidgetInfo.TO_GROUP(entry.getParam1());
if (groupId != WidgetID.BANK_GROUP_ID && groupId != WidgetID.BANK_INVENTORY_GROUP_ID && groupId != WidgetID.GRAND_EXCHANGE_GROUP_ID)
if (isNotBankWidget(entry.getParam1()))
{
return false;
}
@@ -34,4 +32,13 @@ public class BankComparableEntry extends AbstractComparableEntry
return StringUtils.containsIgnoreCase(entry.getOption(), this.getOption()) && Text.standardize(entry.getTarget()).contains(this.getTarget());
}
static boolean isNotBankWidget(int widgetID)
{
final int groupId = WidgetInfo.TO_GROUP(widgetID);
return groupId != WidgetID.BANK_GROUP_ID
&& groupId != WidgetID.BANK_INVENTORY_GROUP_ID
&& groupId != WidgetID.GRAND_EXCHANGE_GROUP_ID;
}
}

View File

@@ -1,4 +1,4 @@
package net.runelite.client.plugins.menuentryswapper;
package net.runelite.client.plugins.menuentryswapper.comparables;
import lombok.EqualsAndHashCode;
import net.runelite.api.MenuEntry;

View File

@@ -1,4 +1,4 @@
package net.runelite.client.plugins.menuentryswapper;
package net.runelite.client.plugins.menuentryswapper.comparables;
import lombok.EqualsAndHashCode;
import net.runelite.api.MenuEntry;

View File

@@ -0,0 +1,46 @@
package net.runelite.client.plugins.menuentryswapper.comparables;
import java.util.List;
import net.runelite.api.MenuEntry;
import net.runelite.api.util.Text;
import net.runelite.client.menus.AbstractComparableEntry;
public class ShopComparableEntry extends AbstractComparableEntry
{
private ShopComparableEntry(final boolean buy, final int amount, final String item)
{
assert amount == 1 || amount == 5 || amount == 10 || amount == 50 : "Only 1, 5, 10, or 50 are valid amounts";
this.setOption((buy ? "Buy " : "Sell ") + amount);
this.setTarget(Text.standardize(item));
}
@Override
public boolean matches(final MenuEntry entry)
{
return entry.getOption().equals(this.getOption()) && Text.standardize(entry.getTarget()).equals(this.getTarget());
}
@Override
public int getPriority()
{
return 100;
}
@Override
public boolean equals(Object other)
{
return other instanceof ShopComparableEntry && super.equals(other);
}
/**
* Fills the array with ShopComparableEntries, getting the items from the fed list
*/
public static void populateArray(final AbstractComparableEntry[] array, final List<String> items, final boolean buy, final int amount)
{
for (int i = 0; i < array.length; i++)
{
array[i] = new ShopComparableEntry(buy, amount, items.get(i));
}
}
}

View File

@@ -0,0 +1,83 @@
package net.runelite.client.plugins.menuentryswapper.comparables;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import net.runelite.api.MenuEntry;
import net.runelite.api.util.Text;
import net.runelite.client.menus.AbstractComparableEntry;
@EqualsAndHashCode(callSuper = true)
public class WithdrawComparableEntry extends AbstractComparableEntry
{
private static String x;
private final Amount amount;
private WithdrawComparableEntry(Amount amount, String item)
{
this.amount = amount;
this.setTarget(Text.standardize(item));
}
@Override
public boolean matches(MenuEntry entry)
{
if (BankComparableEntry.isNotBankWidget(entry.getParam1()))
{
return false;
}
final String option = entry.getOption();
if (!option.startsWith("Withdraw") && !option.startsWith("Deposit"))
{
return false;
}
if (amount == Amount.X)
{
if (!option.endsWith(x))
{
return false;
}
}
else if (!option.endsWith(amount.suffix))
{
return false;
}
return Text.standardize(entry.getTarget()).contains(this.getTarget());
}
@Override
public int getPriority()
{
return 10;
}
public static void setX(int amount)
{
x = String.valueOf(amount);
}
public static void populateArray(AbstractComparableEntry[] array, List<String> items, Amount amount)
{
for (int i = 0; i < array.length; i++)
{
array[i] = new WithdrawComparableEntry(amount, items.get(i));
}
}
@AllArgsConstructor
public enum Amount
{
ONE("1"),
FIVE("5"),
TEN("10"),
X(null),
ALL("All");
private String suffix;
}
}

View File

@@ -59,8 +59,8 @@ import static net.runelite.client.menus.ComparableEntries.newBaseComparableEntry
import net.runelite.client.menus.MenuManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.menuentryswapper.BankComparableEntry;
import net.runelite.client.plugins.menuentryswapper.EquipmentComparableEntry;
import net.runelite.client.plugins.menuentryswapper.comparables.BankComparableEntry;
import net.runelite.client.plugins.menuentryswapper.comparables.EquipmentComparableEntry;
import static net.runelite.client.plugins.runecraft.AbyssRifts.*;
import net.runelite.client.ui.overlay.OverlayManager;