Merge pull request #364 from Lucwousin/no_really_i_fucking_hate_that_menu_entry_clicked_command

Menu entry stuff
This commit is contained in:
Lucwousin
2019-05-22 21:25:12 +02:00
committed by GitHub
6 changed files with 397 additions and 189 deletions

View File

@@ -1,102 +0,0 @@
package net.runelite.client.menus;
import joptsimple.internal.Strings;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import net.runelite.api.MenuEntry;
import static net.runelite.client.menus.MenuManager.LEVEL_PATTERN;
import net.runelite.client.util.Text;
@EqualsAndHashCode
public class AbstractMenuEntry
{
@Getter
private String option;
@Getter
private String target;
@Getter
private int id;
@Getter
private int type;
@Getter
private boolean strictOption;
@Getter
private boolean strictTarget;
public AbstractMenuEntry(String option, String target)
{
this(option, target, -1, -1, true, true);
}
public AbstractMenuEntry(String option, String target, boolean strictTarget)
{
this(option, target, -1, -1, true, strictTarget);
}
public AbstractMenuEntry(String option, String target, int id, int type, boolean strictOption, boolean strictTarget)
{
this.option = option;
this.target = target;
this.id = id;
this.type = type;
this.strictOption = strictOption;
this.strictTarget = strictTarget;
}
boolean matches(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;
}
/*boolean equals(AbstractMenuEntry other)
{
return target.equals(other.getTarget())
&& option.equals(other.getOption())
&& id == other.getId()
&& type == other.getType()
&& strictOption == other.isStrictOption()
&& strictTarget == other.isStrictTarget();
}*/
}

View File

