Menus: Make comparable entries abstract for more specific .matc… (#1268)

Menus: Make comparable entries abstract for more specific .matches()'s
This commit is contained in:
Owain van Brakel
2019-08-05 19:36:27 +02:00
committed by GitHub
9 changed files with 444 additions and 250 deletions

View File

@@ -0,0 +1,29 @@
package net.runelite.client.menus;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import net.runelite.api.MenuEntry;
@Getter
@Setter
@EqualsAndHashCode
public abstract class AbstractComparableEntry
{
String option = null;
String target = null;
int id = -1;
int type = -1;
boolean strictOption = true;
boolean strictTarget = true;
@EqualsAndHashCode.Exclude
private int priority = 0;
public abstract boolean matches(MenuEntry entry);
}

View File

@@ -1,140 +1,94 @@
/*
* 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.menus;
import com.google.common.base.Strings;
import javax.annotation.Nonnull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import net.runelite.api.MenuEntry;
import static net.runelite.client.menus.MenuManager.LEVEL_PATTERN;
import net.runelite.client.util.Text;
@EqualsAndHashCode
public class ComparableEntry
{
@Getter
private String option;
@Getter
private String target;
@Getter
private int id;
@Getter
private int type;
@Getter
private boolean strictOption;
@Getter
private boolean strictTarget;
/**
* If two entries are both suppose to be left click,
* the entry with the higher priority will be selected.
* This only effects left click priority entries.
*/
@Getter
@Setter
@EqualsAndHashCode.Exclude
private int priority;
public ComparableEntry(String option, String target)
{
this(option, target, -1, -1, true, true);
}
public ComparableEntry(String option, String target, boolean strictTarget)
{
this(option, target, -1, -1, true, strictTarget);
}
public ComparableEntry(String option, String target, int id, int type, boolean strictOption, boolean strictTarget)
{
this.option = Text.standardize(option);
this.target = Text.standardize(target);
this.id = id;
this.type = type;
this.strictOption = strictOption;
this.strictTarget = strictTarget;
this.priority = 0;
}
// This is only used for type checking, which is why it has everything but target
// target sometimes changes to option.
public ComparableEntry(MenuEntry e)
{
this.option = Text.standardize(e.getOption());
this.id = e.getIdentifier();
this.type = e.getType();
this.strictOption = true;
this.priority = 0;
}
boolean matches(@Nonnull MenuEntry entry)
{
String opt = Text.standardize(entry.getOption());
if (strictOption && !opt.equals(option) || !strictOption && !opt.contains(option))
{
return false;
}
if (strictTarget || !Strings.isNullOrEmpty(target))
{
String tgt = Text.standardize(LEVEL_PATTERN.matcher(entry.getTarget()).replaceAll(""));
if (strictTarget && !tgt.equals(target) || !strictTarget && !tgt.contains(target))
{
return false;
}
}
if (id != -1)
{
int id = entry.getIdentifier();
if (this.id != id)
{
return false;
}
}
if (type != -1)
{
int type = entry.getType();
if (this.type != type)
{
return false;
}
}
return true;
}
}
/*
* 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.menus;
import javax.annotation.Nonnull;
import joptsimple.internal.Strings;
import lombok.EqualsAndHashCode;
import net.runelite.api.MenuEntry;
import static net.runelite.client.menus.MenuManager.LEVEL_PATTERN;
import net.runelite.client.util.Text;
@EqualsAndHashCode(callSuper = true)
public class BaseComparableEntry extends AbstractComparableEntry
{
/**
* If two entries are both suppose to be left click,
* the entry with the higher priority will be selected.
* This only effects left click priority entries.
*/
public BaseComparableEntry(String option, String target, int id, int type, boolean strictOption, boolean strictTarget)
{
super.option = Text.standardize(option);
super.target = Text.standardize(target);
super.id = id;
super.type = type;
super.strictOption = strictOption;
super.strictTarget = strictTarget;
}
public boolean matches(@Nonnull MenuEntry entry)
{
String opt = Text.standardize(entry.getOption());
if (strictOption && !opt.equals(option) || !strictOption && !opt.contains(option))
{
return false;
}
if (strictTarget || !Strings.isNullOrEmpty(target))
{
String tgt = Text.standardize(LEVEL_PATTERN.matcher(entry.getTarget()).replaceAll(""));
if (strictTarget && !tgt.equals(target) || !strictTarget && !tgt.contains(target))
{
return false;
}
}
if (id != -1)
{
int id = entry.getIdentifier();
if (this.id != id)
{
return false;
}
}
if (type != -1)
{
int type = entry.getType();
if (this.type != type)
{
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,76 @@
package net.runelite.client.menus;
import net.runelite.api.Client;
import net.runelite.client.plugins.menuentryswapper.BankComparableEntry;
public interface ComparableEntries
{
/**
* BaseComparableEntries should only be used if there's
* no better ComparableEntry available.
*
* @param option has to equal entry option
* @param target has to equal entry option
*
* @return a new BaseComparableEntry
*/
static BaseComparableEntry newBaseComparableEntry(String option, String target)
{
return new BaseComparableEntry(option, target, -1, -1, true, true);
}
/**
* BaseComparableEntries should only be used if there's
* no better ComparableEntry available.
*
* @param option has to equal option
* @param target equal or contains depending on strictTarget
* @param strictTarget read up one line
*
* @return a new BaseComparableEntry
*/
static BaseComparableEntry newBaseComparableEntry(String option, String target, boolean strictTarget)
{
return new BaseComparableEntry(option, target, -1, -1, true, strictTarget);
}
/**
* BaseComparableEntries should only be used if there's
* no better ComparableEntry available.
*
* @param option equal or contains depending on strictOption
* @param target equal or contains depending on strictTarget
* @param id has to be the same, or -1 to skip checking
* @param type has to be the same, or -1 to skip checking
* @param strictOption strict option or nah
* @param strictTarget strict target or nah
*
* @return a new BaseComparableEntry
*/
static BaseComparableEntry newBaseComparableEntry(String option, String target, int id, int type, boolean strictOption, boolean strictTarget)
{
return new BaseComparableEntry(option, target, id, type, strictOption, strictTarget);
}
/**
* This comparable finds all items with itemName
* in their name. It then checks the ItemDefinition
* for each of them, to see if it's possible for
* the item to have option as one of their options.
*
* This has to be ran on the clientthread!
*/
static ItemComparableEntry newInvItemComparableEntry(Client client, String option, String itemName)
{
return new ItemComparableEntry.InvItemComparableEntry(client, option, itemName);
}
/**
* This will only match items in the bank or in
* your inventory if the bank is open. Withdraw-x anyone?
*/
static BankComparableEntry newBankComparableEntry(String option, String itemName)
{
return new BankComparableEntry(option, itemName);
}
}

View File

@@ -0,0 +1,95 @@
package net.runelite.client.menus;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import net.runelite.api.Client;
import net.runelite.api.ItemDefinition;
import net.runelite.api.MenuEntry;
import net.runelite.client.util.Text;
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
abstract class ItemComparableEntry extends AbstractComparableEntry
{
@EqualsAndHashCode.Exclude
short[] itemIds;
@EqualsAndHashCode.Exclude
short itemCount;
public abstract boolean matches(MenuEntry entry);
@EqualsAndHashCode(callSuper = true)
static class InvItemComparableEntry extends ItemComparableEntry
{
public InvItemComparableEntry(Client client, String option, String itemName)
{
assert client.isClientThread() : "You can only create these on the clientthread";
this.target = Text.standardize(itemName);
this.option = Text.standardize(option);
short[] tmp = this.itemIds = new short[16];
final int itemCount = client.getItemCount();
short found = 0;
for (short i = 0; i < itemCount; i++)
{
ItemDefinition def = client.getItemDefinition(i);
if (def.getNote() != -1 || !def.getName().toLowerCase().contains(target))
{
continue;
}
boolean notValid = true;
for (String opt : def.getInventoryActions())
{
if (opt != null && Text.standardize(opt).contains(option))
{
notValid = false;
break;
}
}
if (notValid && !"use".equals(this.option))
{
continue;
}
if (found >= tmp.length)
{
short[] rlyTmp = new short[found * 2];
System.arraycopy(tmp, 0, rlyTmp, 0, found);
tmp = rlyTmp;
}
tmp[found++] = i;
}
this.itemIds = new short[itemCount];
this.itemCount = found;
System.arraycopy(tmp, 0, this.itemIds, 0, found);
}
public boolean matches(MenuEntry entry)
{
if (!this.option.contains(Text.standardize(entry.getOption())))
{
return false;
}
int entryId = entry.getIdentifier();
for (short i = 0; i < itemCount; i++)
{
if (entryId == itemIds[i])
{
return true;
}
}
return false;
}
}
}

View File

@@ -63,6 +63,7 @@ import net.runelite.api.events.WidgetMenuOptionClicked;
import net.runelite.api.events.WidgetPressed;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.eventbus.EventBus;
import static net.runelite.client.menus.ComparableEntries.newBaseComparableEntry;
import net.runelite.client.util.Text;
@Singleton
@@ -84,10 +85,10 @@ public class MenuManager
//Used to manage custom non-player menu options
private final Multimap<Integer, WidgetMenuOption> managedMenuOptions = HashMultimap.create();
private final Set<String> npcMenuOptions = new HashSet<>();
private final HashSet<ComparableEntry> priorityEntries = new HashSet<>();
private LinkedHashMap<MenuEntry, ComparableEntry> currentPriorityEntries = new LinkedHashMap<>();
private final HashSet<ComparableEntry> hiddenEntries = new HashSet<>();
private final HashMap<ComparableEntry, ComparableEntry> swaps = new HashMap<>();
private final HashSet<AbstractComparableEntry> priorityEntries = new HashSet<>();
private LinkedHashMap<MenuEntry, AbstractComparableEntry> currentPriorityEntries = new LinkedHashMap<>();
private final HashSet<AbstractComparableEntry> hiddenEntries = new HashSet<>();
private final HashMap<AbstractComparableEntry, AbstractComparableEntry> swaps = new HashMap<>();
private MenuEntry leftClickEntry = null;
private MenuEntry firstEntry = null;
@@ -161,7 +162,7 @@ public class MenuManager
prioritizer:
for (MenuEntry entry : oldEntries)
{
for (ComparableEntry p : priorityEntries)
for (AbstractComparableEntry p : priorityEntries)
{
// Create list of priority entries, and remove from menus
if (p.matches(entry))
@@ -180,7 +181,7 @@ public class MenuManager
if (newEntries.size() > 0)
{
// Swap first matching entry to top
for (ComparableEntry src : swaps.keySet())
for (AbstractComparableEntry src : swaps.keySet())
{
if (!src.matches(entry))
{
@@ -189,7 +190,7 @@ public class MenuManager
MenuEntry swapFrom = null;
ComparableEntry from = swaps.get(src);
AbstractComparableEntry from = swaps.get(src);
for (MenuEntry e : newEntries)
{
@@ -246,7 +247,7 @@ public class MenuManager
private void onMenuEntryAdded(MenuEntryAdded event)
{
for (ComparableEntry e : hiddenEntries)
for (AbstractComparableEntry e : hiddenEntries)
{
if (e.matches(event.getMenuEntry()))
{
@@ -513,12 +514,12 @@ public class MenuManager
/**
* Adds to the set of menu entries which when present, will remove all entries except for this one
*/
public ComparableEntry addPriorityEntry(String option, String target)
public AbstractComparableEntry addPriorityEntry(String option, String target)
{
option = Text.standardize(option);
target = Text.standardize(target);
ComparableEntry entry = new ComparableEntry(option, target);
AbstractComparableEntry entry = newBaseComparableEntry(option, target);
priorityEntries.add(entry);
@@ -530,7 +531,7 @@ public class MenuManager
option = Text.standardize(option);
target = Text.standardize(target);
ComparableEntry entry = new ComparableEntry(option, target);
AbstractComparableEntry entry = newBaseComparableEntry(option, target);
priorityEntries.removeIf(entry::equals);
}
@@ -540,22 +541,29 @@ public class MenuManager
* Adds to the set of menu entries which when present, will remove all entries except for this one
* This method will add one with strict option, but not-strict target (contains for target, equals for option)
*/
public ComparableEntry addPriorityEntry(String option)
public AbstractComparableEntry addPriorityEntry(String option)
{
option = Text.standardize(option);
ComparableEntry entry = new ComparableEntry(option, "", false);
AbstractComparableEntry entry = newBaseComparableEntry(option, "", false);
priorityEntries.add(entry);
return entry;
}
public AbstractComparableEntry addPriorityEntry(AbstractComparableEntry entry)
{
priorityEntries.add(entry);
return entry;
}
public void removePriorityEntry(String option)
{
option = Text.standardize(option);
ComparableEntry entry = new ComparableEntry(option, "", false);
AbstractComparableEntry entry = newBaseComparableEntry(option, "", false);
priorityEntries.removeIf(entry::equals);
}
@@ -584,8 +592,8 @@ public class MenuManager
option2 = Text.standardize(option2);
target2 = Text.standardize(target2);
ComparableEntry swapFrom = new ComparableEntry(option, target, -1, -1, strictOption, strictTarget);
ComparableEntry swapTo = new ComparableEntry(option2, target2, -1, -1, strictOption, strictTarget);
AbstractComparableEntry swapFrom = newBaseComparableEntry(option, target, -1, -1, strictOption, strictTarget);
AbstractComparableEntry swapTo = newBaseComparableEntry(option2, target2, -1, -1, strictOption, strictTarget);
if (swapTo.equals(swapFrom))
{
@@ -605,8 +613,8 @@ public class MenuManager
option2 = Text.standardize(option2);
target2 = Text.standardize(target2);
ComparableEntry swapFrom = new ComparableEntry(option, target, -1, -1, strictOption, strictTarget);
ComparableEntry swapTo = new ComparableEntry(option2, target2, -1, -1, strictOption, strictTarget);
AbstractComparableEntry swapFrom = newBaseComparableEntry(option, target, -1, -1, strictOption, strictTarget);
AbstractComparableEntry swapTo = newBaseComparableEntry(option2, target2, -1, -1, strictOption, strictTarget);
removeSwap(swapFrom, swapTo);
}
@@ -627,7 +635,7 @@ public class MenuManager
/**
* Adds to the map of swaps - Pre-baked entry
*/
public void addSwap(ComparableEntry swapFrom, ComparableEntry swapTo)
public void addSwap(AbstractComparableEntry swapFrom, AbstractComparableEntry swapTo)
{
if (swapTo.equals(swapFrom))
{
@@ -650,8 +658,8 @@ public class MenuManager
option2 = Text.standardize(option2);
target2 = Text.standardize(target2);
ComparableEntry swapFrom = new ComparableEntry(option, target, id, type, false, false);
ComparableEntry swapTo = new ComparableEntry(option2, target2, id2, type2, false, false);
AbstractComparableEntry swapFrom = newBaseComparableEntry(option, target, id, type, false, false);
AbstractComparableEntry swapTo = newBaseComparableEntry(option2, target2, id2, type2, false, false);
if (swapTo.equals(swapFrom))
{
@@ -670,13 +678,13 @@ public class MenuManager
option2 = Text.standardize(option2);
target2 = Text.standardize(target2);
ComparableEntry swapFrom = new ComparableEntry(option, target, id, type, false, false);
ComparableEntry swapTo = new ComparableEntry(option2, target2, id2, type2, false, false);
AbstractComparableEntry swapFrom = newBaseComparableEntry(option, target, id, type, false, false);
AbstractComparableEntry swapTo = newBaseComparableEntry(option2, target2, id2, type2, false, false);
swaps.entrySet().removeIf(e -> e.getKey().equals(swapFrom) && e.getValue().equals(swapTo));
}
public void removeSwap(ComparableEntry swapFrom, ComparableEntry swapTo)
public void removeSwap(AbstractComparableEntry swapFrom, AbstractComparableEntry swapTo)
{
swaps.entrySet().removeIf(e -> e.getKey().equals(swapFrom) && e.getValue().equals(swapTo));
}
@@ -699,7 +707,7 @@ public class MenuManager
option = Text.standardize(option);
target = Text.standardize(target);
ComparableEntry entry = new ComparableEntry(option, target);
AbstractComparableEntry entry = newBaseComparableEntry(option, target);
hiddenEntries.add(entry);
}
@@ -709,7 +717,7 @@ public class MenuManager
option = Text.standardize(option);
target = Text.standardize(target);
ComparableEntry entry = new ComparableEntry(option, target);
AbstractComparableEntry entry = newBaseComparableEntry(option, target);
hiddenEntries.removeIf(entry::equals);
}
@@ -722,7 +730,7 @@ public class MenuManager
{
option = Text.standardize(option);
ComparableEntry entry = new ComparableEntry(option, "", false);
AbstractComparableEntry entry = newBaseComparableEntry(option, "", false);
hiddenEntries.add(entry);
}
@@ -731,7 +739,7 @@ public class MenuManager
{
option = Text.standardize(option);
ComparableEntry entry = new ComparableEntry(option, "", false);
AbstractComparableEntry entry = newBaseComparableEntry(option, "", false);
hiddenEntries.removeIf(entry::equals);
}
@@ -744,7 +752,7 @@ public class MenuManager
option = Text.standardize(option);
target = Text.standardize(target);
ComparableEntry entry = new ComparableEntry(option, target, -1, -1, strictOption, strictTarget);
AbstractComparableEntry entry = newBaseComparableEntry(option, target, -1, -1, strictOption, strictTarget);
hiddenEntries.add(entry);
}
@@ -754,7 +762,7 @@ public class MenuManager
option = Text.standardize(option);
target = Text.standardize(target);
ComparableEntry entry = new ComparableEntry(option, target, -1, -1, strictOption, strictTarget);
AbstractComparableEntry entry = newBaseComparableEntry(option, target, -1, -1, strictOption, strictTarget);
hiddenEntries.remove(entry);
}
@@ -762,12 +770,12 @@ public class MenuManager
/**
* Adds to the set of hidden entries - Pre-baked Comparable entry
*/
public void addHiddenEntry(ComparableEntry entry)
public void addHiddenEntry(AbstractComparableEntry entry)
{
hiddenEntries.add(entry);
}
public void removeHiddenEntry(ComparableEntry entry)
public void removeHiddenEntry(AbstractComparableEntry entry)
{
hiddenEntries.remove(entry);
}
@@ -782,7 +790,7 @@ public class MenuManager
for (int i = 0; i < menuOptionCount; i++)
{
final MenuEntry entry = entries[i];
for (ComparableEntry prio : priorityEntries)
for (AbstractComparableEntry prio : priorityEntries)
{
if (!prio.matches(entry))
{
@@ -824,9 +832,9 @@ public class MenuManager
return;
}
Set<ComparableEntry> values = new HashSet<>();
Set<AbstractComparableEntry> values = new HashSet<>();
for (Map.Entry<ComparableEntry, ComparableEntry> pair : swaps.entrySet())
for (Map.Entry<AbstractComparableEntry, AbstractComparableEntry> pair : swaps.entrySet())
{
if (pair.getKey().matches(first))
{
@@ -845,7 +853,7 @@ public class MenuManager
for (int i = menuOptionCount - 2; i > 0; i--)
{
final MenuEntry entry = entries[i];
for (ComparableEntry swap : values)
for (AbstractComparableEntry swap : values)
{
if (!swap.matches(entry))
{

View File

@@ -30,7 +30,7 @@ import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import net.runelite.client.menus.ComparableEntry;
import net.runelite.client.menus.AbstractComparableEntry;
import net.runelite.client.menus.MenuManager;
import javax.inject.Inject;
@@ -42,7 +42,7 @@ class BarbarianAssaultMenu
{
private final MenuManager menuManager;
private final BarbarianAssaultPlugin game;
private final List<ComparableEntry> tracker = new ArrayList<>();
private final List<AbstractComparableEntry> tracker = new ArrayList<>();
@Getter(AccessLevel.PACKAGE)
@Setter(AccessLevel.PACKAGE)
private boolean hornUpdated = false;
@@ -76,7 +76,7 @@ class BarbarianAssaultMenu
void clearHiddenMenus()
{
// Clears menus from MenuManager and tracker
for (Iterator<ComparableEntry> iterator = tracker.iterator(); iterator.hasNext();)
for (Iterator<AbstractComparableEntry> iterator = tracker.iterator(); iterator.hasNext();)
{
menuManager.removeHiddenEntry(iterator.next());
iterator.remove();

View File

@@ -29,67 +29,68 @@ import com.google.common.collect.ImmutableSet;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.runelite.api.MenuAction;
import net.runelite.client.menus.ComparableEntry;
import net.runelite.client.menus.BaseComparableEntry;
import static net.runelite.client.menus.ComparableEntries.newBaseComparableEntry;
@AllArgsConstructor
public enum Menus
{
ATTACK_PENANCE_FIGHTER(Role.ATTACKER, new ComparableEntry("attack", "penance fighter", -1, -1, true, false)),
ATTACK_PENANCE_RANGER(Role.ATTACKER, new ComparableEntry("attack", "penance ranger", -1, -1, true, false)),
GET_SPIKES_PETRIFIED_MUSHROOM(Role.ATTACKER, new ComparableEntry("get-spikes", "petrified mushroom", -1, -1, true, true)),
TAKE_ATTACKER_ITEM_MACHINE(Role.ATTACKER, new ComparableEntry("take", "attacker item machine", -1, -1, false, true)),
TELL_RED_ATTACKER_HORN(Role.ATTACKER, new ComparableEntry("tell-red", "attacker horn", -1, -1, true, true)),
TELL_GREEN_ATTACKER_HORN(Role.ATTACKER, new ComparableEntry("tell-green", "attacker horn", -1, -1, true, true)),
TELL_BLUE_ATTACKER_HORN(Role.ATTACKER, new ComparableEntry("tell-blue", "attacker horn", -1, -1, true, true)),
ATTACK_PENANCE_FIGHTER(Role.ATTACKER, newBaseComparableEntry("attack", "penance fighter", -1, -1, true, false)),
ATTACK_PENANCE_RANGER(Role.ATTACKER, newBaseComparableEntry("attack", "penance ranger", -1, -1, true, false)),
GET_SPIKES_PETRIFIED_MUSHROOM(Role.ATTACKER, newBaseComparableEntry("get-spikes", "petrified mushroom", -1, -1, true, true)),
TAKE_ATTACKER_ITEM_MACHINE(Role.ATTACKER, newBaseComparableEntry("take", "attacker item machine", -1, -1, false, true)),
TELL_RED_ATTACKER_HORN(Role.ATTACKER, newBaseComparableEntry("tell-red", "attacker horn", -1, -1, true, true)),
TELL_GREEN_ATTACKER_HORN(Role.ATTACKER, newBaseComparableEntry("tell-green", "attacker horn", -1, -1, true, true)),
TELL_BLUE_ATTACKER_HORN(Role.ATTACKER, newBaseComparableEntry("tell-blue", "attacker horn", -1, -1, true, true)),
BLOCK_PENANCE_CAVE(Role.DEFENDER, new ComparableEntry("block", "penance cave", -1, -1, true, true)),
DUNK_LAVA_CRATER(Role.DEFENDER, new ComparableEntry("dunk", "lava crater", -1, -1, true, true)),
FIX(Role.DEFENDER, new ComparableEntry("fix", "", -1, -1, true, false)),
STOCK_UP_DEFENDER_ITEM_MACHINE(Role.DEFENDER, new ComparableEntry("stock-up", "defender item machine", -1, -1, true, true)),
TAKE_DEFENDER_ITEM_MACHINE(Role.DEFENDER, new ComparableEntry("take", "defender item machine", -1, -1, false, true)),
TAKE_HAMMER(Role.DEFENDER, new ComparableEntry("take", "hammer", -1, -1, true, true)),
TAKE_LOGS(Role.DEFENDER, new ComparableEntry("take", "logs", -1, -1, true, true)),
TELL_WORMS_DEFENDER_HORN(Role.DEFENDER, new ComparableEntry("tell-worms", "defender horn", -1, -1, true, true)),
TELL_TOFU_DEFENDER_HORN(Role.DEFENDER, new ComparableEntry("tell-tofu", "defender horn", -1, -1, true, true)),
TELL_MEAT_DEFENDER_HORN(Role.DEFENDER, new ComparableEntry("tell-meat", "defender horn", -1, -1, true, true)),
BLOCK_PENANCE_CAVE(Role.DEFENDER, newBaseComparableEntry("block", "penance cave", -1, -1, true, true)),
DUNK_LAVA_CRATER(Role.DEFENDER, newBaseComparableEntry("dunk", "lava crater", -1, -1, true, true)),
FIX(Role.DEFENDER, newBaseComparableEntry("fix", "", -1, -1, true, false)),
STOCK_UP_DEFENDER_ITEM_MACHINE(Role.DEFENDER, newBaseComparableEntry("stock-up", "defender item machine", -1, -1, true, true)),
TAKE_DEFENDER_ITEM_MACHINE(Role.DEFENDER, newBaseComparableEntry("take", "defender item machine", -1, -1, false, true)),
TAKE_HAMMER(Role.DEFENDER, newBaseComparableEntry("take", "hammer", -1, -1, true, true)),
TAKE_LOGS(Role.DEFENDER, newBaseComparableEntry("take", "logs", -1, -1, true, true)),
TELL_WORMS_DEFENDER_HORN(Role.DEFENDER, newBaseComparableEntry("tell-worms", "defender horn", -1, -1, true, true)),
TELL_TOFU_DEFENDER_HORN(Role.DEFENDER, newBaseComparableEntry("tell-tofu", "defender horn", -1, -1, true, true)),
TELL_MEAT_DEFENDER_HORN(Role.DEFENDER, newBaseComparableEntry("tell-meat", "defender horn", -1, -1, true, true)),
DRINK_FROM_HEALER_SPRING(Role.HEALER, new ComparableEntry("drink-from", "healer spring", -1, -1, true, true)),
DUNK_POISON_CRATER(Role.HEALER, new ComparableEntry("dunk", "poison crater", -1, -1, true, true)),
STOCK_UP_HEALER_ITEM_MACHINE(Role.HEALER, new ComparableEntry("stock-up", "healer item machine", -1, -1, true, true)),
TAKE_HEALER_ITEM_MACHINE(Role.HEALER, new ComparableEntry("take", "healer item machine", -1, -1, false, true)),
TAKE_FROM_HEALER_SPRING(Role.HEALER, new ComparableEntry("take-from", "healer spring", -1, -1, true, true)),
TELL_TOFU_HEALER_HORN(Role.HEALER, new ComparableEntry("tell-tofu", "healer horn", -1, -1, true, true)),
TELL_CRACKERS_HEALER_HORN(Role.HEALER, new ComparableEntry("tell-crackers", "healer horn", -1, -1, true, true)),
TELL_WORMS_HEALER_HORN(Role.HEALER, new ComparableEntry("tell-worms", "healer horn", -1, -1, true, true)),
USE_VIAL_GROUND(Role.HEALER, new ComparableEntry("use", "healing vial", -1, MenuAction.ITEM_USE_ON_GROUND_ITEM.getId(), true, false)),
USE_VIAL_ITEM(Role.HEALER, new ComparableEntry("use", "healing vial", -1, MenuAction.ITEM_USE_ON_WIDGET_ITEM.getId(), true, false)),
USE_VIAL_NPC(Role.HEALER, new ComparableEntry("use", "healing vial", -1, MenuAction.ITEM_USE_ON_NPC.getId(), true, false)),
USE_VIAL_WIDGET(Role.HEALER, new ComparableEntry("use", "healing vial", -1, MenuAction.ITEM_USE_ON_WIDGET.getId(), true, false)),
DRINK_FROM_HEALER_SPRING(Role.HEALER, newBaseComparableEntry("drink-from", "healer spring", -1, -1, true, true)),
DUNK_POISON_CRATER(Role.HEALER, newBaseComparableEntry("dunk", "poison crater", -1, -1, true, true)),
STOCK_UP_HEALER_ITEM_MACHINE(Role.HEALER, newBaseComparableEntry("stock-up", "healer item machine", -1, -1, true, true)),
TAKE_HEALER_ITEM_MACHINE(Role.HEALER, newBaseComparableEntry("take", "healer item machine", -1, -1, false, true)),
TAKE_FROM_HEALER_SPRING(Role.HEALER, newBaseComparableEntry("take-from", "healer spring", -1, -1, true, true)),
TELL_TOFU_HEALER_HORN(Role.HEALER, newBaseComparableEntry("tell-tofu", "healer horn", -1, -1, true, true)),
TELL_CRACKERS_HEALER_HORN(Role.HEALER, newBaseComparableEntry("tell-crackers", "healer horn", -1, -1, true, true)),
TELL_WORMS_HEALER_HORN(Role.HEALER, newBaseComparableEntry("tell-worms", "healer horn", -1, -1, true, true)),
USE_VIAL_GROUND(Role.HEALER, newBaseComparableEntry("use", "healing vial", -1, MenuAction.ITEM_USE_ON_GROUND_ITEM.getId(), true, false)),
USE_VIAL_ITEM(Role.HEALER, newBaseComparableEntry("use", "healing vial", -1, MenuAction.ITEM_USE_ON_WIDGET_ITEM.getId(), true, false)),
USE_VIAL_NPC(Role.HEALER, newBaseComparableEntry("use", "healing vial", -1, MenuAction.ITEM_USE_ON_NPC.getId(), true, false)),
USE_VIAL_WIDGET(Role.HEALER, newBaseComparableEntry("use", "healing vial", -1, MenuAction.ITEM_USE_ON_WIDGET.getId(), true, false)),
CONVERT_COLLECTOR_CONVERTER(Role.COLLECTOR, new ComparableEntry("convert", "collector converter", -1, -1, true, true)),
LOAD_EGG_HOPPER(Role.COLLECTOR, new ComparableEntry("load", "egg hopper", -1, -1, true, true)),
TAKE_BLUE_EGG(Role.COLLECTOR, new ComparableEntry("take", "blue egg", -1, -1, true, true)),
TAKE_GREEN_EGG(Role.COLLECTOR, new ComparableEntry("take", "green egg", -1, -1, true, true)),
TAKE_RED_EGG(Role.COLLECTOR, new ComparableEntry("take", "red egg", -1, -1, true, true)),
TAKE_YELLOW_EGG(Role.COLLECTOR, new ComparableEntry("take", "yellow egg", -1, -1, true, true)),
TELL_CONTROLLED_COLLECTOR_HORN(Role.COLLECTOR, new ComparableEntry("tell-controlled", "collector horn", -1, -1, true, true)),
TELL_ACCURATE_COLLECTOR_HORN(Role.COLLECTOR, new ComparableEntry("tell-accurate", "collector horn", -1, -1, true, true)),
TELL_AGGRESSIVE_COLLECTOR_HORN(Role.COLLECTOR, new ComparableEntry("tell-aggressive", "collector horn", -1, -1, true, true)),
TELL_DEFENSIVE_COLLECTOR_HORN(Role.COLLECTOR, new ComparableEntry("tell-defensive", "collector horn", -1, -1, true, true)),
CONVERT_COLLECTOR_CONVERTER(Role.COLLECTOR, newBaseComparableEntry("convert", "collector converter", -1, -1, true, true)),
LOAD_EGG_HOPPER(Role.COLLECTOR, newBaseComparableEntry("load", "egg hopper", -1, -1, true, true)),
TAKE_BLUE_EGG(Role.COLLECTOR, newBaseComparableEntry("take", "blue egg", -1, -1, true, true)),
TAKE_GREEN_EGG(Role.COLLECTOR, newBaseComparableEntry("take", "green egg", -1, -1, true, true)),
TAKE_RED_EGG(Role.COLLECTOR, newBaseComparableEntry("take", "red egg", -1, -1, true, true)),
TAKE_YELLOW_EGG(Role.COLLECTOR, newBaseComparableEntry("take", "yellow egg", -1, -1, true, true)),
TELL_CONTROLLED_COLLECTOR_HORN(Role.COLLECTOR, newBaseComparableEntry("tell-controlled", "collector horn", -1, -1, true, true)),
TELL_ACCURATE_COLLECTOR_HORN(Role.COLLECTOR, newBaseComparableEntry("tell-accurate", "collector horn", -1, -1, true, true)),
TELL_AGGRESSIVE_COLLECTOR_HORN(Role.COLLECTOR, newBaseComparableEntry("tell-aggressive", "collector horn", -1, -1, true, true)),
TELL_DEFENSIVE_COLLECTOR_HORN(Role.COLLECTOR, newBaseComparableEntry("tell-defensive", "collector horn", -1, -1, true, true)),
ATTACK_PENANCE_QUEEN(null, new ComparableEntry("attack", "penance queen", -1, -1, true, false)),
ATTACK_QUEEN_SPAWN(null, new ComparableEntry("attack", "queen spawn", -1, -1, true, false)),
DROP_HORN(null, new ComparableEntry("drop", "r horn", -1, -1, true, false)),
EXAMINE_HORN(null, new ComparableEntry("examine", "r horn", -1, -1, true, false)),
LIGHT_LOGS(null, new ComparableEntry("light", "logs", -1, -1, true, true)),
MEDIC_HORN(null, new ComparableEntry("medic", "r horn", -1, -1, true, false)),
USE_HORN(null, new ComparableEntry("use", "r horn", -1, -1, true, false));
ATTACK_PENANCE_QUEEN(null, newBaseComparableEntry("attack", "penance queen", -1, -1, true, false)),
ATTACK_QUEEN_SPAWN(null, newBaseComparableEntry("attack", "queen spawn", -1, -1, true, false)),
DROP_HORN(null, newBaseComparableEntry("drop", "r horn", -1, -1, true, false)),
EXAMINE_HORN(null, newBaseComparableEntry("examine", "r horn", -1, -1, true, false)),
LIGHT_LOGS(null, newBaseComparableEntry("light", "logs", -1, -1, true, true)),
MEDIC_HORN(null, newBaseComparableEntry("medic", "r horn", -1, -1, true, false)),
USE_HORN(null, newBaseComparableEntry("use", "r horn", -1, -1, true, false));
@Getter
private final Role role;
@Getter
private final ComparableEntry entry;
private final BaseComparableEntry entry;
private static final ImmutableSet<Menus> ALL = ImmutableSet.copyOf(Menus.values());

View File

@@ -0,0 +1,29 @@
package net.runelite.client.plugins.menuentryswapper;
import lombok.EqualsAndHashCode;
import net.runelite.api.MenuEntry;
import net.runelite.api.widgets.WidgetID;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.menus.AbstractComparableEntry;
import net.runelite.client.util.Text;
@EqualsAndHashCode(callSuper = true)
public class BankComparableEntry extends AbstractComparableEntry
{
public BankComparableEntry(String option, String itemName)
{
this.setOption(Text.standardize(option));
this.setTarget(Text.standardize(itemName));
}
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)
{
return false;
}
return Text.standardize(entry.getOption()).contains(this.getOption()) && Text.standardize(entry.getTarget()).equals(this.getTarget());
}
}

View File

@@ -76,7 +76,9 @@ import net.runelite.client.eventbus.EventBus;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.ItemVariationMapping;
import net.runelite.client.input.KeyManager;
import net.runelite.client.menus.ComparableEntry;
import net.runelite.client.menus.AbstractComparableEntry;
import static net.runelite.client.menus.ComparableEntries.newBankComparableEntry;
import static net.runelite.client.menus.ComparableEntries.newBaseComparableEntry;
import net.runelite.client.menus.MenuManager;
import net.runelite.client.menus.WidgetMenuOption;
import net.runelite.client.plugins.Plugin;
@@ -178,7 +180,7 @@ public class MenuEntrySwapperPlugin extends Plugin
private boolean buildingMode;
private boolean inTobRaid = false;
private boolean inCoxRaid = false;
private final Map<ComparableEntry, ComparableEntry> customSwaps = new HashMap<>();
private final Map<AbstractComparableEntry, AbstractComparableEntry> customSwaps = new HashMap<>();
private List<String> bankItemNames = new ArrayList<>();
@Getter(AccessLevel.PACKAGE)
private boolean configuringShiftClick = false;
@@ -925,7 +927,7 @@ public class MenuEntrySwapperPlugin extends Plugin
private void loadCustomSwaps(String config)
{
Map<ComparableEntry, ComparableEntry> tmp = new HashMap<>();
Map<AbstractComparableEntry, AbstractComparableEntry> tmp = new HashMap<>();
if (!Strings.isNullOrEmpty(config))
{
@@ -957,7 +959,7 @@ public class MenuEntrySwapperPlugin extends Plugin
targetFrom = splitFrom[1].trim();
}
ComparableEntry fromEntry = new ComparableEntry(optionFrom, targetFrom);
AbstractComparableEntry fromEntry = newBaseComparableEntry(optionFrom, targetFrom);
String[] splitTo = Text.standardize(to).split(",");
String optionTo = splitTo[0].trim();
@@ -971,26 +973,26 @@ public class MenuEntrySwapperPlugin extends Plugin
targetTo = splitTo[1].trim();
}
ComparableEntry toEntry = new ComparableEntry(optionTo, targetTo);
AbstractComparableEntry toEntry = newBaseComparableEntry(optionTo, targetTo);
tmp.put(fromEntry, toEntry);
}
}
for (Map.Entry<ComparableEntry, ComparableEntry> e : customSwaps.entrySet())
for (Map.Entry<AbstractComparableEntry, AbstractComparableEntry> e : customSwaps.entrySet())
{
ComparableEntry key = e.getKey();
ComparableEntry value = e.getValue();
AbstractComparableEntry key = e.getKey();
AbstractComparableEntry value = e.getValue();
menuManager.removeSwap(key, value);
}
customSwaps.clear();
customSwaps.putAll(tmp);
for (Map.Entry<ComparableEntry, ComparableEntry> entry : customSwaps.entrySet())
for (Map.Entry<AbstractComparableEntry, AbstractComparableEntry> entry : customSwaps.entrySet())
{
ComparableEntry a1 = entry.getKey();
ComparableEntry a2 = entry.getValue();
AbstractComparableEntry a1 = entry.getKey();
AbstractComparableEntry a2 = entry.getValue();
menuManager.addSwap(a1, a2);
}
}
@@ -1006,8 +1008,8 @@ public class MenuEntrySwapperPlugin extends Plugin
{
Text.fromCSV(this.getWithdrawOneItems).forEach(item ->
{
menuManager.addPriorityEntry("Withdraw-1", item).setPriority(10);
menuManager.addPriorityEntry("Deposit-1", item).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Withdraw-1", item)).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Deposit-1", item)).setPriority(10);
});
}
@@ -1015,8 +1017,8 @@ public class MenuEntrySwapperPlugin extends Plugin
{
Text.fromCSV(this.getWithdrawFiveItems).forEach(item ->
{
menuManager.addPriorityEntry("Withdraw-5", item).setPriority(10);
menuManager.addPriorityEntry("Deposit-5", item).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Withdraw-5", item)).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Deposit-5", item)).setPriority(10);
});
}
@@ -1024,8 +1026,8 @@ public class MenuEntrySwapperPlugin extends Plugin
{
Text.fromCSV(this.getWithdrawTenItems).forEach(item ->
{
menuManager.addPriorityEntry("Withdraw-10", item).setPriority(10);
menuManager.addPriorityEntry("Deposit-10", item).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Withdraw-10", item)).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Deposit-10", item)).setPriority(10);
});
}
@@ -1033,8 +1035,8 @@ public class MenuEntrySwapperPlugin extends Plugin
{
Text.fromCSV(this.getWithdrawXItems).forEach(item ->
{
menuManager.addPriorityEntry("Withdraw-", item).setPriority(10);
menuManager.addPriorityEntry("Deposit-", item).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Withdraw-" + this.getWithdrawXAmount, item)).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Deposit-" + this.getWithdrawXAmount, item)).setPriority(10);
});
}
@@ -1042,8 +1044,8 @@ public class MenuEntrySwapperPlugin extends Plugin
{
Text.fromCSV(this.getWithdrawAllItems).forEach(item ->
{
menuManager.addPriorityEntry("Withdraw-All", item).setPriority(10);
menuManager.addPriorityEntry("Deposit-All", item).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Withdraw-All", item)).setPriority(10);
menuManager.addPriorityEntry(newBankComparableEntry("Deposit-All", item)).setPriority(10);
});
}
@@ -1470,8 +1472,8 @@ public class MenuEntrySwapperPlugin extends Plugin
});
Text.fromCSV(this.getWithdrawXItems).forEach(item ->
{
menuManager.removePriorityEntry("Withdraw-", item);
menuManager.removePriorityEntry("Deposit-", item);
menuManager.removePriorityEntry("Withdraw-" + this.getWithdrawXAmount, item);
menuManager.removePriorityEntry("Deposit-" + this.getWithdrawXAmount, item);
});
Text.fromCSV(this.getWithdrawAllItems).forEach(item ->
{