From 837be0633d918d04771b528a4af7c6c89100d711 Mon Sep 17 00:00:00 2001 From: 7ate9 <7ate9@users.noreply.github.com`> Date: Sat, 8 Jun 2019 23:52:40 -0400 Subject: [PATCH 1/2] menumanager: adds option to hide entries and switched to Collection.removeIf() when removing entries from sets --- .../runelite/client/menus/MenuManager.java | 170 +++++++++++------- 1 file changed, 103 insertions(+), 67 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java b/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java index 2743d01b25..8af9da478d 100644 --- a/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java +++ b/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java @@ -29,7 +29,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.HashMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -93,6 +92,7 @@ public class MenuManager private final Set priorityEntries = new HashSet<>(); private final Set currentPriorityEntries = new HashSet<>(); + private final Set hiddenEntries = new HashSet<>(); private final Map swaps = new HashMap<>(); private final Set originalTypes = new HashSet<>(); @@ -192,7 +192,7 @@ public class MenuManager } // Make a copy of the menu entries, cause you can't remove from Arrays.asList() - List copy = new ArrayList<>(Arrays.asList(menuEntries)); + List copy = Lists.newArrayList(menuEntries); // If there are entries we want to prioritize, we have to remove the rest if (!currentPriorityEntries.isEmpty()) @@ -253,6 +253,21 @@ public class MenuManager } } + boolean isHidden = false; + for (ComparableEntry p : hiddenEntries) + { + if (p.matches(newestEntry)) + { + isHidden = true; + break; + } + } + + if (isHidden) + { + copy.remove(newestEntry); + } + client.setMenuEntries(copy.toArray(new MenuEntry[0])); } @@ -599,19 +614,7 @@ public class MenuManager ComparableEntry entry = new ComparableEntry(option, target); - Set toRemove = new HashSet<>(); - for (ComparableEntry priorityEntry : priorityEntries) - { - if (entry.equals(priorityEntry)) - { - toRemove.add(entry); - } - } - - for (ComparableEntry e : toRemove) - { - priorityEntries.remove(e); - } + priorityEntries.removeIf(entry::equals); } @@ -634,19 +637,7 @@ public class MenuManager ComparableEntry entry = new ComparableEntry(option, "", false); - Set toRemove = new HashSet<>(); - for (ComparableEntry priorityEntry : priorityEntries) - { - if (entry.equals(priorityEntry)) - { - toRemove.add(entry); - } - } - - for (ComparableEntry e : toRemove) - { - priorityEntries.remove(e); - } + priorityEntries.removeIf(entry::equals); } /** @@ -757,36 +748,12 @@ public class MenuManager ComparableEntry swapFrom = new ComparableEntry(option, target, id, type, false, false); ComparableEntry swapTo = new ComparableEntry(option2, target2, id2, type2, false, false); - Set toRemove = new HashSet<>(); - for (Map.Entry e : swaps.entrySet()) - { - if (e.getKey().equals(swapFrom) && e.getValue().equals(swapTo)) - { - toRemove.add(e.getKey()); - } - } - - for (ComparableEntry entry : toRemove) - { - swaps.remove(entry); - } + swaps.entrySet().removeIf(e -> e.getKey().equals(swapFrom) && e.getValue().equals(swapTo)); } public void removeSwap(ComparableEntry swapFrom, ComparableEntry swapTo) { - Set toRemove = new HashSet<>(); - for (Map.Entry e : swaps.entrySet()) - { - if (e.getKey().equals(swapFrom) && e.getValue().equals(swapTo)) - { - toRemove.add(e.getKey()); - } - } - - for (ComparableEntry entry : toRemove) - { - swaps.remove(entry); - } + swaps.entrySet().removeIf(e -> e.getKey().equals(swapFrom) && e.getValue().equals(swapTo)); } /** @@ -794,21 +761,90 @@ public class MenuManager */ public void removeSwaps(String withTarget) { - withTarget = Text.standardize(withTarget); + final String target = Text.standardize(withTarget); - Set toRemove = new HashSet<>(); + swaps.keySet().removeIf(e -> e.getTarget().equals(target)); + } - for (ComparableEntry e : swaps.keySet()) - { - if (e.getTarget().equals(withTarget)) - { - toRemove.add(e); - } - } + /** + * Adds to the set of menu entries which when present, will be hidden from the menu + */ + public void addHiddenEntry(String option, String target) + { + option = Text.standardize(option); + target = Text.standardize(target); - for (ComparableEntry entry : toRemove) - { - swaps.remove(entry); - } + ComparableEntry entry = new ComparableEntry(option, target); + + hiddenEntries.add(entry); + } + + public void removeHiddenEntry(String option, String target) + { + option = Text.standardize(option); + target = Text.standardize(target); + + ComparableEntry entry = new ComparableEntry(option, target); + + hiddenEntries.removeIf(entry::equals); + } + + /** + * Adds to the set of menu entries which when present, will be hidden from the menu + * This method will add one with strict option, but not-strict target (contains for target, equals for option) + */ + public void addHiddenEntry(String option) + { + option = Text.standardize(option); + + ComparableEntry entry = new ComparableEntry(option, "", false); + + hiddenEntries.add(entry); + } + + public void removeHiddenEntry(String option) + { + option = Text.standardize(option); + + ComparableEntry entry = new ComparableEntry(option, "", false); + + hiddenEntries.removeIf(entry::equals); + } + + /** + * Adds to the set of hidden entries. + */ + public void addHiddenEntry(String option, String target, boolean strictOption, boolean strictTarget) + { + option = Text.standardize(option); + target = Text.standardize(target); + + ComparableEntry entry = new ComparableEntry(option, target, -1, -1, strictOption, strictTarget); + + hiddenEntries.add(entry); + } + + + public void removeHiddenEntry(String option, String target, boolean strictOption, boolean strictTarget) + { + option = Text.standardize(option); + target = Text.standardize(target); + + ComparableEntry entry = new ComparableEntry(option, target, -1, -1, strictOption, strictTarget); + + hiddenEntries.remove(entry); + } + + /** + * Adds to the set of hidden entries - Pre-baked Abstract entry + */ + public void addHiddenEntry(ComparableEntry entry) + { + hiddenEntries.add(entry); + } + + public void removeHiddenEntry(ComparableEntry entry) + { + hiddenEntries.remove(entry); } } From c5f063ee1b1f13e5c85ca8a1cb5ba7ca7003bf0a Mon Sep 17 00:00:00 2001 From: 7ate9 <7ate9@users.noreply.github.com`> Date: Sat, 8 Jun 2019 23:56:39 -0400 Subject: [PATCH 2/2] menumanager: adds option to hide entries and switched to Collection.removeIf() when removing entries from sets --- .../src/main/java/net/runelite/client/menus/MenuManager.java | 1 - 1 file changed, 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java b/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java index 8af9da478d..0c6350a292 100644 --- a/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java +++ b/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java @@ -824,7 +824,6 @@ public class MenuManager hiddenEntries.add(entry); } - public void removeHiddenEntry(String option, String target, boolean strictOption, boolean strictTarget) { option = Text.standardize(option);