@@ -0,0 +1,116 @@
/*
* 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 joptsimple.internal.Strings;
import lombok.EqualsAndHashCode;
import lombok.Getter;
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;
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 = option;
this.target = target;
this.id = id;
this.type = type;
this.strictOption = strictOption;
this.strictTarget = strictTarget;
}
boolean matches(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

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2017, Robin <robin.weymans@gmail.com>
* Copyright (c) 2019, Lucas <https://github.com/Lucwousin>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -39,11 +40,13 @@ import java.util.Set;
import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.inject.Singleton;
import joptsimple.internal.Strings;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
import net.runelite.api.NPCComposition;
import net.runelite.api.ObjectComposition;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.NpcActionChanged;
@@ -88,10 +91,12 @@ public class MenuManager
private final Multimap<Integer, WidgetMenuOption> managedMenuOptions = HashMultimap.create();
private final Set<String> npcMenuOptions = new HashSet<>();
private final Set<AbstractMenuEntry> priorityEntries = new HashSet<>();
private final Set<ComparableEntry> priorityEntries = new HashSet<>();
private final Set<MenuEntry> currentPriorityEntries = new HashSet<>();
private final Map<AbstractMenuEntry, AbstractMenuEntry> swaps = new HashMap<>();
private final Map<ComparableEntry, ComparableEntry> swaps = new HashMap<>();
private final Set<MenuEntry> originalTypes = new HashSet<>();
private final Set<Integer> leftClickObjects = new HashSet<>();
@Inject
private MenuManager(Client client, EventBus eventBus)
@@ -148,6 +153,8 @@ public class MenuManager
{
// Menu entries reset, so priority entries should reset as well
currentPriorityEntries.clear();
originalTypes.clear();
}
for (WidgetMenuOption currentMenu : options)
@@ -166,10 +173,10 @@ public class MenuManager
}
}
MenuEntry newestEntry = menuEntries[menuEntries.length - 1];
final MenuEntry newestEntry = menuEntries[menuEntries.length - 1];
boolean isPrio = false;
for (AbstractMenuEntry p : priorityEntries)
for (ComparableEntry p : priorityEntries)
{
if (p.matches(newestEntry))
{
@@ -192,12 +199,12 @@ public class MenuManager
{
copy.retainAll(currentPriorityEntries);
copy.add(CANCEL());
copy.add(0, CANCEL());
}
// Find the current entry in the swaps map
AbstractMenuEntry swapEntry = null;
for (AbstractMenuEntry e : swaps.keySet())
ComparableEntry swapEntry = null;
for (ComparableEntry e : swaps.keySet())
{
if (e.matches(newestEntry))
{
@@ -208,7 +215,7 @@ public class MenuManager
if (swapEntry != null)
{
AbstractMenuEntry swapTarget = swaps.get(swapEntry);
ComparableEntry swapTarget = swaps.get(swapEntry);
// Find the target for the swap in current menu entries
MenuEntry foundSwap = null;
@@ -223,14 +230,18 @@ public class MenuManager
if (foundSwap != null)
{
// This is to make things like games necklace and essence pouches show up right
if (foundSwap.getType() == MenuAction.EXAMINE_ITEM_BANK_EQ.getId())
// This is the menu entry added last's type
final int otherType = foundSwap.getType();
// MenuActions with an id of over 1000 get shifted to the back of the menu entry array
// They have different id's in the packet buffer though, so we got to modify them back on click
// I couldn't get this to work with objects, so we're using modified objectcomposition for that
final boolean shouldModifyType = otherType == MenuAction.EXAMINE_ITEM_BANK_EQ.getId();
if (shouldModifyType)
{
int newType = foundSwap.getType();
foundSwap.setType(newestEntry.getType());
newestEntry.setType(newType);
foundSwap.setType(MenuAction.WIDGET_DEFAULT.getId());
originalTypes.add(foundSwap);
}
// Swap
@@ -271,6 +282,86 @@ public class MenuManager
}
}
public boolean toggleLeftClick(String menuText, int objectID, boolean reset)
{
Preconditions.checkNotNull(menuText);
if (client == null)
{
return false;
}
ObjectComposition oc = client.getObjectDefinition(objectID);
if (oc == null)
{
return false;
}
ObjectComposition impostor = oc.getImpostorIds() != null ? oc.getImpostor() : null;
if (impostor != null)
{
if (toggleLeftClick(menuText, impostor.getId(), reset))
{
// Sorry about this
leftClickObjects.remove(impostor.getId());
if (reset)
{
leftClickObjects.remove(objectID);
}
else
{
leftClickObjects.add(objectID);
}
return true;
}
}
String[] options = oc.getActions();
if (options == null)
{
return false;
}
boolean hasOption5 = !Strings.isNullOrEmpty(options[options.length - 1]);
boolean hasOption1 = !Strings.isNullOrEmpty(options[0]);
if (hasOption5 || hasOption1)
{
String option1 = options[0];
String option5 = options[options.length - 1];
if (reset && !hasOption1 // Won't have to reset anything cause
|| reset && !menuText.equalsIgnoreCase(option1) // theres nothing to reset
|| hasOption5 && !menuText.equalsIgnoreCase(option5))
{
return false;
}
options[0] = option5;
options[options.length - 1] = option1;
}
else
{
return false;
}
if (reset)
{
leftClickObjects.remove(objectID);
}
else
{
leftClickObjects.add(objectID);
}
return true;
}
@Subscribe
public void onPlayerMenuOptionsChanged(PlayerMenuOptionsChanged event)
{
@@ -349,6 +440,79 @@ public class MenuManager
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
if (!event.getMenuTarget().equals("do not edit") &&
!originalTypes.isEmpty() &&
event.getMenuAction() == MenuAction.WIDGET_DEFAULT)
{
for (MenuEntry e : originalTypes)
{
// Honestly, I was about to write a huge ass rant about
// how I hate whoever wrote the menuoptionclicked class
// but I decided that that'd be un-nice to them, and they
// probably spent over 24 hours writing it. Not because
// it was that difficult to write, of course, but because
// they must have the fucking iq of a retarded, under developed,
// braindead, basically good-for-nothing, idiotic chimp.
//
// Just kidding, of course, that would be too big of an
// insult towards those poor chimps. It's not their fault
// some dumbass is the way they are, right? Why should they
// feel bad for something they can't do anything about?
//
// Whoever wrote that class though, should actually feel
// 100% terrible. If they aren't depressed, I really wish
// they become depressed very, very soon. What the fuck
// were they even thinking.
if (event.getMenuAction().getId() != e.getType()
|| event.getId() != e.getIdentifier()
|| !event.getMenuOption().equals(e.getOption()))
{
continue;
}
event.consume();
client.invokeMenuAction(
event.getActionParam(),
event.getWidgetId(),
MenuAction.EXAMINE_ITEM_BANK_EQ.getId(),
event.getId(),
event.getMenuOption(),
"do not edit",
client.getMouseCanvasPosition().getX(),
client.getMouseCanvasPosition().getY()
);
break;
}
}
if (!event.getMenuTarget().equals("do not edit") &&
!leftClickObjects.isEmpty() &&
event.getMenuAction() == MenuAction.GAME_OBJECT_FIRST_OPTION &&
(
leftClickObjects.contains(event.getId())
||
client.getObjectDefinition(event.getId()) != null &&
client.getObjectDefinition(event.getId()).getImpostorIds() != null &&
client.getObjectDefinition(event.getId()).getImpostor() != null &&
client.getObjectDefinition(event.getId()).getImpostor().getId() == event.getId()))
{
event.consume();
client.invokeMenuAction(
event.getActionParam(),
event.getWidgetId(),
MenuAction.GAME_OBJECT_FIFTH_OPTION.getId(),
event.getId(),
event.getMenuOption(),
"do not edit",
client.getMouseCanvasPosition().getX(),
client.getMouseCanvasPosition().getY()
);
}
if (event.getMenuAction() != MenuAction.RUNELITE)
{
return; // not a player menu
@@ -423,7 +587,7 @@ public class MenuManager
option = Text.standardize(option);
target = Text.standardize(target);
AbstractMenuEntry entry = new AbstractMenuEntry(option, target);
ComparableEntry entry = new ComparableEntry(option, target);
priorityEntries.add(entry);
}
@@ -433,10 +597,10 @@ public class MenuManager
option = Text.standardize(option);
target = Text.standardize(target);
AbstractMenuEntry entry = new AbstractMenuEntry(option, target);
ComparableEntry entry = new ComparableEntry(option, target);
Set<AbstractMenuEntry> toRemove = new HashSet<>();
for (AbstractMenuEntry priorityEntry : priorityEntries)
Set<ComparableEntry> toRemove = new HashSet<>();
for (ComparableEntry priorityEntry : priorityEntries)
{
if (entry.equals(priorityEntry))
{
@@ -444,7 +608,7 @@ public class MenuManager
}
}
for (AbstractMenuEntry e : toRemove)
for (ComparableEntry e : toRemove)
{
priorityEntries.remove(e);
}
@@ -459,7 +623,7 @@ public class MenuManager
{
option = Text.standardize(option);
AbstractMenuEntry entry = new AbstractMenuEntry(option, "", false);
ComparableEntry entry = new ComparableEntry(option, "", false);
priorityEntries.add(entry);
}
@@ -468,10 +632,10 @@ public class MenuManager
{
option = Text.standardize(option);
AbstractMenuEntry entry = new AbstractMenuEntry(option, "", false);
ComparableEntry entry = new ComparableEntry(option, "", false);
Set<AbstractMenuEntry> toRemove = new HashSet<>();
for (AbstractMenuEntry priorityEntry : priorityEntries)
Set<ComparableEntry> toRemove = new HashSet<>();
for (ComparableEntry priorityEntry : priorityEntries)
{
if (entry.equals(priorityEntry))
{
@@ -479,7 +643,7 @@ public class MenuManager
}
}
for (AbstractMenuEntry e : toRemove)
for (ComparableEntry e : toRemove)
{
priorityEntries.remove(e);
}
@@ -496,8 +660,8 @@ public class MenuManager
option2 = Text.standardize(option2);
target2 = Text.standardize(target2);
AbstractMenuEntry swapFrom = new AbstractMenuEntry(option, target, -1, -1, strictOption, strictTarget);
AbstractMenuEntry swapTo = new AbstractMenuEntry(option2, target2, -1, -1, strictOption, strictTarget);
ComparableEntry swapFrom = new ComparableEntry(option, target, -1, -1, strictOption, strictTarget);
ComparableEntry swapTo = new ComparableEntry(option2, target2, -1, -1, strictOption, strictTarget);
if (swapTo.equals(swapFrom))
{
@@ -517,8 +681,8 @@ public class MenuManager
option2 = Text.standardize(option2);
target2 = Text.standardize(target2);
AbstractMenuEntry swapFrom = new AbstractMenuEntry(option, target, -1, -1, strictOption, strictTarget);
AbstractMenuEntry swapTo = new AbstractMenuEntry(option2, target2, -1, -1, strictOption, strictTarget);
ComparableEntry swapFrom = new ComparableEntry(option, target, -1, -1, strictOption, strictTarget);
ComparableEntry swapTo = new ComparableEntry(option2, target2, -1, -1, strictOption, strictTarget);
removeSwap(swapFrom, swapTo);
}
@@ -539,7 +703,7 @@ public class MenuManager
/**
* Adds to the map of swaps - Pre-baked Abstract entry
*/
public void addSwap(AbstractMenuEntry swapFrom, AbstractMenuEntry swapTo)
public void addSwap(ComparableEntry swapFrom, ComparableEntry swapTo)
{
if (swapTo.equals(swapFrom))
{
@@ -562,8 +726,8 @@ public class MenuManager
option2 = Text.standardize(option2);
target2 = Text.standardize(target2);
AbstractMenuEntry swapFrom = new AbstractMenuEntry(option, target, id, type, false, false);
AbstractMenuEntry swapTo = new AbstractMenuEntry(option2, target2, id2, type2, false, false);
ComparableEntry swapFrom = new ComparableEntry(option, target, id, type, false, false);
ComparableEntry swapTo = new ComparableEntry(option2, target2, id2, type2, false, false);
if (swapTo.equals(swapFrom))
{
@@ -582,11 +746,11 @@ public class MenuManager
option2 = Text.standardize(option2);
target2 = Text.standardize(target2);
AbstractMenuEntry swapFrom = new AbstractMenuEntry(option, target, id, type, false, false);
AbstractMenuEntry swapTo = new AbstractMenuEntry(option2, target2, id2, type2, false, false);
ComparableEntry swapFrom = new ComparableEntry(option, target, id, type, false, false);
ComparableEntry swapTo = new ComparableEntry(option2, target2, id2, type2, false, false);
Set<AbstractMenuEntry> toRemove = new HashSet<>();
for (Map.Entry<AbstractMenuEntry, AbstractMenuEntry> e : swaps.entrySet())
Set<ComparableEntry> toRemove = new HashSet<>();
for (Map.Entry<ComparableEntry, ComparableEntry> e : swaps.entrySet())
{
if (e.getKey().equals(swapFrom) && e.getValue().equals(swapTo))
{
@@ -594,16 +758,16 @@ public class MenuManager
}
}
for (AbstractMenuEntry entry : toRemove)
for (ComparableEntry entry : toRemove)
{
swaps.remove(entry);
}
}
public void removeSwap(AbstractMenuEntry swapFrom, AbstractMenuEntry swapTo)
public void removeSwap(ComparableEntry swapFrom, ComparableEntry swapTo)
{
Set<AbstractMenuEntry> toRemove = new HashSet<>();
for (Map.Entry<AbstractMenuEntry, AbstractMenuEntry> e : swaps.entrySet())
Set<ComparableEntry> toRemove = new HashSet<>();
for (Map.Entry<ComparableEntry, ComparableEntry> e : swaps.entrySet())
{
if (e.getKey().equals(swapFrom) && e.getValue().equals(swapTo))
{
@@ -611,7 +775,7 @@ public class MenuManager
}
}
for (AbstractMenuEntry entry : toRemove)
for (ComparableEntry entry : toRemove)
{
swaps.remove(entry);
}
@@ -624,9 +788,9 @@ public class MenuManager
{
withTarget = Text.standardize(withTarget);
Set<AbstractMenuEntry> toRemove = new HashSet<>();
Set<ComparableEntry> toRemove = new HashSet<>();
for (AbstractMenuEntry e : swaps.keySet())
for (ComparableEntry e : swaps.keySet())
{
if (e.getTarget().equals(withTarget))
{
@@ -634,7 +798,7 @@ public class MenuManager
}
}
for (AbstractMenuEntry entry : toRemove)
for (ComparableEntry entry : toRemove)
{
swaps.remove(entry);
}

View File

@@ -433,7 +433,7 @@ public interface EasyscapeConfig extends Config
@ConfigItem(
keyName = "easyConstruction",
name = "Easy Construction",
description = "Makes \"Remove\" the default option for listed items in build mode.",
description = "Makes \"Remove\"/\"Build\" the default option for listed item ID's in build mode.<br>Tip: Use dev tools \"Game Objects\" to find out the ID!",
position = 30,
group = "Miscellaneous swapper"
)
@@ -445,7 +445,7 @@ public interface EasyscapeConfig extends Config
@ConfigItem(
keyName = "constructionItems",
name = "Construction Items",
description = "Items listed here will have the default option set to \"Removed\" in build mode.",
description = "Makes \"Remove\"/\"Build\" the default option for listed item ID's in build mode.<br>Tip: Use dev tools \"Game Objects\" to find out the ID, and seperate values with a ','",
position = 31,
group = "Miscellaneous swapper",
hidden = true,

View File

@@ -29,6 +29,8 @@ package net.runelite.client.plugins.easyscape;
import com.google.common.base.Strings;
import com.google.inject.Provides;
import java.util.HashSet;
import java.util.Set;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.GameState;
@@ -40,6 +42,7 @@ import net.runelite.api.Player;
import static net.runelite.api.Varbits.BUILDING_MODE;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
@@ -61,6 +64,7 @@ public class EasyscapePlugin extends Plugin
private static final int PURO_PURO_REGION_ID = 10307;
private MenuEntry[] entries;
private final Set<Integer> leftClickConstructionIDs = new HashSet<>();
@Inject
private Client client;
@@ -81,12 +85,25 @@ public class EasyscapePlugin extends Plugin
public void startUp()
{
addSwaps();
loadConstructionIDs(config.getConstructionItems());
}
@Override
public void shutDown()
{
removeSwaps();
loadConstructionIDs("");
}
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
if (client.getGameState() != GameState.LOGGED_IN)
{
return;
}
loadConstructionIDs(config.getConstructionItems());
}
@Subscribe
@@ -301,35 +318,7 @@ public class EasyscapePlugin extends Plugin
}
}
if (config.getEasyConstruction() && client.getVar(BUILDING_MODE) == 1 && !Strings.isNullOrEmpty(config.getConstructionItems()))
{
if (event.getType() == WALK.getId())
{
MenuEntry menuEntry = entries[entries.length - 1];
menuEntry.setType(MenuAction.WALK.getId() + MENU_ACTION_DEPRIORITIZE_OFFSET);
}
swap(client, "Build", option, target);
for (int i = entries.length - 1; i >= 0; i--)
{
for (String item : Text.fromCSV(config.getConstructionItems()))
{
if (item.equalsIgnoreCase(Text.removeTags(entries[i].getTarget())))
{
if (!entries[i].getOption().equalsIgnoreCase("remove"))
{
entries = ArrayUtils.remove(entries, i);
i--;
}
}
}
}
client.setMenuEntries(entries);
}
if (config.getSwapSmithing() && option.contains("smith"))
else if (config.getSwapSmithing() && option.contains("smith"))
{
if (option.equalsIgnoreCase("Smith 1"))
{
@@ -396,6 +385,7 @@ public class EasyscapePlugin extends Plugin
return;
}
loadConstructionIDs(config.getConstructionItems());
removeSwaps();
addSwaps();
}
@@ -443,7 +433,6 @@ public class EasyscapePlugin extends Plugin
menuManager.addSwap("remove", "digsite pendant", config.getDigsitePendantMode().toString(), "digsite pendant", true, false);
}
if (config.getSlayerRing())
{
menuManager.addSwap("remove", "slayer ring", config.getSlayerRingMode().toString(), "slayer ring", true, false);
@@ -508,4 +497,45 @@ public class EasyscapePlugin extends Plugin
return location.getRegionID() == PURO_PURO_REGION_ID;
}
}
private void loadConstructionIDs(String from)
{
if (client.getGameState() != GameState.LOGGED_IN
|| Strings.isNullOrEmpty(from) && leftClickConstructionIDs.isEmpty())
{
return;
}
if (!leftClickConstructionIDs.isEmpty())
{
for (int i : leftClickConstructionIDs)
{
menuManager.toggleLeftClick("build", i, true);
menuManager.toggleLeftClick("remove", i, true);
}
leftClickConstructionIDs.clear();
}
if (!config.getEasyConstruction() &&
!Strings.isNullOrEmpty(from) &&
client.getVar(BUILDING_MODE) == 1)
{
for (String s : Text.fromCSV(from))
{
int id = Integer.parseInt(s.replaceAll("[^0-9]", ""));
if (leftClickConstructionIDs.contains(id))
{
continue;
}
if (menuManager.toggleLeftClick("build", id, false)
|| menuManager.toggleLeftClick("remove", id, false))
{
leftClickConstructionIDs.add(id);
}
}
}
}
}

View File

@@ -55,7 +55,7 @@ import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.ItemManager;
import net.runelite.client.game.ItemVariationMapping;
import net.runelite.client.input.KeyManager;
import net.runelite.client.menus.AbstractMenuEntry;
import net.runelite.client.menus.ComparableEntry;
import net.runelite.client.menus.MenuManager;
import net.runelite.client.menus.WidgetMenuOption;
import net.runelite.client.plugins.Plugin;
@@ -110,7 +110,7 @@ public class MenuEntrySwapperPlugin extends Plugin
.omitEmptyStrings()
.trimResults();
private final Map<AbstractMenuEntry, AbstractMenuEntry> customSwaps = new HashMap<>();
private final Map<ComparableEntry, ComparableEntry> customSwaps = new HashMap<>();
@Inject
private Client client;
@@ -762,7 +762,7 @@ else if (config.swapOccult() != OccultAltarMode.VENERATE && option.equals("vener
private void loadCustomSwaps(String config)
{
Map<AbstractMenuEntry, AbstractMenuEntry> tmp = new HashMap<>();
Map<ComparableEntry, ComparableEntry> tmp = new HashMap<>();
if (!Strings.isNullOrEmpty(config))
{
@@ -784,7 +784,7 @@ else if (config.swapOccult() != OccultAltarMode.VENERATE && option.equals("vener
targetFrom = splitFrom[1].trim();
}
AbstractMenuEntry fromEntry = new AbstractMenuEntry(optionFrom, targetFrom);
ComparableEntry fromEntry = new ComparableEntry(optionFrom, targetFrom);
String[] splitTo = Text.standardize(to).split(",");
String optionTo = splitTo[0].trim();
@@ -798,26 +798,26 @@ else if (config.swapOccult() != OccultAltarMode.VENERATE && option.equals("vener
targetTo = splitTo[1].trim();
}
AbstractMenuEntry toEntry = new AbstractMenuEntry(optionTo, targetTo);
ComparableEntry toEntry = new ComparableEntry(optionTo, targetTo);
tmp.put(fromEntry, toEntry);
}
}
for (Map.Entry<AbstractMenuEntry, AbstractMenuEntry> e : customSwaps.entrySet())
for (Map.Entry<ComparableEntry, ComparableEntry> e : customSwaps.entrySet())
{
AbstractMenuEntry key = e.getKey();
AbstractMenuEntry value = e.getValue();
ComparableEntry key = e.getKey();
ComparableEntry value = e.getValue();
menuManager.removeSwap(key, value);
}
customSwaps.clear();
customSwaps.putAll(tmp);
for (Map.Entry<AbstractMenuEntry, AbstractMenuEntry> entry : customSwaps.entrySet())
for (Map.Entry<ComparableEntry, ComparableEntry> entry : customSwaps.entrySet())
{
AbstractMenuEntry a1 = entry.getKey();
AbstractMenuEntry a2 = entry.getValue();
ComparableEntry a1 = entry.getKey();
ComparableEntry a2 = entry.getValue();
menuManager.addSwap(a1, a2);
}
}