diff --git a/runelite-api/src/main/java/net/runelite/api/Client.java b/runelite-api/src/main/java/net/runelite/api/Client.java index 5f1175fcdd..e53d03ec7f 100644 --- a/runelite-api/src/main/java/net/runelite/api/Client.java +++ b/runelite-api/src/main/java/net/runelite/api/Client.java @@ -593,6 +593,13 @@ public interface Client extends GameEngine */ World[] getWorldList(); + /** + * Create a new menu entry + * @param idx the index to create the menu entry at. Accepts negative indexes eg. -1 inserts at the end. + * @return the newly created menu entry + */ + MenuEntry createMenuEntry(int idx); + /** * Gets an array of currently open right-click menu entries that can be * clicked and activated. diff --git a/runelite-api/src/main/java/net/runelite/api/MenuEntry.java b/runelite-api/src/main/java/net/runelite/api/MenuEntry.java index e28165e603..6891927c4b 100644 --- a/runelite-api/src/main/java/net/runelite/api/MenuEntry.java +++ b/runelite-api/src/main/java/net/runelite/api/MenuEntry.java @@ -24,46 +24,72 @@ */ package net.runelite.api; -import lombok.Data; +import java.util.function.Consumer; /** * A menu entry in a right-click menu. */ -@Data -public class MenuEntry +public interface MenuEntry { /** * The option text added to the menu. (ie. "Walk here", "Use") */ - private String option; + String getOption(); + MenuEntry setOption(String option); + /** * The target of the action. (ie. Item or Actor name) *

* If the option does not apply to any target, this field * will be set to empty string. */ - private String target; + String getTarget(); + MenuEntry setTarget(String target); + /** * An identifier value for the target of the action. */ - private int identifier; + int getIdentifier(); + MenuEntry setIdentifier(int identifier); + /** * The action the entry will trigger. */ - private int type; + MenuAction getType(); + MenuEntry setType(MenuAction type); + /** * An additional parameter for the action. */ - private int param0; + int getParam0(); + MenuEntry setParam0(int param0); + /** * A second additional parameter for the action. */ - private int param1; + int getParam1(); + MenuEntry setParam1(int param1); + /** - * If this field is true and you have single mouse button on and this entry is + * If this is true and you have single mouse button on and this entry is * the top entry the right click menu will not be opened when you left click * * This is used for shift click */ - private boolean forceLeftClick; + boolean isForceLeftClick(); + MenuEntry setForceLeftClick(boolean forceLeftClick); + + /** + * Deprioritized menus are sorted in the menu to be below the other menu entries. + * @return + */ + boolean isDeprioritized(); + void setDeprioritized(boolean deprioritized); + + /** + * Set a callback to be called when this menu option is clicked + * @param callback + * @return + */ + MenuEntry onClick(Consumer callback); } diff --git a/runelite-api/src/main/java/net/runelite/api/events/WidgetMenuOptionClicked.java b/runelite-api/src/main/java/net/runelite/api/events/WidgetMenuOptionClicked.java deleted file mode 100644 index d3a4dda748..0000000000 --- a/runelite-api/src/main/java/net/runelite/api/events/WidgetMenuOptionClicked.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2017, Adam - * 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.api.events; - -import javax.annotation.Nullable; -import lombok.Data; -import net.runelite.api.widgets.WidgetInfo; - -/** - * A MenuManager widget menu was clicked. This event is fired only for MenuManager managed custom menus. - */ -@Data -public class WidgetMenuOptionClicked -{ - /** - * The clicked menu option. - */ - private String menuOption; - /** - * The clicked menu target. - */ - private String menuTarget; - /** - * The WidgetInfo of the widget that was clicked, if available. - */ - @Nullable - private WidgetInfo widget; - /** - * The widget id of the widget that was clicked. - */ - private int widgetId; -} diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLite.java b/runelite-client/src/main/java/net/runelite/client/RuneLite.java index dde04da268..142c4570c3 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLite.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLite.java @@ -326,7 +326,6 @@ public class RuneLite // Add core overlays WidgetOverlay.createOverlays(overlayManager, client).forEach(overlayManager::add); overlayManager.add(worldMapOverlay.get()); - eventBus.register(worldMapOverlay.get()); overlayManager.add(tooltipOverlay.get()); } 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 c6a952239a..2b77f99e13 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 @@ -27,10 +27,10 @@ package net.runelite.client.menus; import com.google.common.base.Preconditions; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.function.Consumer; import javax.inject.Inject; import javax.inject.Singleton; import lombok.extern.slf4j.Slf4j; @@ -38,9 +38,7 @@ import net.runelite.api.Client; import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; import net.runelite.api.events.MenuEntryAdded; -import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.PlayerMenuOptionsChanged; -import net.runelite.api.events.WidgetMenuOptionClicked; import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.Subscribe; @@ -55,7 +53,6 @@ public class MenuManager private static final int IDX_UPPER = 8; private final Client client; - private final EventBus eventBus; //Maps the indexes that are being used to the menu option. private final Map playerMenuIndexMap = new HashMap<>(); @@ -66,7 +63,6 @@ public class MenuManager private MenuManager(Client client, EventBus eventBus) { this.client = client; - this.eventBus = eventBus; eventBus.register(this); } @@ -74,10 +70,12 @@ public class MenuManager * Adds a CustomMenuOption to the list of managed menu options. * * @param customMenuOption The custom menu to add + * @param callback callback to be called when the menu is clicked */ - public void addManagedCustomMenu(WidgetMenuOption customMenuOption) + public void addManagedCustomMenu(WidgetMenuOption customMenuOption, Consumer callback) { managedMenuOptions.put(customMenuOption.getWidgetId(), customMenuOption); + customMenuOption.callback = callback; } /** @@ -122,11 +120,10 @@ public class MenuManager MenuEntry[] menuEntries = client.getMenuEntries(); - MenuEntry[] newMenuEntries = Arrays.copyOf(menuEntries, menuEntries.length + options.size()); // Menu entries are sorted with higher-index entries appearing toward the top of the minimenu, so insert older // managed menu entries at higher indices and work backward for newer entries so newly-added entries appear at // the bottom - int insertIdx = newMenuEntries.length - 1; + int insertIdx = -1; for (WidgetMenuOption currentMenu : options) { // Exit if we've inserted the managed menu entries already @@ -135,16 +132,13 @@ public class MenuManager return; } - MenuEntry menuEntry = new MenuEntry(); - menuEntry.setOption(currentMenu.getMenuOption()); - menuEntry.setParam1(widgetId); - menuEntry.setTarget(currentMenu.getMenuTarget()); - menuEntry.setType(MenuAction.RUNELITE.getId()); - - newMenuEntries[insertIdx--] = menuEntry; + client.createMenuEntry(insertIdx--) + .setOption(currentMenu.getMenuOption()) + .setTarget(currentMenu.getMenuTarget()) + .setType(MenuAction.RUNELITE) + .setParam1(widgetId) + .onClick(currentMenu.callback); } - - client.setMenuEntries(newMenuEntries); } public void addPlayerMenuItem(String menuText) @@ -198,33 +192,6 @@ public class MenuManager addPlayerMenuItem(newIdx, menuText); } - @Subscribe - public void onMenuOptionClicked(MenuOptionClicked event) - { - if (event.getMenuAction() != MenuAction.RUNELITE) - { - return; - } - - int widgetId = event.getParam1(); - Collection options = managedMenuOptions.get(widgetId); - - for (WidgetMenuOption curMenuOption : options) - { - if (curMenuOption.getMenuTarget().equals(event.getMenuTarget()) - && curMenuOption.getMenuOption().equals(event.getMenuOption())) - { - WidgetMenuOptionClicked customMenu = new WidgetMenuOptionClicked(); - customMenu.setMenuOption(event.getMenuOption()); - customMenu.setMenuTarget(event.getMenuTarget()); - customMenu.setWidget(curMenuOption.getWidget()); - customMenu.setWidgetId(curMenuOption.getWidgetId()); - eventBus.post(customMenu); - return; - } - } - } - private void addPlayerMenuItem(int playerOptionIndex, String menuText) { client.getPlayerOptions()[playerOptionIndex] = menuText; diff --git a/runelite-client/src/main/java/net/runelite/client/menus/WidgetMenuOption.java b/runelite-client/src/main/java/net/runelite/client/menus/WidgetMenuOption.java index 1f1a74606b..7727897f3d 100644 --- a/runelite-client/src/main/java/net/runelite/client/menus/WidgetMenuOption.java +++ b/runelite-client/src/main/java/net/runelite/client/menus/WidgetMenuOption.java @@ -25,9 +25,11 @@ package net.runelite.client.menus; import java.awt.Color; +import java.util.function.Consumer; import javax.annotation.Nullable; import lombok.Getter; import lombok.Setter; +import net.runelite.api.MenuEntry; import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.ui.JagexColors; import net.runelite.client.util.ColorUtil; @@ -65,6 +67,8 @@ public final class WidgetMenuOption @Getter private final int widgetId; + Consumer callback; + /** * Creates a menu to be added to right click menus. The menu will only be added if match is found within the menu options * diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java index 70088692c8..bacab9beae 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java @@ -341,8 +341,6 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener @Subscribe public void onMenuEntryAdded(MenuEntryAdded event) { - MenuEntry[] entries = client.getMenuEntries(); - if (event.getActionParam1() == WidgetInfo.BANK_ITEM_CONTAINER.getId() && event.getOption().equals("Examine")) { @@ -357,87 +355,80 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener text += " (" + tagCount + ")"; } - MenuEntry editTags = new MenuEntry(); - editTags.setParam0(event.getActionParam0()); - editTags.setParam1(event.getActionParam1()); - editTags.setTarget(event.getTarget()); - editTags.setOption(text); - editTags.setType(MenuAction.RUNELITE.getId()); - editTags.setIdentifier(event.getIdentifier()); - entries = Arrays.copyOf(entries, entries.length + 1); - entries[entries.length - 1] = editTags; - client.setMenuEntries(entries); + client.createMenuEntry(-1) + .setParam0(event.getActionParam0()) + .setParam1(event.getActionParam1()) + .setTarget(event.getTarget()) + .setOption(text) + .setType(MenuAction.RUNELITE) + .setIdentifier(event.getIdentifier()) + .onClick(this::editTags); } tabInterface.handleAdd(event); } + private void editTags(MenuEntry entry) + { + int inventoryIndex = entry.getParam0(); + ItemContainer bankContainer = client.getItemContainer(InventoryID.BANK); + if (bankContainer == null) + { + return; + } + Item[] items = bankContainer.getItems(); + if (inventoryIndex < 0 || inventoryIndex >= items.length) + { + return; + } + Item item = bankContainer.getItems()[inventoryIndex]; + if (item == null) + { + return; + } + + int itemId = item.getId(); + ItemComposition itemComposition = itemManager.getItemComposition(itemId); + String name = itemComposition.getName(); + + // Get both tags and vartags and append * to end of vartags name + Collection tags = tagManager.getTags(itemId, false); + tagManager.getTags(itemId, true).stream() + .map(i -> i + "*") + .forEach(tags::add); + + String initialValue = Text.toCSV(tags); + + chatboxPanelManager.openTextInput(name + " tags:
(append " + VAR_TAG_SUFFIX + " for variation tag)") + .addCharValidator(FILTERED_CHARS) + .value(initialValue) + .onDone((Consumer) (newValue) -> + clientThread.invoke(() -> + { + // Split inputted tags to vartags (ending with *) and regular tags + final Collection newTags = new ArrayList<>(Text.fromCSV(newValue.toLowerCase())); + final Collection newVarTags = new ArrayList<>(newTags).stream().filter(s -> s.endsWith(VAR_TAG_SUFFIX)).map(s -> + { + newTags.remove(s); + return s.substring(0, s.length() - VAR_TAG_SUFFIX.length()); + }).collect(Collectors.toList()); + + // And save them + tagManager.setTagString(itemId, Text.toCSV(newTags), false); + tagManager.setTagString(itemId, Text.toCSV(newVarTags), true); + + // Check both previous and current tags in case the tag got removed in new tags or in case + // the tag got added in new tags + tabInterface.updateTabIfActive(Text.fromCSV(initialValue.toLowerCase().replaceAll(Pattern.quote(VAR_TAG_SUFFIX), ""))); + tabInterface.updateTabIfActive(Text.fromCSV(newValue.toLowerCase().replaceAll(Pattern.quote(VAR_TAG_SUFFIX), ""))); + })) + .build(); + } + @Subscribe public void onMenuOptionClicked(MenuOptionClicked event) { - if (event.getParam1() == WidgetInfo.BANK_ITEM_CONTAINER.getId() - && event.getMenuAction() == MenuAction.RUNELITE - && event.getMenuOption().startsWith(EDIT_TAGS_MENU_OPTION)) - { - event.consume(); - int inventoryIndex = event.getParam0(); - ItemContainer bankContainer = client.getItemContainer(InventoryID.BANK); - if (bankContainer == null) - { - return; - } - Item[] items = bankContainer.getItems(); - if (inventoryIndex < 0 || inventoryIndex >= items.length) - { - return; - } - Item item = bankContainer.getItems()[inventoryIndex]; - if (item == null) - { - return; - } - - int itemId = item.getId(); - ItemComposition itemComposition = itemManager.getItemComposition(itemId); - String name = itemComposition.getName(); - - // Get both tags and vartags and append * to end of vartags name - Collection tags = tagManager.getTags(itemId, false); - tagManager.getTags(itemId, true).stream() - .map(i -> i + "*") - .forEach(tags::add); - - String initialValue = Text.toCSV(tags); - - chatboxPanelManager.openTextInput(name + " tags:
(append " + VAR_TAG_SUFFIX + " for variation tag)") - .addCharValidator(FILTERED_CHARS) - .value(initialValue) - .onDone((Consumer) (newValue) -> - clientThread.invoke(() -> - { - // Split inputted tags to vartags (ending with *) and regular tags - final Collection newTags = new ArrayList<>(Text.fromCSV(newValue.toLowerCase())); - final Collection newVarTags = new ArrayList<>(newTags).stream().filter(s -> s.endsWith(VAR_TAG_SUFFIX)).map(s -> - { - newTags.remove(s); - return s.substring(0, s.length() - VAR_TAG_SUFFIX.length()); - }).collect(Collectors.toList()); - - // And save them - tagManager.setTagString(itemId, Text.toCSV(newTags), false); - tagManager.setTagString(itemId, Text.toCSV(newVarTags), true); - - // Check both previous and current tags in case the tag got removed in new tags or in case - // the tag got added in new tags - tabInterface.updateTabIfActive(Text.fromCSV(initialValue.toLowerCase().replaceAll(Pattern.quote(VAR_TAG_SUFFIX), ""))); - tabInterface.updateTabIfActive(Text.fromCSV(newValue.toLowerCase().replaceAll(Pattern.quote(VAR_TAG_SUFFIX), ""))); - })) - .build(); - } - else - { - tabInterface.handleClick(event); - } + tabInterface.handleClick(event); } @Subscribe diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabInterface.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabInterface.java index 04c41c9d1b..7a1954e656 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabInterface.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabInterface.java @@ -618,38 +618,32 @@ public class TabInterface return; } - MenuEntry[] entries = client.getMenuEntries(); if (activeTab != null && event.getActionParam1() == WidgetInfo.BANK_ITEM_CONTAINER.getId() && event.getOption().equals("Examine")) { - entries = createMenuEntry(event, REMOVE_TAG + " (" + activeTab.getTag() + ")", event.getTarget(), entries); - client.setMenuEntries(entries); + createMenuEntry(event, REMOVE_TAG + " (" + activeTab.getTag() + ")", event.getTarget()); } else if (event.getActionParam1() == WidgetInfo.BANK_DEPOSIT_INVENTORY.getId() && event.getOption().equals("Deposit inventory")) { - entries = createMenuEntry(event, TAG_INVENTORY, event.getTarget(), entries); + createMenuEntry(event, TAG_INVENTORY, event.getTarget()); if (activeTab != null) { - entries = createMenuEntry(event, TAG_INVENTORY, ColorUtil.wrapWithColorTag(activeTab.getTag(), HILIGHT_COLOR), entries); + createMenuEntry(event, TAG_INVENTORY, ColorUtil.wrapWithColorTag(activeTab.getTag(), HILIGHT_COLOR)); } - - client.setMenuEntries(entries); } else if (event.getActionParam1() == WidgetInfo.BANK_DEPOSIT_EQUIPMENT.getId() && event.getOption().equals("Deposit worn items")) { - entries = createMenuEntry(event, TAG_GEAR, event.getTarget(), entries); + createMenuEntry(event, TAG_GEAR, event.getTarget()); if (activeTab != null) { - entries = createMenuEntry(event, TAG_GEAR, ColorUtil.wrapWithColorTag(activeTab.getTag(), HILIGHT_COLOR), entries); + createMenuEntry(event, TAG_GEAR, ColorUtil.wrapWithColorTag(activeTab.getTag(), HILIGHT_COLOR)); } - - client.setMenuEntries(entries); } } @@ -773,7 +767,6 @@ public class TabInterface { entry.setOption(TAG_SEARCH + Text.removeTags(entry.getTarget()) + (shiftDown ? VAR_TAG_SUFFIX : "")); entry.setTarget(draggedWidget.getName()); - client.setMenuEntries(entries); } if (entry.getOption().equals(SCROLL_UP)) @@ -1195,17 +1188,14 @@ public class TabInterface searchButtonBackground.setSpriteId(SpriteID.EQUIPMENT_SLOT_TILE); } - private static MenuEntry[] createMenuEntry(MenuEntryAdded event, String option, String target, MenuEntry[] entries) + private void createMenuEntry(MenuEntryAdded event, String option, String target) { - final MenuEntry entry = new MenuEntry(); - entry.setParam0(event.getActionParam0()); - entry.setParam1(event.getActionParam1()); - entry.setTarget(target); - entry.setOption(option); - entry.setType(MenuAction.RUNELITE.getId()); - entry.setIdentifier(event.getIdentifier()); - entries = Arrays.copyOf(entries, entries.length + 1); - entries[entries.length - 1] = entry; - return entries; + client.createMenuEntry(-1) + .setParam0(event.getActionParam0()) + .setParam1(event.getActionParam1()) + .setTarget(target) + .setOption(option) + .setType(MenuAction.RUNELITE) + .setIdentifier(event.getIdentifier()); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/camera/CameraPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/camera/CameraPlugin.java index dfb29e8950..21c495b603 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/camera/CameraPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/camera/CameraPlugin.java @@ -294,7 +294,7 @@ public class CameraPlugin extends Plugin implements KeyListener, MouseListener { for (MenuEntry menuEntry : menuEntries) { - MenuAction action = MenuAction.of(menuEntry.getType()); + MenuAction action = menuEntry.getType(); switch (action) { case CANCEL: diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/chathistory/ChatHistoryPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/chathistory/ChatHistoryPlugin.java index ad6530a2e7..2b11c3318b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/chathistory/ChatHistoryPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/chathistory/ChatHistoryPlugin.java @@ -25,7 +25,6 @@ */ package net.runelite.client.plugins.chathistory; -import com.google.common.base.Strings; import com.google.common.collect.EvictingQueue; import com.google.inject.Provides; import java.awt.Toolkit; @@ -83,8 +82,6 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener private Queue messageQueue; private Deque friends; - private String currentMessage = null; - @Inject private Client client; @@ -121,7 +118,6 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener messageQueue = null; friends.clear(); friends = null; - currentMessage = null; keyManager.unregisterKeyListener(this); } @@ -195,7 +191,7 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener // Use second entry as first one can be walk here with transparent chatbox final MenuEntry entry = event.getMenuEntries()[event.getMenuEntries().length - 2]; - if (entry.getType() != MenuAction.CC_OP_LOW_PRIORITY.getId() && entry.getType() != MenuAction.RUNELITE.getId()) + if (entry.getType() != MenuAction.CC_OP_LOW_PRIORITY && entry.getType() != MenuAction.RUNELITE) { return; } @@ -236,16 +232,17 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener return; } - currentMessage = messageContents.getText(); + String currentMessage = messageContents.getText(); - final MenuEntry menuEntry = new MenuEntry(); - menuEntry.setOption(COPY_TO_CLIPBOARD); - menuEntry.setTarget(entry.getTarget()); - menuEntry.setType(MenuAction.RUNELITE.getId()); - menuEntry.setParam0(entry.getParam0()); - menuEntry.setParam1(entry.getParam1()); - menuEntry.setIdentifier(entry.getIdentifier()); - client.setMenuEntries(ArrayUtils.insert(1, client.getMenuEntries(), menuEntry)); + client.createMenuEntry(1) + .setOption(COPY_TO_CLIPBOARD) + .setTarget(entry.getTarget()) + .setType(MenuAction.RUNELITE) + .onClick(e -> + { + final StringSelection stringSelection = new StringSelection(Text.removeTags(currentMessage)); + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null); + }); } @Subscribe @@ -258,11 +255,6 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener { clearChatboxHistory(ChatboxTab.of(event.getParam1())); } - else if (COPY_TO_CLIPBOARD.equals(menuOption) && !Strings.isNullOrEmpty(currentMessage)) - { - final StringSelection stringSelection = new StringSelection(Text.removeTags(currentMessage)); - Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null); - } } @Subscribe @@ -279,10 +271,8 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener return; } - final MenuEntry clearEntry = new MenuEntry(); - clearEntry.setTarget(""); - clearEntry.setType(MenuAction.RUNELITE_HIGH_PRIORITY.getId()); - clearEntry.setParam0(entry.getActionParam0()); + final MenuEntry clearEntry = client.createMenuEntry(-2) + .setType(MenuAction.RUNELITE_HIGH_PRIORITY); clearEntry.setParam1(entry.getActionParam1()); final StringBuilder optionBuilder = new StringBuilder(); @@ -299,9 +289,6 @@ public class ChatHistoryPlugin extends Plugin implements KeyListener optionBuilder.append(CLEAR_HISTORY); clearEntry.setOption(optionBuilder.toString()); - - final MenuEntry[] menuEntries = client.getMenuEntries(); - client.setMenuEntries(ArrayUtils.insert(menuEntries.length - 1, menuEntries, clearEntry)); } private void clearMessageQueue(ChatboxTab tab) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPlugin.java index b9cc30c8dd..a1588594ab 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPlugin.java @@ -488,7 +488,6 @@ public class DevToolsPlugin extends Plugin } entry.setTarget(entry.getTarget() + " " + ColorUtil.prependColorTag("(" + info + ")", JagexColors.MENU_TARGET)); - client.setMenuEntries(entries); } } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/WidgetInspector.java b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/WidgetInspector.java index 2f361bc99b..6e27c99a35 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/WidgetInspector.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/WidgetInspector.java @@ -487,7 +487,7 @@ class WidgetInspector extends DevToolsFrame client.setSpellSelected(false); ev.consume(); - Object target = getWidgetOrWidgetItemForMenuOption(ev.getMenuAction().getId(), ev.getParam0(), ev.getParam1()); + Object target = getWidgetOrWidgetItemForMenuOption(ev.getMenuAction(), ev.getParam0(), ev.getParam1()); if (target == null) { return; @@ -516,8 +516,8 @@ class WidgetInspector extends DevToolsFrame for (int i = 0; i < menuEntries.length; i++) { MenuEntry entry = menuEntries[i]; - if (entry.getType() != MenuAction.ITEM_USE_ON_WIDGET.getId() - && entry.getType() != MenuAction.SPELL_CAST_ON_WIDGET.getId()) + if (entry.getType() != MenuAction.ITEM_USE_ON_WIDGET + && entry.getType() != MenuAction.SPELL_CAST_ON_WIDGET) { continue; } @@ -532,8 +532,6 @@ class WidgetInspector extends DevToolsFrame entry.setTarget(ColorUtil.wrapWithColorTag(name, color)); } - - client.setMenuEntries(menuEntries); } Color colorForWidget(int index, int length) @@ -543,9 +541,9 @@ class WidgetInspector extends DevToolsFrame return Color.getHSBColor(h, 1, 1); } - Object getWidgetOrWidgetItemForMenuOption(int type, int param0, int param1) + Object getWidgetOrWidgetItemForMenuOption(MenuAction type, int param0, int param1) { - if (type == MenuAction.SPELL_CAST_ON_WIDGET.getId()) + if (type == MenuAction.SPELL_CAST_ON_WIDGET) { Widget w = client.getWidget(param1); if (param0 != -1) @@ -555,7 +553,7 @@ class WidgetInspector extends DevToolsFrame return w; } - else if (type == MenuAction.ITEM_USE_ON_WIDGET.getId()) + else if (type == MenuAction.ITEM_USE_ON_WIDGET) { Widget w = client.getWidget(param1); return w.getWidgetItem(param0); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java index db87e799a0..c274b74834 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/friendnotes/FriendNotesPlugin.java @@ -28,7 +28,6 @@ package net.runelite.client.plugins.friendnotes; import com.google.common.base.Strings; -import com.google.common.collect.ObjectArrays; import com.google.inject.Provides; import java.awt.Color; import java.awt.image.BufferedImage; @@ -43,12 +42,10 @@ import net.runelite.api.GameState; import net.runelite.api.Ignore; import net.runelite.api.IndexedSprite; import net.runelite.api.MenuAction; -import net.runelite.api.MenuEntry; import net.runelite.api.Nameable; import net.runelite.api.ScriptID; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.MenuEntryAdded; -import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.NameableNameChanged; import net.runelite.api.events.RemovedFriend; import net.runelite.api.events.ScriptCallbackEvent; @@ -245,16 +242,31 @@ public class FriendNotesPlugin extends Plugin setHoveredFriend(Text.toJagexName(Text.removeTags(event.getTarget()))); // Build "Add Note" or "Edit Note" menu entry - final MenuEntry addNote = new MenuEntry(); - addNote.setOption(hoveredFriend == null || hoveredFriend.getNote() == null ? ADD_NOTE : EDIT_NOTE); - addNote.setType(MenuAction.RUNELITE.getId()); - addNote.setTarget(event.getTarget()); //Preserve color codes here - addNote.setParam0(event.getActionParam0()); - addNote.setParam1(event.getActionParam1()); + client.createMenuEntry(-1) + .setOption(hoveredFriend == null || hoveredFriend.getNote() == null ? ADD_NOTE : EDIT_NOTE) + .setType(MenuAction.RUNELITE) + .setTarget(event.getTarget()) //Preserve color codes here + .onClick(e -> + { + //Friends have color tags + final String sanitizedTarget = Text.toJagexName(Text.removeTags(e.getTarget())); + final String note = getFriendNote(sanitizedTarget); - // Add menu entry - final MenuEntry[] menuEntries = ObjectArrays.concat(client.getMenuEntries(), addNote); - client.setMenuEntries(menuEntries); + // Open the new chatbox input dialog + chatboxPanelManager.openTextInput(String.format(NOTE_PROMPT_FORMAT, sanitizedTarget, CHARACTER_LIMIT)) + .value(Strings.nullToEmpty(note)) + .onDone((content) -> + { + if (content == null) + { + return; + } + + content = Text.removeTags(content).trim(); + log.debug("Set note for '{}': '{}'", sanitizedTarget, content); + setFriendNote(sanitizedTarget, content); + }).build(); + }); } else if (hoveredFriend != null) { @@ -262,46 +274,6 @@ public class FriendNotesPlugin extends Plugin } } - @Subscribe - public void onMenuOptionClicked(MenuOptionClicked event) - { - final int groupId = WidgetInfo.TO_GROUP(event.getParam1()); - - if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() || groupId == WidgetInfo.IGNORE_LIST.getGroupId()) - { - if (Strings.isNullOrEmpty(event.getMenuTarget())) - { - return; - } - - // Handle clicks on "Add Note" or "Edit Note" - if (event.getMenuOption().equals(ADD_NOTE) || event.getMenuOption().equals(EDIT_NOTE)) - { - event.consume(); - - //Friends have color tags - final String sanitizedTarget = Text.toJagexName(Text.removeTags(event.getMenuTarget())); - final String note = getFriendNote(sanitizedTarget); - - // Open the new chatbox input dialog - chatboxPanelManager.openTextInput(String.format(NOTE_PROMPT_FORMAT, sanitizedTarget, CHARACTER_LIMIT)) - .value(Strings.nullToEmpty(note)) - .onDone((content) -> - { - if (content == null) - { - return; - } - - content = Text.removeTags(content).trim(); - log.debug("Set note for '{}': '{}'", sanitizedTarget, content); - setFriendNote(sanitizedTarget, content); - }).build(); - } - } - - } - @Subscribe public void onNameableNameChanged(NameableNameChanged event) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java index 6075b23e11..697bf0d43b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grandexchange/GrandExchangePlugin.java @@ -574,8 +574,7 @@ public class GrandExchangePlugin extends Plugin case WidgetID.GRAND_EXCHANGE_INVENTORY_GROUP_ID: case WidgetID.SHOP_INVENTORY_GROUP_ID: menuEntry.setOption(SEARCH_GRAND_EXCHANGE); - menuEntry.setType(MenuAction.RUNELITE.getId()); - client.setMenuEntries(entries); + menuEntry.setType(MenuAction.RUNELITE); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java index 655ae55fc7..6490f4d8d8 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java @@ -115,14 +115,6 @@ public class GroundItemsPlugin extends Plugin static final int MAX_QUANTITY = 65535; // ItemID for coins private static final int COINS = ItemID.COINS_995; - // Ground item menu options - private static final int FIRST_OPTION = MenuAction.GROUND_ITEM_FIRST_OPTION.getId(); - private static final int SECOND_OPTION = MenuAction.GROUND_ITEM_SECOND_OPTION.getId(); - private static final int THIRD_OPTION = MenuAction.GROUND_ITEM_THIRD_OPTION.getId(); // this is Take - private static final int FOURTH_OPTION = MenuAction.GROUND_ITEM_FOURTH_OPTION.getId(); - private static final int FIFTH_OPTION = MenuAction.GROUND_ITEM_FIFTH_OPTION.getId(); - private static final int EXAMINE_ITEM = MenuAction.EXAMINE_ITEM_GROUND.getId(); - private static final int CAST_ON_ITEM = MenuAction.SPELL_CAST_ON_GROUND_ITEM.getId(); private static final String TELEGRAB_TEXT = ColorUtil.wrapWithColorTag("Telekinetic Grab", Color.GREEN) + ColorUtil.prependColorTag(" -> ", Color.WHITE); @@ -344,9 +336,10 @@ public class GroundItemsPlugin extends Plugin { MenuEntry menuEntry = menuEntries[i]; - int menuType = menuEntry.getType(); - if (menuType == FIRST_OPTION || menuType == SECOND_OPTION || menuType == THIRD_OPTION - || menuType == FOURTH_OPTION || menuType == FIFTH_OPTION || menuType == EXAMINE_ITEM) + MenuAction menuType = menuEntry.getType(); + if (menuType == MenuAction.GROUND_ITEM_FIRST_OPTION || menuType == MenuAction.GROUND_ITEM_SECOND_OPTION + || menuType == MenuAction.GROUND_ITEM_THIRD_OPTION || menuType == MenuAction.GROUND_ITEM_FOURTH_OPTION + || menuType == MenuAction.GROUND_ITEM_FIFTH_OPTION || menuType == MenuAction.SPELL_CAST_ON_GROUND_ITEM) { for (MenuEntryWithCount entryWCount : newEntries) { @@ -490,8 +483,8 @@ public class GroundItemsPlugin extends Plugin { if (config.itemHighlightMode() == ItemHighlightMode.MENU || config.itemHighlightMode() == ItemHighlightMode.BOTH) { - final boolean telegrabEntry = event.getOption().equals("Cast") && event.getTarget().startsWith(TELEGRAB_TEXT) && event.getType() == CAST_ON_ITEM; - if (!(event.getOption().equals("Take") && event.getType() == THIRD_OPTION) && !telegrabEntry) + final boolean telegrabEntry = event.getOption().equals("Cast") && event.getTarget().startsWith(TELEGRAB_TEXT) && event.getType() == MenuAction.SPELL_CAST_ON_GROUND_ITEM.getId(); + if (!(event.getOption().equals("Take") && event.getType() == MenuAction.GROUND_ITEM_THIRD_OPTION.getId()) && !telegrabEntry) { return; } @@ -548,8 +541,6 @@ public class GroundItemsPlugin extends Plugin { lastEntry.setTarget(lastEntry.getTarget() + " (" + quantity + ")"); } - - client.setMenuEntries(menuEntries); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerPlugin.java index 850f383439..e8de79d73e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerPlugin.java @@ -30,7 +30,6 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.google.inject.Provides; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -44,13 +43,11 @@ import net.runelite.api.Client; import net.runelite.api.GameState; import net.runelite.api.KeyCode; import net.runelite.api.MenuAction; -import net.runelite.api.MenuEntry; import net.runelite.api.Tile; import net.runelite.api.coords.LocalPoint; import net.runelite.api.coords.WorldPoint; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.MenuEntryAdded; -import net.runelite.api.events.MenuOptionClicked; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.Subscribe; @@ -243,48 +240,34 @@ public class GroundMarkerPlugin extends Plugin final GroundMarkerPoint point = new GroundMarkerPoint(regionId, worldPoint.getRegionX(), worldPoint.getRegionY(), client.getPlane(), null, null); final boolean exists = getPoints(regionId).contains(point); - MenuEntry[] menuEntries = client.getMenuEntries(); - menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + (exists ? 2 : 1)); - - MenuEntry mark = menuEntries[menuEntries.length - 1] = new MenuEntry(); - mark.setOption(exists ? UNMARK : MARK); - mark.setTarget(event.getTarget()); - mark.setType(MenuAction.RUNELITE.getId()); + client.createMenuEntry(-1) + .setOption(exists ? UNMARK : MARK) + .setTarget(event.getTarget()) + .setType(MenuAction.RUNELITE) + .onClick(e -> + { + Tile target = client.getSelectedSceneTile(); + if (target != null) + { + markTile(target.getLocalLocation()); + } + }); if (exists) { - MenuEntry label = menuEntries[menuEntries.length - 2] = new MenuEntry(); - label.setOption(LABEL); - label.setTarget(event.getTarget()); - label.setType(MenuAction.RUNELITE.getId()); + client.createMenuEntry(-2) + .setOption(LABEL) + .setTarget(event.getTarget()) + .setType(MenuAction.RUNELITE) + .onClick(e -> + { + Tile target = client.getSelectedSceneTile(); + if (target != null) + { + labelTile(target); + } + }); } - - client.setMenuEntries(menuEntries); - } - } - - @Subscribe - public void onMenuOptionClicked(MenuOptionClicked event) - { - if (event.getMenuAction().getId() != MenuAction.RUNELITE.getId()) - { - return; - } - - Tile target = client.getSelectedSceneTile(); - if (target == null) - { - return; - } - - final String option = event.getMenuOption(); - if (option.equals(MARK) || option.equals(UNMARK)) - { - markTile(target.getLocalLocation()); - } - else if (option.equals(LABEL)) - { - labelTile(target); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerSharingManager.java b/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerSharingManager.java index d311a51319..a7661ff202 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerSharingManager.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/groundmarkers/GroundMarkerSharingManager.java @@ -45,11 +45,10 @@ import javax.inject.Inject; import lombok.extern.slf4j.Slf4j; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; -import net.runelite.api.events.WidgetMenuOptionClicked; +import net.runelite.api.MenuEntry; import static net.runelite.api.widgets.WidgetInfo.MINIMAP_WORLDMAP_OPTIONS; import net.runelite.client.chat.ChatMessageManager; import net.runelite.client.chat.QueuedMessage; -import net.runelite.client.eventbus.Subscribe; import net.runelite.client.game.chatbox.ChatboxPanelManager; import net.runelite.client.menus.MenuManager; import net.runelite.client.menus.WidgetMenuOption; @@ -82,13 +81,13 @@ class GroundMarkerSharingManager void addImportExportMenuOptions() { - menuManager.addManagedCustomMenu(EXPORT_MARKERS_OPTION); - menuManager.addManagedCustomMenu(IMPORT_MARKERS_OPTION); + menuManager.addManagedCustomMenu(EXPORT_MARKERS_OPTION, this::exportGroundMarkers); + menuManager.addManagedCustomMenu(IMPORT_MARKERS_OPTION, this::promptForImport); } void addClearMenuOption() { - menuManager.addManagedCustomMenu(CLEAR_MARKERS_OPTION); + menuManager.addManagedCustomMenu(CLEAR_MARKERS_OPTION, this::promptForClear); } void removeMenuOptions() @@ -98,36 +97,7 @@ class GroundMarkerSharingManager menuManager.removeManagedCustomMenu(CLEAR_MARKERS_OPTION); } - private boolean widgetMenuClickedEquals(final WidgetMenuOptionClicked event, final WidgetMenuOption target) - { - return event.getMenuTarget().equals(target.getMenuTarget()) && - event.getMenuOption().equals(target.getMenuOption()); - } - - @Subscribe - public void onWidgetMenuOptionClicked(WidgetMenuOptionClicked event) - { - // ensure that the option clicked is the export markers option - if (event.getWidget() != MINIMAP_WORLDMAP_OPTIONS) - { - return; - } - - if (widgetMenuClickedEquals(event, EXPORT_MARKERS_OPTION)) - { - exportGroundMarkers(); - } - else if (widgetMenuClickedEquals(event, IMPORT_MARKERS_OPTION)) - { - promptForImport(); - } - else if (widgetMenuClickedEquals(event, CLEAR_MARKERS_OPTION)) - { - promptForClear(); - } - } - - private void exportGroundMarkers() + private void exportGroundMarkers(MenuEntry menuEntry) { int[] regions = client.getMapRegions(); if (regions == null) @@ -156,7 +126,7 @@ class GroundMarkerSharingManager sendChatMessage(activePoints.size() + " ground markers were copied to your clipboard."); } - private void promptForImport() + private void promptForImport(MenuEntry menuEntry) { final String clipboardText; try @@ -244,7 +214,7 @@ class GroundMarkerSharingManager sendChatMessage(importPoints.size() + " ground markers were imported from the clipboard."); } - private void promptForClear() + private void promptForClear(MenuEntry entry) { int[] regions = client.getMapRegions(); if (regions == null) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePlugin.java index 95f12ec821..6123055d1c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/hiscore/HiscorePlugin.java @@ -24,7 +24,6 @@ */ package net.runelite.client.plugins.hiscore; -import com.google.common.collect.ObjectArrays; import com.google.inject.Provides; import java.awt.image.BufferedImage; import java.util.EnumSet; @@ -39,7 +38,6 @@ import net.runelite.api.ChatMessageType; import net.runelite.api.Client; import net.runelite.api.IconID; import net.runelite.api.MenuAction; -import net.runelite.api.MenuEntry; import net.runelite.api.Player; import net.runelite.api.WorldType; import net.runelite.api.events.ChatMessage; @@ -59,7 +57,6 @@ import net.runelite.client.ui.NavigationButton; import net.runelite.client.util.ImageUtil; import net.runelite.client.util.Text; import net.runelite.http.api.hiscore.HiscoreEndpoint; -import org.apache.commons.lang3.ArrayUtils; @PluginDescriptor( name = "HiScore", @@ -169,46 +166,37 @@ public class HiscorePlugin extends Plugin || groupId == WidgetID.GROUP_IRON_GROUP_ID && (option.equals("Add friend") || option.equals("Remove friend") || option.equals("Remove ignore")) ) { - final MenuEntry lookup = new MenuEntry(); - lookup.setOption(LOOKUP); - lookup.setTarget(event.getTarget()); - lookup.setType(MenuAction.RUNELITE.getId()); - lookup.setParam0(event.getActionParam0()); - lookup.setParam1(event.getActionParam1()); - lookup.setIdentifier(event.getIdentifier()); - - insertMenuEntry(lookup, client.getMenuEntries()); + client.createMenuEntry(-2) + .setOption(LOOKUP) + .setTarget(event.getTarget()) + .setType(MenuAction.RUNELITE) + .setIdentifier(event.getIdentifier()) + .onClick(e -> + { + // Determine proper endpoint from player name. + // TODO: look at target's world and determine if tournament/dmm endpoint should be used instead. + HiscoreEndpoint endpoint = findHiscoreEndpointFromPlayerName(e.getTarget()); + String target = Text.removeTags(e.getTarget()); + lookupPlayer(target, endpoint); + }); } } @Subscribe public void onMenuOptionClicked(MenuOptionClicked event) { - if ((event.getMenuAction() == MenuAction.RUNELITE || event.getMenuAction() == MenuAction.RUNELITE_PLAYER) - && event.getMenuOption().equals(LOOKUP)) + if (event.getMenuAction() == MenuAction.RUNELITE_PLAYER && event.getMenuOption().equals(LOOKUP)) { - final String target; - HiscoreEndpoint endpoint; - if (event.getMenuAction() == MenuAction.RUNELITE_PLAYER) + // The player id is included in the event, so we can use that to get the player name, + // which avoids having to parse out the combat level and any icons preceding the name. + Player player = client.getCachedPlayers()[event.getId()]; + if (player == null) { - // The player id is included in the event, so we can use that to get the player name, - // which avoids having to parse out the combat level and any icons preceding the name. - Player player = client.getCachedPlayers()[event.getId()]; - if (player == null) - { - return; - } + return; + } - endpoint = getWorldEndpoint(); - target = player.getName(); - } - else - { - // Determine proper endpoint from player name. - // TODO: look at target's world and determine if tournament/dmm endpoint should be used instead. - endpoint = findHiscoreEndpointFromPlayerName(event.getMenuTarget()); - target = Text.removeTags(event.getMenuTarget()); - } + String target = player.getName(); + HiscoreEndpoint endpoint = getWorldEndpoint(); lookupPlayer(target, endpoint); } @@ -236,14 +224,6 @@ public class HiscorePlugin extends Plugin localHiscoreEndpoint = findHiscoreEndpointFromLocalPlayer(); } - private void insertMenuEntry(MenuEntry newEntry, MenuEntry[] entries) - { - MenuEntry[] newMenu = ObjectArrays.concat(entries, newEntry); - int menuEntryCount = newMenu.length; - ArrayUtils.swap(newMenu, menuEntryCount - 1, menuEntryCount - 2); - client.setMenuEntries(newMenu); - } - private void lookupPlayer(String playerName, HiscoreEndpoint endpoint) { SwingUtilities.invokeLater(() -> diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/InstanceMapPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/InstanceMapPlugin.java index f5cc4b6a51..8ed901350a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/InstanceMapPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/instancemap/InstanceMapPlugin.java @@ -27,7 +27,6 @@ package net.runelite.client.plugins.instancemap; import com.google.inject.Binder; import javax.inject.Inject; import net.runelite.api.events.GameStateChanged; -import net.runelite.api.events.WidgetMenuOptionClicked; import static net.runelite.api.widgets.WidgetInfo.MINIMAP_WORLDMAP_OPTIONS; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.input.KeyManager; @@ -72,7 +71,17 @@ public class InstanceMapPlugin extends Plugin private void addCustomOptions() { - menuManager.addManagedCustomMenu(openMapOption); + menuManager.addManagedCustomMenu(openMapOption, entry -> + { + if (overlay.isMapShown()) + { + closeMap(); + } + else + { + showMap(); + } + }); } private void removeCustomOptions() @@ -107,32 +116,6 @@ public class InstanceMapPlugin extends Plugin overlay.onGameStateChange(event); } - private boolean clickedOptionEquals(WidgetMenuOptionClicked event, WidgetMenuOption widgetMenuOption) - { - return event.getMenuOption().equals(widgetMenuOption.getMenuOption()) && event.getMenuTarget().equals(widgetMenuOption.getMenuTarget()); - } - - @Subscribe - public void onWidgetMenuOptionClicked(WidgetMenuOptionClicked event) - { - if (event.getWidget() != MINIMAP_WORLDMAP_OPTIONS) - { - return; - } - - if (clickedOptionEquals(event, openMapOption)) - { - if (overlay.isMapShown()) - { - closeMap(); - } - else - { - showMap(); - } - } - } - public void showMap() { overlay.setShowMap(true); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/interacthighlight/InteractHighlightOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/interacthighlight/InteractHighlightOverlay.java index a5dd9c95da..0a14053e36 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/interacthighlight/InteractHighlightOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/interacthighlight/InteractHighlightOverlay.java @@ -79,7 +79,7 @@ class InteractHighlightOverlay extends Overlay } MenuEntry top = menuEntries[menuEntries.length - 1]; - MenuAction menuAction = MenuAction.of(top.getType()); + MenuAction menuAction = top.getType(); switch (menuAction) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java index cdbf26a845..d588ed42aa 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java @@ -28,14 +28,13 @@ import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; import com.google.inject.Provides; import java.awt.Color; +import java.util.Arrays; import java.util.List; import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; import net.runelite.api.events.MenuOpened; -import net.runelite.api.events.MenuOptionClicked; -import net.runelite.api.events.WidgetMenuOptionClicked; import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.Subscribe; @@ -46,7 +45,6 @@ import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.util.ColorUtil; -import net.runelite.client.util.Text; @PluginDescriptor( name = "Inventory Tags", @@ -157,44 +155,11 @@ public class InventoryTagsPlugin extends Plugin } } - @Subscribe - public void onWidgetMenuOptionClicked(final WidgetMenuOptionClicked event) - { - if (event.getWidget() == WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB - || event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB - || event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB) - { - editorMode = event.getMenuOption().equals(CONFIGURE) && Text.removeTags(event.getMenuTarget()).equals(MENU_TARGET); - refreshInventoryMenuOptions(); - } - } - - @Subscribe - public void onMenuOptionClicked(final MenuOptionClicked event) - { - if (event.getMenuAction() != MenuAction.RUNELITE) - { - return; - } - - final String selectedMenu = Text.removeTags(event.getMenuTarget()); - - if (event.getMenuOption().equals(MENU_SET)) - { - setTag(event.getId(), selectedMenu); - } - else if (event.getMenuOption().equals(MENU_REMOVE)) - { - unsetTag(event.getId()); - } - } - @Subscribe public void onMenuOpened(final MenuOpened event) { final MenuEntry firstEntry = event.getFirstEntry(); - - if (firstEntry == null) + if (firstEntry == null || !editorMode) { return; } @@ -202,7 +167,7 @@ public class InventoryTagsPlugin extends Plugin final int widgetId = firstEntry.getParam1(); // Inventory item menu - if (widgetId == WidgetInfo.INVENTORY.getId() && editorMode) + if (widgetId == WidgetInfo.INVENTORY.getId()) { int itemId = firstEntry.getIdentifier(); @@ -211,26 +176,30 @@ public class InventoryTagsPlugin extends Plugin return; } - MenuEntry[] menuList = new MenuEntry[GROUPS.size() + 1]; - int num = 0; - - // preserve the 'Cancel' option as the client will reuse the first entry for Cancel and only resets option/action - menuList[num++] = event.getMenuEntries()[0]; + // Set menu to only be Cancel + client.setMenuEntries(Arrays.copyOf(client.getMenuEntries(), 1)); for (final String groupName : GROUPS) { final String group = getTag(itemId); - final MenuEntry newMenu = new MenuEntry(); final Color color = getGroupNameColor(groupName); - newMenu.setOption(groupName.equals(group) ? MENU_REMOVE : MENU_SET); - newMenu.setTarget(ColorUtil.prependColorTag(groupName, MoreObjects.firstNonNull(color, Color.WHITE))); - newMenu.setIdentifier(itemId); - newMenu.setParam1(widgetId); - newMenu.setType(MenuAction.RUNELITE.getId()); - menuList[num++] = newMenu; - } - client.setMenuEntries(menuList); + client.createMenuEntry(-1) + .setOption(groupName.equals(group) ? MENU_REMOVE : MENU_SET) + .setTarget(ColorUtil.prependColorTag(groupName, MoreObjects.firstNonNull(color, Color.WHITE))) + .setType(MenuAction.RUNELITE) + .onClick(e -> + { + if (e.getOption().equals(MENU_SET)) + { + setTag(itemId, groupName); + } + else + { + unsetTag(itemId); + } + }); + } } } @@ -270,15 +239,27 @@ public class InventoryTagsPlugin extends Plugin removeInventoryMenuOptions(); if (editorMode) { - menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE); - menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE); - menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE); + menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE, this::save); + menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE, this::save); + menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE, this::save); } else { - menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE); - menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE); - menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE); + menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE, this::configure); + menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE, this::configure); + menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE, this::configure); } } + + private void save(MenuEntry menuEntry) + { + editorMode = false; + refreshInventoryMenuOptions(); + } + + private void configure(MenuEntry menuEntry) + { + editorMode = true; + refreshInventoryMenuOptions(); + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemprices/ItemPricesOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemprices/ItemPricesOverlay.java index ea33e614f8..bea5de5af5 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemprices/ItemPricesOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemprices/ItemPricesOverlay.java @@ -90,7 +90,7 @@ class ItemPricesOverlay extends Overlay } final MenuEntry menuEntry = menuEntries[last]; - final MenuAction action = MenuAction.of(menuEntry.getType()); + final MenuAction action = menuEntry.getType(); final int widgetId = menuEntry.getParam1(); final int groupId = WidgetInfo.TO_GROUP(widgetId); final boolean isAlching = menuEntry.getOption().equals("Cast") && menuEntry.getTarget().contains("High Level Alchemy"); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java index 56cb315caf..68ecf39f3b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java @@ -55,7 +55,6 @@ import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.MenuOpened; import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.PostItemComposition; -import net.runelite.api.events.WidgetMenuOptionClicked; import net.runelite.api.widgets.WidgetID; import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.callback.ClientThread; @@ -74,7 +73,6 @@ import static net.runelite.client.plugins.menuentryswapper.MenuEntrySwapperConfi import static net.runelite.client.plugins.menuentryswapper.MenuEntrySwapperConfig.MorytaniaLegsMode; import static net.runelite.client.plugins.menuentryswapper.MenuEntrySwapperConfig.RadasBlessingMode; import net.runelite.client.util.Text; -import org.apache.commons.lang3.ArrayUtils; @PluginDescriptor( name = "Menu Entry Swapper", @@ -506,24 +504,6 @@ public class MenuEntrySwapperPlugin extends Plugin clientThread.invoke(this::resetItemCompositionCache); } - @Subscribe - public void onWidgetMenuOptionClicked(WidgetMenuOptionClicked event) - { - if (event.getWidget() == WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB - || event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB - || event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB) - { - String option = event.getMenuOption(); - String target = Text.removeTags(event.getMenuTarget()); - if ((option.equals(CONFIGURE) || option.equals(SAVE)) && (target.equals(LEFT_CLICK_MENU_TARGET) || target.equals(SHIFT_CLICK_MENU_TARGET))) - { - configuringShiftClick = option.equals(CONFIGURE) && target.equals(SHIFT_CLICK_MENU_TARGET); - configuringLeftClick = option.equals(CONFIGURE) && target.equals(LEFT_CLICK_MENU_TARGET); - rebuildCustomizationMenus(); - } - } - } - @Subscribe public void onMenuOpened(MenuOpened event) { @@ -591,11 +571,11 @@ public class MenuEntrySwapperPlugin extends Plugin for (MenuEntry entry : entries) { - final MenuAction menuAction = MenuAction.of(entry.getType()); + final MenuAction menuAction = entry.getType(); if (ITEM_MENU_TYPES.contains(menuAction) && entry.getIdentifier() == itemId) { - entry.setType(MenuAction.RUNELITE.getId()); + entry.setType(MenuAction.RUNELITE); if (activeAction == menuAction) { @@ -604,13 +584,11 @@ public class MenuEntrySwapperPlugin extends Plugin } } - final MenuEntry resetShiftClickEntry = new MenuEntry(); - resetShiftClickEntry.setOption(RESET); - resetShiftClickEntry.setTarget(configuringShiftClick ? SHIFT_CLICK_MENU_TARGET : LEFT_CLICK_MENU_TARGET); - resetShiftClickEntry.setIdentifier(itemId); - resetShiftClickEntry.setParam1(widgetId); - resetShiftClickEntry.setType(MenuAction.RUNELITE.getId()); - client.setMenuEntries(ArrayUtils.addAll(entries, resetShiftClickEntry)); + client.createMenuEntry(-1) + .setOption(RESET) + .setTarget(configuringShiftClick ? SHIFT_CLICK_MENU_TARGET : LEFT_CLICK_MENU_TARGET) + .setType(MenuAction.RUNELITE) + .onClick(e -> unsetSwapConfig(configuringShiftClick, itemId)); } @Subscribe @@ -636,8 +614,8 @@ public class MenuEntrySwapperPlugin extends Plugin final int opId = isDepositBoxPlayerInventory ? shiftDepositMode.getIdentifierDepositBox() : isChambersOfXericStorageUnitPlayerInventory ? shiftDepositMode.getIdentifierChambersStorageUnit() : shiftDepositMode.getIdentifier(); - final int actionId = opId >= 6 ? MenuAction.CC_OP_LOW_PRIORITY.getId() : MenuAction.CC_OP.getId(); - bankModeSwap(actionId, opId); + final MenuAction action = opId >= 6 ? MenuAction.CC_OP_LOW_PRIORITY : MenuAction.CC_OP; + bankModeSwap(action, opId); } // Swap to shift-click withdraw behavior @@ -647,22 +625,23 @@ public class MenuEntrySwapperPlugin extends Plugin && menuEntryAdded.getOption().startsWith("Withdraw")) { ShiftWithdrawMode shiftWithdrawMode = config.bankWithdrawShiftClick(); - final int actionId, opId; + final MenuAction action; + final int opId; if (widgetGroupId == WidgetID.CHAMBERS_OF_XERIC_STORAGE_UNIT_PRIVATE_GROUP_ID || widgetGroupId == WidgetID.CHAMBERS_OF_XERIC_STORAGE_UNIT_SHARED_GROUP_ID) { - actionId = MenuAction.CC_OP.getId(); + action = MenuAction.CC_OP; opId = shiftWithdrawMode.getIdentifierChambersStorageUnit(); } else { - actionId = shiftWithdrawMode.getMenuAction().getId(); + action = shiftWithdrawMode.getMenuAction(); opId = shiftWithdrawMode.getIdentifier(); } - bankModeSwap(actionId, opId); + bankModeSwap(action, opId); } } - private void bankModeSwap(int entryTypeId, int entryIdentifier) + private void bankModeSwap(MenuAction entryType, int entryIdentifier) { MenuEntry[] menuEntries = client.getMenuEntries(); @@ -670,10 +649,10 @@ public class MenuEntrySwapperPlugin extends Plugin { MenuEntry entry = menuEntries[i]; - if (entry.getType() == entryTypeId && entry.getIdentifier() == entryIdentifier) + if (entry.getType() == entryType && entry.getIdentifier() == entryIdentifier) { // Raise the priority of the op so it doesn't get sorted later - entry.setType(MenuAction.CC_OP.getId()); + entry.setType(MenuAction.CC_OP); menuEntries[i] = menuEntries[menuEntries.length - 1]; menuEntries[menuEntries.length - 1] = entry; @@ -703,17 +682,6 @@ public class MenuEntrySwapperPlugin extends Plugin String target = event.getMenuTarget(); ItemComposition itemComposition = itemManager.getItemComposition(itemId); - if (option.equals(RESET) && target.equals(SHIFT_CLICK_MENU_TARGET)) - { - unsetSwapConfig(true, itemId); - return; - } - if (option.equals(RESET) && target.equals(LEFT_CLICK_MENU_TARGET)) - { - unsetSwapConfig(false, itemId); - return; - } - if (!itemComposition.getName().equals(Text.removeTags(target))) { return; @@ -741,7 +709,7 @@ public class MenuEntrySwapperPlugin extends Plugin private void swapMenuEntry(MenuEntry[] menuEntries, int index, MenuEntry menuEntry) { final int eventId = menuEntry.getIdentifier(); - final MenuAction menuAction = MenuAction.of(menuEntry.getType()); + final MenuAction menuAction = menuEntry.getType(); final String option = Text.removeTags(menuEntry.getOption()).toLowerCase(); final String target = Text.removeTags(menuEntry.getTarget()).toLowerCase(); final NPC hintArrowNpc = client.getHintArrowNpc(); @@ -968,31 +936,31 @@ public class MenuEntrySwapperPlugin extends Plugin removeCusomizationMenus(); if (configuringLeftClick) { - menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE_LC); - menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE_LC); - menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE_LC); + menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE_LC, this::save); + menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE_LC, this::save); + menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE_LC, this::save); } else if (configuringShiftClick) { - menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE_SC); - menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE_SC); - menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE_SC); + menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE_SC, this::save); + menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE_SC, this::save); + menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE_SC, this::save); } else { // Left click if (config.leftClickCustomization()) { - menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE_LC); - menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE_LC); - menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE_LC); + menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE_LC, this::configure); + menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE_LC, this::configure); + menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE_LC, this::configure); } // Shift click if (config.shiftClickCustomization()) { - menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE_SC); - menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE_SC); - menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE_SC); + menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE_SC, this::configure); + menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE_SC, this::configure); + menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE_SC, this::configure); } } } @@ -1001,4 +969,18 @@ public class MenuEntrySwapperPlugin extends Plugin { return client.isKeyPressed(KeyCode.KC_SHIFT); } + + private void save(MenuEntry menuEntry) + { + configuringLeftClick = configuringShiftClick = false; + rebuildCustomizationMenus(); + } + + private void configure(MenuEntry menuEntry) + { + String target = Text.removeTags(menuEntry.getTarget()); + configuringShiftClick = target.equals(SHIFT_CLICK_MENU_TARGET); + configuringLeftClick = target.equals(LEFT_CLICK_MENU_TARGET); + rebuildCustomizationMenus(); + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java index 1e56b743eb..f9355f0aa5 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java @@ -108,7 +108,7 @@ class MouseHighlightOverlay extends Overlay MenuEntry menuEntry = menuEntries[last]; String target = menuEntry.getTarget(); String option = menuEntry.getOption(); - MenuAction type = MenuAction.of(menuEntry.getType()); + MenuAction type = menuEntry.getType(); if (type == MenuAction.RUNELITE_OVERLAY || type == MenuAction.CC_OP_LOW_PRIORITY) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java index c2fb671c10..ed736f728a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPlugin.java @@ -31,7 +31,6 @@ import com.google.inject.Provides; import java.awt.Color; import java.time.Instant; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -57,7 +56,6 @@ import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameTick; import net.runelite.api.events.GraphicsObjectCreated; import net.runelite.api.events.MenuEntryAdded; -import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.NpcChanged; import net.runelite.api.events.NpcDespawned; import net.runelite.api.events.NpcSpawned; @@ -271,7 +269,6 @@ public class NpcIndicatorsPlugin extends Plugin final MenuEntry menuEntry = menuEntries[menuEntries.length - 1]; final String target = ColorUtil.prependColorTag(Text.removeTags(event.getTarget()), color); menuEntry.setTarget(target); - client.setMenuEntries(menuEntries); } } else if (menuAction == MenuAction.EXAMINE_NPC && client.isKeyPressed(KeyCode.KC_SHIFT)) @@ -291,48 +288,29 @@ public class NpcIndicatorsPlugin extends Plugin .filter(highlight -> !highlight.equalsIgnoreCase(npcName)) .anyMatch(highlight -> WildcardMatcher.matches(highlight, npcName)); - MenuEntry[] menuEntries = client.getMenuEntries(); - // Only add Untag-All option to npcs not highlighted by a wildcard entry, because untag-all will not remove wildcards if (!matchesList) { - menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 2); - final MenuEntry tagAllEntry = menuEntries[menuEntries.length - 2] = new MenuEntry(); - tagAllEntry.setOption(highlights.stream().anyMatch(npcName::equalsIgnoreCase) ? UNTAG_ALL : TAG_ALL); - tagAllEntry.setTarget(event.getTarget()); - tagAllEntry.setParam0(event.getActionParam0()); - tagAllEntry.setParam1(event.getActionParam1()); - tagAllEntry.setIdentifier(event.getIdentifier()); - tagAllEntry.setType(MenuAction.RUNELITE.getId()); - } - else - { - menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1); + client.createMenuEntry(-1) + .setOption(highlights.stream().anyMatch(npcName::equalsIgnoreCase) ? UNTAG_ALL : TAG_ALL) + .setTarget(event.getTarget()) + .setIdentifier(event.getIdentifier()) + .setType(MenuAction.RUNELITE) + .onClick(this::tag); } - final MenuEntry tagEntry = menuEntries[menuEntries.length - 1] = new MenuEntry(); - tagEntry.setOption(npcTags.contains(npc.getIndex()) ? UNTAG : TAG); - tagEntry.setTarget(event.getTarget()); - tagEntry.setParam0(event.getActionParam0()); - tagEntry.setParam1(event.getActionParam1()); - tagEntry.setIdentifier(event.getIdentifier()); - tagEntry.setType(MenuAction.RUNELITE.getId()); - - client.setMenuEntries(menuEntries); + client.createMenuEntry(-1) + .setOption(npcTags.contains(npc.getIndex()) ? UNTAG : TAG) + .setTarget(event.getTarget()) + .setIdentifier(event.getIdentifier()) + .setType(MenuAction.RUNELITE) + .onClick(this::tag); } } - @Subscribe - public void onMenuOptionClicked(MenuOptionClicked click) + private void tag(MenuEntry entry) { - if (click.getMenuAction() != MenuAction.RUNELITE || - !(click.getMenuOption().equals(TAG) || click.getMenuOption().equals(UNTAG) || - click.getMenuOption().equals(TAG_ALL) || click.getMenuOption().equals(UNTAG_ALL))) - { - return; - } - - final int id = click.getId(); + final int id = entry.getIdentifier(); final NPC[] cachedNPCs = client.getCachedNPCs(); final NPC npc = cachedNPCs[id]; @@ -341,7 +319,7 @@ public class NpcIndicatorsPlugin extends Plugin return; } - if (click.getMenuOption().equals(TAG) || click.getMenuOption().equals(UNTAG)) + if (entry.getOption().equals(TAG) || entry.getOption().equals(UNTAG)) { final boolean removed = npcTags.remove(id); @@ -371,8 +349,6 @@ public class NpcIndicatorsPlugin extends Plugin // this trips a config change which triggers the overlay rebuild updateNpcsToHighlight(name); } - - click.consume(); } @Subscribe diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java index 826eb725da..526ffe7f91 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/objectindicators/ObjectIndicatorsPlugin.java @@ -31,7 +31,6 @@ import com.google.gson.reflect.TypeToken; import com.google.inject.Provides; import java.awt.Color; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -65,7 +64,6 @@ import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GroundObjectDespawned; import net.runelite.api.events.GroundObjectSpawned; import net.runelite.api.events.MenuEntryAdded; -import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.WallObjectChanged; import net.runelite.api.events.WallObjectDespawned; import net.runelite.api.events.WallObjectSpawned; @@ -230,35 +228,26 @@ public class ObjectIndicatorsPlugin extends Plugin return; } - MenuEntry[] menuEntries = client.getMenuEntries(); - menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1); - MenuEntry menuEntry = menuEntries[menuEntries.length - 1] = new MenuEntry(); - menuEntry.setOption(objects.stream().anyMatch(o -> o.getTileObject() == tileObject) ? UNMARK : MARK); - menuEntry.setTarget(event.getTarget()); - menuEntry.setParam0(event.getActionParam0()); - menuEntry.setParam1(event.getActionParam1()); - menuEntry.setIdentifier(event.getIdentifier()); - menuEntry.setType(MenuAction.RUNELITE.getId()); - client.setMenuEntries(menuEntries); + client.createMenuEntry(-1) + .setOption(objects.stream().anyMatch(o -> o.getTileObject() == tileObject) ? UNMARK : MARK) + .setTarget(event.getTarget()) + .setParam0(event.getActionParam0()) + .setParam1(event.getActionParam1()) + .setIdentifier(event.getIdentifier()) + .setType(MenuAction.RUNELITE) + .onClick(this::markObject); } - @Subscribe - public void onMenuOptionClicked(MenuOptionClicked event) + private void markObject(MenuEntry entry) { - if (event.getMenuAction() != MenuAction.RUNELITE - || !(event.getMenuOption().equals(MARK) || event.getMenuOption().equals(UNMARK))) - { - return; - } - Scene scene = client.getScene(); Tile[][][] tiles = scene.getTiles(); - final int x = event.getParam0(); - final int y = event.getParam1(); + final int x = entry.getParam0(); + final int y = entry.getParam1(); final int z = client.getPlane(); final Tile tile = tiles[z][x][y]; - TileObject object = findTileObject(tile, event.getId()); + TileObject object = findTileObject(tile, entry.getIdentifier()); if (object == null) { return; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/opponentinfo/OpponentInfoPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/opponentinfo/OpponentInfoPlugin.java index 4d58b924d1..330f4dfb42 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/opponentinfo/OpponentInfoPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/opponentinfo/OpponentInfoPlugin.java @@ -184,7 +184,6 @@ public class OpponentInfoPlugin extends Plugin { MenuEntry[] menuEntries = client.getMenuEntries(); menuEntries[menuEntries.length - 1].setTarget("*" + menuEntries[menuEntries.length - 1].getTarget()); - client.setMenuEntries(menuEntries); } } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsPlugin.java index df72925bb8..eaa841a620 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/playerindicators/PlayerIndicatorsPlugin.java @@ -31,8 +31,8 @@ import lombok.Value; import net.runelite.api.Client; import net.runelite.api.FriendsChatRank; import static net.runelite.api.FriendsChatRank.UNRANKED; +import net.runelite.api.MenuAction; import static net.runelite.api.MenuAction.ITEM_USE_ON_PLAYER; -import static net.runelite.api.MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET; import static net.runelite.api.MenuAction.PLAYER_EIGTH_OPTION; import static net.runelite.api.MenuAction.PLAYER_FIFTH_OPTION; import static net.runelite.api.MenuAction.PLAYER_FIRST_OPTION; @@ -118,29 +118,23 @@ public class PlayerIndicatorsPlugin extends Plugin } MenuEntry[] menuEntries = client.getMenuEntries(); - boolean modified = false; for (MenuEntry entry : menuEntries) { - int type = entry.getType(); + MenuAction type = entry.getType(); - if (type >= MENU_ACTION_DEPRIORITIZE_OFFSET) - { - type -= MENU_ACTION_DEPRIORITIZE_OFFSET; - } - - if (type == WALK.getId() - || type == SPELL_CAST_ON_PLAYER.getId() - || type == ITEM_USE_ON_PLAYER.getId() - || type == PLAYER_FIRST_OPTION.getId() - || type == PLAYER_SECOND_OPTION.getId() - || type == PLAYER_THIRD_OPTION.getId() - || type == PLAYER_FOURTH_OPTION.getId() - || type == PLAYER_FIFTH_OPTION.getId() - || type == PLAYER_SIXTH_OPTION.getId() - || type == PLAYER_SEVENTH_OPTION.getId() - || type == PLAYER_EIGTH_OPTION.getId() - || type == RUNELITE_PLAYER.getId()) + if (type == WALK + || type == SPELL_CAST_ON_PLAYER + || type == ITEM_USE_ON_PLAYER + || type == PLAYER_FIRST_OPTION + || type == PLAYER_SECOND_OPTION + || type == PLAYER_THIRD_OPTION + || type == PLAYER_FOURTH_OPTION + || type == PLAYER_FIFTH_OPTION + || type == PLAYER_SIXTH_OPTION + || type == PLAYER_SEVENTH_OPTION + || type == PLAYER_EIGTH_OPTION + || type == RUNELITE_PLAYER) { Player[] players = client.getCachedPlayers(); Player player = null; @@ -149,7 +143,7 @@ public class PlayerIndicatorsPlugin extends Plugin // 'Walk here' identifiers are offset by 1 because the default // identifier for this option is 0, which is also a player index. - if (type == WALK.getId()) + if (type == WALK) { identifier--; } @@ -175,14 +169,8 @@ public class PlayerIndicatorsPlugin extends Plugin String newTarget = decorateTarget(oldTarget, decorations); entry.setTarget(newTarget); - modified = true; } } - - if (modified) - { - client.setMenuEntries(menuEntries); - } } private Decorations getDecorations(Player player) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/wiki/WikiPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/wiki/WikiPlugin.java index 241ebc9809..9ac225d4ba 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/wiki/WikiPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/wiki/WikiPlugin.java @@ -70,7 +70,7 @@ import okhttp3.HttpUrl; ) public class WikiPlugin extends Plugin { - static final HttpUrl WIKI_BASE = HttpUrl.parse("https://oldschool.runescape.wiki"); + static final HttpUrl WIKI_BASE = HttpUrl.get("https://oldschool.runescape.wiki"); static final HttpUrl WIKI_API = WIKI_BASE.newBuilder().addPathSegments("api.php").build(); static final String UTM_SORUCE_KEY = "utm_source"; static final String UTM_SORUCE_VALUE = "runelite"; @@ -335,20 +335,6 @@ public class WikiPlugin extends Plugin LinkBrowser.browse(url.toString()); return; } - - if (ev.getMenuAction() == MenuAction.RUNELITE) - { - switch (ev.getMenuOption()) - { - case MENUOP_WIKI: - LinkBrowser.browse(WIKI_BASE.newBuilder() - .addPathSegment("w") - .addPathSegment(Text.removeTags(ev.getMenuTarget())) - .addQueryParameter(UTM_SORUCE_KEY, UTM_SORUCE_VALUE) - .build().toString()); - - } - } } private void openSearchInput() @@ -372,17 +358,17 @@ public class WikiPlugin extends Plugin { int widgetIndex = event.getActionParam0(); int widgetID = event.getActionParam1(); - MenuEntry[] menuEntries = client.getMenuEntries(); if (wikiSelected && event.getType() == MenuAction.SPELL_CAST_ON_WIDGET.getId()) { + MenuEntry[] menuEntries = client.getMenuEntries(); Widget w = getWidget(widgetID, widgetIndex); if (w.getType() == WidgetType.GRAPHIC && w.getItemId() != -1) { for (int ourEntry = menuEntries.length - 1;ourEntry >= 0; ourEntry--) { MenuEntry entry = menuEntries[ourEntry]; - if (entry.getType() == MenuAction.SPELL_CAST_ON_WIDGET.getId()) + if (entry.getType() == MenuAction.SPELL_CAST_ON_WIDGET) { int id = itemManager.canonicalize(w.getItemId()); String name = itemManager.getItemComposition(id).getName(); @@ -390,7 +376,6 @@ public class WikiPlugin extends Plugin break; } } - client.setMenuEntries(menuEntries); } else { @@ -400,7 +385,7 @@ public class WikiPlugin extends Plugin MenuEntry[] oldEntries = menuEntries; menuEntries = Arrays.copyOf(menuEntries, menuEntries.length - 1); for (int ourEntry = oldEntries.length - 1; - ourEntry >= 2 && oldEntries[oldEntries.length - 1].getType() != MenuAction.SPELL_CAST_ON_WIDGET.getId(); + ourEntry >= 2 && oldEntries[oldEntries.length - 1].getType() != MenuAction.SPELL_CAST_ON_WIDGET; ourEntry--) { menuEntries[ourEntry - 1] = oldEntries[ourEntry]; @@ -425,16 +410,15 @@ public class WikiPlugin extends Plugin return; } - menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1); - - MenuEntry menuEntry = menuEntries[menuEntries.length - 1] = new MenuEntry(); - menuEntry.setTarget(action.replace("View ", "").replace(" guide", "")); - menuEntry.setOption(MENUOP_WIKI); - menuEntry.setParam0(widgetIndex); - menuEntry.setParam1(widgetID); - menuEntry.setType(MenuAction.RUNELITE.getId()); - - client.setMenuEntries(menuEntries); + client.createMenuEntry(-1) + .setTarget(action.replace("View ", "").replace(" guide", "")) + .setOption(MENUOP_WIKI) + .setType(MenuAction.RUNELITE) + .onClick(ev -> LinkBrowser.browse(WIKI_BASE.newBuilder() + .addPathSegment("w") + .addPathSegment(Text.removeTags(ev.getTarget())) + .addQueryParameter(UTM_SORUCE_KEY, UTM_SORUCE_VALUE) + .build().toString())); } } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java index ef3bcaf423..109095545b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/worldhopper/WorldHopperPlugin.java @@ -28,7 +28,6 @@ package net.runelite.client.plugins.worldhopper; import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ObjectArrays; import com.google.inject.Provides; import java.awt.image.BufferedImage; import java.time.Instant; @@ -54,7 +53,6 @@ import net.runelite.api.FriendsChatManager; import net.runelite.api.FriendsChatMember; import net.runelite.api.GameState; import net.runelite.api.MenuAction; -import net.runelite.api.MenuEntry; import net.runelite.api.NameableContainer; import net.runelite.api.Varbits; import net.runelite.api.clan.ClanChannel; @@ -63,7 +61,6 @@ import net.runelite.api.events.ChatMessage; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameTick; import net.runelite.api.events.MenuEntryAdded; -import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.VarbitChanged; import net.runelite.api.events.WorldListLoad; import net.runelite.api.widgets.WidgetInfo; @@ -92,7 +89,6 @@ import net.runelite.client.util.WorldUtil; import net.runelite.http.api.worlds.World; import net.runelite.http.api.worlds.WorldResult; import net.runelite.http.api.worlds.WorldType; -import org.apache.commons.lang3.ArrayUtils; @PluginDescriptor( name = "World Hopper", @@ -397,43 +393,19 @@ public class WorldHopperPlugin extends Plugin return; } - final MenuEntry hopTo = new MenuEntry(); - hopTo.setOption(HOP_TO); - hopTo.setTarget(event.getTarget()); - hopTo.setType(MenuAction.RUNELITE.getId()); - hopTo.setParam0(event.getActionParam0()); - hopTo.setParam1(event.getActionParam1()); + client.createMenuEntry(after ? -2 : -1) + .setOption(HOP_TO) + .setTarget(event.getTarget()) + .setType(MenuAction.RUNELITE) + .onClick(e -> + { + ChatPlayer p = getChatPlayerFromName(e.getTarget()); - insertMenuEntry(hopTo, client.getMenuEntries(), after); - } - } - - private void insertMenuEntry(MenuEntry newEntry, MenuEntry[] entries, boolean after) - { - MenuEntry[] newMenu = ObjectArrays.concat(entries, newEntry); - - if (after) - { - int menuEntryCount = newMenu.length; - ArrayUtils.swap(newMenu, menuEntryCount - 1, menuEntryCount - 2); - } - - client.setMenuEntries(newMenu); - } - - @Subscribe - public void onMenuOptionClicked(MenuOptionClicked event) - { - if (event.getMenuAction() != MenuAction.RUNELITE || !event.getMenuOption().equals(HOP_TO)) - { - return; - } - - ChatPlayer player = getChatPlayerFromName(event.getMenuTarget()); - - if (player != null) - { - hop(player.getWorld()); + if (p != null) + { + hop(p.getWorld()); + } + }); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpTrackerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpTrackerPlugin.java index 7433a81323..5407226a99 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpTrackerPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/xptracker/XpTrackerPlugin.java @@ -32,7 +32,6 @@ import com.google.inject.Binder; import com.google.inject.Provides; import java.awt.image.BufferedImage; import java.time.temporal.ChronoUnit; -import java.util.Arrays; import java.util.EnumSet; import java.util.List; import java.util.Objects; @@ -45,7 +44,6 @@ import net.runelite.api.Client; import net.runelite.api.Experience; import net.runelite.api.GameState; import net.runelite.api.MenuAction; -import net.runelite.api.MenuEntry; import net.runelite.api.NPC; import net.runelite.api.Player; import net.runelite.api.Skill; @@ -54,7 +52,6 @@ import net.runelite.api.WorldType; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GameTick; import net.runelite.api.events.MenuEntryAdded; -import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.NpcDespawned; import net.runelite.api.events.StatChanged; import net.runelite.api.widgets.WidgetID; @@ -521,48 +518,21 @@ public class XpTrackerPlugin extends Plugin final String skillText = event.getOption().split(" ")[1]; final Skill skill = Skill.valueOf(Text.removeTags(skillText).toUpperCase()); - MenuEntry[] menuEntries = client.getMenuEntries(); - menuEntries = Arrays.copyOf(menuEntries, menuEntries.length + 1); - - MenuEntry menuEntry = menuEntries[menuEntries.length - 1] = new MenuEntry(); - menuEntry.setTarget(skillText); - menuEntry.setOption(hasOverlay(skill) ? MENUOP_REMOVE_CANVAS_TRACKER : MENUOP_ADD_CANVAS_TRACKER); - menuEntry.setParam0(event.getActionParam0()); - menuEntry.setParam1(widgetID); - menuEntry.setType(MenuAction.RUNELITE.getId()); - - client.setMenuEntries(menuEntries); - } - - @Subscribe - public void onMenuOptionClicked(MenuOptionClicked event) - { - if (event.getMenuAction().getId() != MenuAction.RUNELITE.getId() - || TO_GROUP(event.getParam1()) != WidgetID.SKILLS_GROUP_ID) - { - return; - } - - final Skill skill; - try - { - skill = Skill.valueOf(Text.removeTags(event.getMenuTarget()).toUpperCase()); - } - catch (IllegalArgumentException ex) - { - log.debug(null, ex); - return; - } - - switch (event.getMenuOption()) - { - case MENUOP_ADD_CANVAS_TRACKER: - addOverlay(skill); - break; - case MENUOP_REMOVE_CANVAS_TRACKER: - removeOverlay(skill); - break; - } + client.createMenuEntry(-1) + .setTarget(skillText) + .setOption(hasOverlay(skill) ? MENUOP_REMOVE_CANVAS_TRACKER : MENUOP_ADD_CANVAS_TRACKER) + .setType(MenuAction.RUNELITE) + .onClick(e -> + { + if (hasOverlay(skill)) + { + removeOverlay(skill); + } + else + { + addOverlay(skill); + } + }); } XpStateSingle getSkillState(Skill skill) diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java index bea3f9d280..31d428ceed 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java @@ -40,17 +40,13 @@ import javax.inject.Singleton; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; -import net.runelite.api.MenuAction; -import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.widgets.WidgetID; import net.runelite.api.widgets.WidgetItem; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigManager; import net.runelite.client.config.RuneLiteConfig; -import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.events.ConfigChanged; -import net.runelite.client.events.OverlayMenuClicked; import net.runelite.client.events.PluginChanged; /** @@ -108,14 +104,12 @@ public class OverlayManager private ArrayListMultimap overlayMap = ArrayListMultimap.create(); private final ConfigManager configManager; - private final EventBus eventBus; private final RuneLiteConfig runeLiteConfig; @Inject - private OverlayManager(final ConfigManager configManager, final EventBus eventBus, final RuneLiteConfig runeLiteConfig) + private OverlayManager(final ConfigManager configManager, final RuneLiteConfig runeLiteConfig) { this.configManager = configManager; - this.eventBus = eventBus; this.runeLiteConfig = runeLiteConfig; } @@ -137,32 +131,6 @@ public class OverlayManager rebuildOverlayLayers(); } - @Subscribe - public void onMenuOptionClicked(MenuOptionClicked event) - { - MenuAction menuAction = event.getMenuAction(); - if (menuAction != MenuAction.RUNELITE_OVERLAY && menuAction != MenuAction.RUNELITE_OVERLAY_CONFIG) - { - return; - } - - event.consume(); - - Overlay overlay = overlays.get(event.getId()); - if (overlay != null) - { - List menuEntries = overlay.getMenuEntries(); - OverlayMenuEntry overlayMenuEntry = menuEntries.stream() - .filter(me -> me.getOption().equals(event.getMenuOption())) - .findAny() - .orElse(null); - if (overlayMenuEntry != null) - { - eventBus.post(new OverlayMenuClicked(overlayMenuEntry, overlay)); - } - } - } - /** * Gets all of the overlays on a layer sorted by priority and position * diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java index 99b75c0255..d673faba77 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayRenderer.java @@ -49,7 +49,6 @@ import lombok.extern.slf4j.Slf4j; import net.runelite.api.Client; import net.runelite.api.GameState; import net.runelite.api.KeyCode; -import net.runelite.api.MenuEntry; import net.runelite.api.Varbits; import net.runelite.api.events.BeforeRender; import net.runelite.api.events.ClientTick; @@ -60,6 +59,7 @@ import net.runelite.api.widgets.WidgetItem; import net.runelite.client.config.RuneLiteConfig; import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.Subscribe; +import net.runelite.client.events.OverlayMenuClicked; import net.runelite.client.input.KeyListener; import net.runelite.client.input.KeyManager; import net.runelite.client.input.MouseAdapter; @@ -86,10 +86,12 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener private static final Color MOVING_OVERLAY_ACTIVE_COLOR = new Color(255, 255, 0, 200); private static final Color MOVING_OVERLAY_TARGET_COLOR = Color.RED; private static final Color MOVING_OVERLAY_RESIZING_COLOR = new Color(255, 0, 255, 200); + private final Client client; private final OverlayManager overlayManager; private final RuneLiteConfig runeLiteConfig; private final ClientUI clientUI; + private final EventBus eventBus; // Overlay movement variables private final Point overlayOffset = new Point(); @@ -101,7 +103,7 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener private boolean inOverlayResizingMode; private boolean inOverlayDraggingMode; private boolean startedMovingOverlay; - private MenuEntry[] menuEntries; + private Overlay hoveredOverlay; // for building menu entries // Overlay state validation private Rectangle viewportBounds; @@ -124,6 +126,7 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener this.overlayManager = overlayManager; this.runeLiteConfig = runeLiteConfig; this.clientUI = clientUI; + this.eventBus = eventBus; keyManager.registerKeyListener(this); mouseManager.registerMouseListener(this); eventBus.register(this); @@ -140,14 +143,15 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener resetOverlayManagementMode(); } - menuEntries = null; + hoveredOverlay = null; } } @Subscribe protected void onClientTick(ClientTick t) { - if (menuEntries == null) + final Overlay overlay = hoveredOverlay; + if (overlay == null || client.isMenuOpen()) { return; } @@ -158,24 +162,29 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener return; } - if (client.isMenuOpen()) + List menuEntries = overlay.getMenuEntries(); + if (menuEntries.isEmpty()) { return; } - MenuEntry[] clientMenuEntries = client.getMenuEntries(); - MenuEntry[] newEntries = new MenuEntry[clientMenuEntries.length + menuEntries.length]; + // Add in reverse order so they display correctly in the right-click menu + for (int i = menuEntries.size() - 1; i >= 0; --i) + { + OverlayMenuEntry overlayMenuEntry = menuEntries.get(i); - newEntries[0] = clientMenuEntries[0]; // Keep cancel at 0 - System.arraycopy(menuEntries, 0, newEntries, 1, menuEntries.length); // Add overlay menu entries - System.arraycopy(clientMenuEntries, 1, newEntries, menuEntries.length + 1, clientMenuEntries.length - 1); // Add remaining menu entries - client.setMenuEntries(newEntries); + client.createMenuEntry(-1) + .setOption(overlayMenuEntry.getOption()) + .setTarget(ColorUtil.wrapWithColorTag(overlayMenuEntry.getTarget(), JagexColors.MENU_TARGET)) + .setType(overlayMenuEntry.getMenuAction()) + .onClick(e -> eventBus.post(new OverlayMenuClicked(overlayMenuEntry, overlay))); + } } @Subscribe public void onBeforeRender(BeforeRender event) { - menuEntries = null; + hoveredOverlay = null; if (client.getGameState() == GameState.LOGGED_IN) { @@ -349,11 +358,7 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener if (!client.isMenuOpen() && !client.getSpellSelected() && bounds.contains(mouse)) { - if (menuEntries == null) - { - menuEntries = createRightClickMenuEntries(overlay); - } - + hoveredOverlay = overlay; overlay.onMouseOver(); } } @@ -902,33 +907,6 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener new Rectangle(canvasTopRightPoint, SNAP_CORNER_SIZE)); } - private MenuEntry[] createRightClickMenuEntries(Overlay overlay) - { - List menuEntries = overlay.getMenuEntries(); - if (menuEntries.isEmpty()) - { - return null; - } - - final MenuEntry[] entries = new MenuEntry[menuEntries.size()]; - - // Add in reverse order so they display correctly in the right-click menu - for (int i = menuEntries.size() - 1; i >= 0; --i) - { - OverlayMenuEntry overlayMenuEntry = menuEntries.get(i); - - final MenuEntry entry = new MenuEntry(); - entry.setOption(overlayMenuEntry.getOption()); - entry.setTarget(ColorUtil.wrapWithColorTag(overlayMenuEntry.getTarget(), JagexColors.MENU_TARGET)); - entry.setType(overlayMenuEntry.getMenuAction().getId()); - entry.setIdentifier(overlayManager.getOverlays().indexOf(overlay)); // overlay id - - entries[i] = entry; - } - - return entries; - } - /** * Adjust the given overlay position to be within its parent's bounds. * diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlay.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlay.java index 2f2beb0c62..16ca444f8a 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/worldmap/WorldMapOverlay.java @@ -24,6 +24,7 @@ */ package net.runelite.client.ui.overlay.worldmap; +import com.google.common.base.MoreObjects; import com.google.common.base.Splitter; import com.google.common.base.Strings; import java.awt.Dimension; @@ -32,23 +33,18 @@ import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.geom.Area; import java.awt.image.BufferedImage; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import javax.inject.Inject; import javax.inject.Singleton; import net.runelite.api.Client; import net.runelite.api.MenuAction; -import net.runelite.api.MenuEntry; import net.runelite.api.Point; import net.runelite.api.RenderOverview; import net.runelite.api.coords.WorldPoint; -import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.widgets.JavaScriptCallback; import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.WidgetID; import net.runelite.api.widgets.WidgetInfo; -import net.runelite.client.eventbus.Subscribe; import net.runelite.client.ui.FontManager; import net.runelite.client.ui.JagexColors; import net.runelite.client.ui.overlay.Overlay; @@ -73,7 +69,7 @@ public class WorldMapOverlay extends Overlay private final WorldMapPointManager worldMapPointManager; private final Client client; - private final List mapMenuEntries = new ArrayList<>(); + private WorldMapPoint hoveredPoint; @Inject private WorldMapOverlay( @@ -107,19 +103,18 @@ public class WorldMapOverlay extends Overlay bottomBar.setOnTimerListener((JavaScriptCallback) ev -> { - if (client.isMenuOpen() || mapMenuEntries.isEmpty()) + WorldMapPoint worldPoint = hoveredPoint; + if (client.isMenuOpen() || worldPoint == null) { return; } - MenuEntry[] entries = client.getMenuEntries(); - int end = entries.length; - entries = Arrays.copyOf(entries, end + mapMenuEntries.size()); - for (int i = 0; i < mapMenuEntries.size(); i++) - { - entries[end + i] = mapMenuEntries.get(i); - } - client.setMenuEntries(entries); + client.createMenuEntry(-1) + .setTarget(ColorUtil.wrapWithColorTag(worldPoint.getName(), JagexColors.MENU_TARGET)) + .setOption(FOCUS_ON) + .setType(MenuAction.RUNELITE) + .onClick(m -> client.getRenderOverview().setWorldMapPositionTarget( + MoreObjects.firstNonNull(worldPoint.getTarget(), worldPoint.getWorldPoint()))); }); bottomBar.setHasListener(true); @@ -135,7 +130,7 @@ public class WorldMapOverlay extends Overlay mousePos = null; } - mapMenuEntries.clear(); + hoveredPoint = null; WorldMapPoint tooltipPoint = null; @@ -227,19 +222,7 @@ public class WorldMapOverlay extends Overlay if (worldPoint.isJumpOnClick()) { assert worldPoint.getName() != null; - - WorldPoint target = worldPoint.getTarget(); - if (target == null) - { - target = worldPoint.getWorldPoint(); - } - - MenuEntry entry = new MenuEntry(); - entry.setType(MenuAction.RUNELITE.getId()); - entry.setOption(FOCUS_ON); - entry.setTarget(ColorUtil.wrapWithColorTag(worldPoint.getName(), JagexColors.MENU_TARGET)); - entry.setIdentifier(target.getPlane() << 28 | target.getX() << 14 | target.getY()); - mapMenuEntries.add(entry); + hoveredPoint = worldPoint; } } } @@ -259,21 +242,6 @@ public class WorldMapOverlay extends Overlay return null; } - @Subscribe - private void onMenuOptionClicked(MenuOptionClicked ev) - { - if (ev.getMenuAction() == MenuAction.RUNELITE && FOCUS_ON.equals(ev.getMenuOption())) - { - int pxy = ev.getId(); - WorldPoint wp = new WorldPoint( - pxy >> 14 & 0x3fff, - pxy & 0x3fff, - pxy >> 28); - - client.getRenderOverview().setWorldMapPositionTarget(wp); - } - } - /** * Get the screen coordinates for a WorldPoint on the world map * diff --git a/runelite-client/src/test/java/net/runelite/client/menus/MenuManagerTest.java b/runelite-client/src/test/java/net/runelite/client/menus/MenuManagerTest.java index 30ca3dfeda..cd33ded89b 100644 --- a/runelite-client/src/test/java/net/runelite/client/menus/MenuManagerTest.java +++ b/runelite-client/src/test/java/net/runelite/client/menus/MenuManagerTest.java @@ -24,9 +24,12 @@ */ package net.runelite.client.menus; +import com.google.common.collect.Lists; import com.google.inject.Guice; import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.BoundFieldModule; +import java.util.ArrayList; +import java.util.List; import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.MenuAction; @@ -38,24 +41,18 @@ import static net.runelite.api.widgets.WidgetInfo.MINIMAP_WORLDMAP_OPTIONS; import net.runelite.client.util.Text; import static org.junit.Assert.assertArrayEquals; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.ArgumentMatchers; +import static org.mockito.ArgumentMatchers.anyInt; import org.mockito.Mock; -import static org.mockito.Mockito.atLeastOnce; -import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.mockito.junit.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; @RunWith(MockitoJUnitRunner.class) public class MenuManagerTest { - private static final MenuEntry CANCEL = new MenuEntry(); - @Inject private MenuManager menuManager; @@ -63,14 +60,18 @@ public class MenuManagerTest @Bind private Client client; - private MenuEntry[] clientMenuEntries = {CANCEL}; + private final MenuEntry CANCEL = createMenuEntry("Cancel", "", MenuAction.CANCEL, MINIMAP_WORLDMAP_OPTIONS.getPackedId()); - @BeforeClass - public static void beforeClass() + private final List createdMenuEntries = new ArrayList<>(); + + private static MenuEntry createMenuEntry(String option, String target, MenuAction type, int param1) { - CANCEL.setOption("Cancel"); - CANCEL.setType(MenuAction.CANCEL.getId()); - CANCEL.setParam1(MINIMAP_WORLDMAP_OPTIONS.getPackedId()); + MenuEntry menuEntry = new TestMenuEntry(); + menuEntry.setOption(option); + menuEntry.setTarget(target); + menuEntry.setType(type); + menuEntry.setParam1(param1); + return menuEntry; } @Before @@ -78,35 +79,25 @@ public class MenuManagerTest { Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this); - doAnswer((Answer) invocationOnMock -> - { - clientMenuEntries = invocationOnMock.getArgument(0, MenuEntry[].class); - return null; - }).when(client).setMenuEntries(ArgumentMatchers.any(MenuEntry[].class)); - when(client.getMenuEntries()).thenAnswer((Answer) invocationMock -> clientMenuEntries); + when(client.createMenuEntry(anyInt())) + .thenAnswer(a -> + { + MenuEntry e = new TestMenuEntry(); + createdMenuEntries.add(e); + return e; + }); + when(client.getMenuEntries()).thenReturn(new MenuEntry[]{CANCEL}); } @Test public void testManagedMenuOrder() { - final MenuEntry first = new MenuEntry(); - final MenuEntry second = new MenuEntry(); - final MenuEntry third = new MenuEntry(); - first.setOption("Test"); - first.setTarget("First Entry"); - first.setParam1(MINIMAP_WORLDMAP_OPTIONS.getPackedId()); - first.setType(RUNELITE.getId()); - second.setOption("Test"); - second.setTarget("Second Entry"); - second.setParam1(MINIMAP_WORLDMAP_OPTIONS.getPackedId()); - second.setType(RUNELITE.getId()); - third.setOption("Test"); - third.setTarget("Third Entry"); - third.setParam1(MINIMAP_WORLDMAP_OPTIONS.getPackedId()); - third.setType(RUNELITE.getId()); - menuManager.addManagedCustomMenu(new WidgetMenuOption(first.getOption(), first.getTarget(), MINIMAP_WORLDMAP_OPTIONS)); - menuManager.addManagedCustomMenu(new WidgetMenuOption(second.getOption(), second.getTarget(), MINIMAP_WORLDMAP_OPTIONS)); - menuManager.addManagedCustomMenu(new WidgetMenuOption(third.getOption(), third.getTarget(), MINIMAP_WORLDMAP_OPTIONS)); + final MenuEntry first = createMenuEntry("Test", "First Entry", RUNELITE, MINIMAP_WORLDMAP_OPTIONS.getPackedId()); + final MenuEntry second = createMenuEntry("Test", "Second Entry", RUNELITE, MINIMAP_WORLDMAP_OPTIONS.getPackedId()); + final MenuEntry third = createMenuEntry("Test", "Third Entry", RUNELITE, MINIMAP_WORLDMAP_OPTIONS.getPackedId()); + menuManager.addManagedCustomMenu(new WidgetMenuOption(first.getOption(), first.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null); + menuManager.addManagedCustomMenu(new WidgetMenuOption(second.getOption(), second.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null); + menuManager.addManagedCustomMenu(new WidgetMenuOption(third.getOption(), third.getTarget(), MINIMAP_WORLDMAP_OPTIONS), null); menuManager.onMenuEntryAdded(new MenuEntryAdded( CANCEL.getOption(), @@ -116,12 +107,10 @@ public class MenuManagerTest CANCEL.getParam0(), CANCEL.getParam1())); - ArgumentCaptor captor = ArgumentCaptor.forClass(MenuEntry[].class); - verify(client, atLeastOnce()).setMenuEntries(captor.capture()); + verify(client, times(3)).createMenuEntry(anyInt()); - final MenuEntry[] resultMenuEntries = captor.getValue(); // Strip color tags from menu options before array comparison - for (MenuEntry resultEntry : resultMenuEntries) + for (MenuEntry resultEntry : createdMenuEntries) { final String resultTarget = resultEntry.getTarget(); if (resultTarget != null) @@ -130,6 +119,7 @@ public class MenuManagerTest } } - assertArrayEquals(new MenuEntry[]{CANCEL, third, second, first}, resultMenuEntries); + assertArrayEquals(new MenuEntry[]{third, second, first}, + Lists.reverse(createdMenuEntries).toArray(new MenuEntry[0])); } } diff --git a/runelite-client/src/test/java/net/runelite/client/menus/TestMenuEntry.java b/runelite-client/src/test/java/net/runelite/client/menus/TestMenuEntry.java new file mode 100644 index 0000000000..35ca935676 --- /dev/null +++ b/runelite-client/src/test/java/net/runelite/client/menus/TestMenuEntry.java @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2021, Adam + * 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 java.util.function.Consumer; +import lombok.EqualsAndHashCode; +import net.runelite.api.MenuAction; +import net.runelite.api.MenuEntry; + +@EqualsAndHashCode +public class TestMenuEntry implements MenuEntry +{ + private String option; + private String target; + private int identifier; + private int type; + private int param0; + private int param1; + private boolean forceLeftClick; + + @Override + public String getOption() + { + return option; + } + + @Override + public MenuEntry setOption(String option) + { + this.option = option; + return this; + } + + @Override + public String getTarget() + { + return target; + } + + @Override + public MenuEntry setTarget(String target) + { + this.target = target; + return this; + } + + @Override + public int getIdentifier() + { + return this.identifier; + } + + @Override + public MenuEntry setIdentifier(int identifier) + { + this.identifier = identifier; + return this; + } + + @Override + public MenuAction getType() + { + return MenuAction.of(this.type); + } + + @Override + public MenuEntry setType(MenuAction type) + { + this.type = type.getId(); + return this; + } + + @Override + public int getParam0() + { + return this.param0; + } + + @Override + public MenuEntry setParam0(int param0) + { + this.param0 = param0; + return this; + } + + @Override + public int getParam1() + { + return this.param1; + } + + @Override + public MenuEntry setParam1(int param1) + { + this.param1 = param1; + return this; + } + + @Override + public boolean isForceLeftClick() + { + return this.forceLeftClick; + } + + @Override + public MenuEntry setForceLeftClick(boolean forceLeftClick) + { + this.forceLeftClick = forceLeftClick; + return this; + } + + @Override + public boolean isDeprioritized() + { + return type >= MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET; + } + + @Override + public void setDeprioritized(boolean deprioritized) + { + if (deprioritized) + { + if (type < MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET) + { + type += MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET; + } + } + else + { + if (type >= MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET) + { + type -= MenuAction.MENU_ACTION_DEPRIORITIZE_OFFSET; + } + } + } + + @Override + public MenuEntry onClick(Consumer callback) + { + return this; + } +} diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java index cbe6cd34d6..4fa03023a1 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java @@ -28,6 +28,7 @@ import com.google.inject.Guice; import com.google.inject.Inject; import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.BoundFieldModule; +import java.util.Arrays; import net.runelite.api.Client; import net.runelite.api.GameState; import net.runelite.api.KeyCode; @@ -37,6 +38,7 @@ import net.runelite.api.events.ClientTick; import net.runelite.api.events.MenuEntryAdded; import net.runelite.client.config.ConfigManager; import net.runelite.client.game.ItemManager; +import net.runelite.client.menus.TestMenuEntry; import static org.junit.Assert.assertArrayEquals; import org.junit.Before; import org.junit.Test; @@ -88,9 +90,7 @@ public class MenuEntrySwapperPluginTest { // The menu implementation returns a copy of the array, which causes swap() to not // modify the same array being iterated in onClientTick - MenuEntry[] copy = new MenuEntry[entries.length]; - System.arraycopy(entries, 0, copy, 0, entries.length); - return copy; + return Arrays.copyOf(entries, entries.length); }); doAnswer((Answer) invocationOnMock -> { @@ -109,10 +109,10 @@ public class MenuEntrySwapperPluginTest private static MenuEntry menu(String option, String target, MenuAction menuAction, int identifier) { - MenuEntry menuEntry = new MenuEntry(); + MenuEntry menuEntry = new TestMenuEntry(); menuEntry.setOption(option); menuEntry.setTarget(target); - menuEntry.setType(menuAction.getId()); + menuEntry.setType(menuAction); menuEntry.setIdentifier(identifier); return menuEntry; } diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPluginTest.java index 00d3bd2eaa..90d306a1cd 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/npchighlight/NpcIndicatorsPluginTest.java @@ -39,6 +39,7 @@ import net.runelite.api.NPC; import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.NpcChanged; import net.runelite.api.events.NpcSpawned; +import net.runelite.client.menus.TestMenuEntry; import net.runelite.client.ui.overlay.OverlayManager; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -48,7 +49,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import org.mockito.junit.MockitoJUnitRunner; @@ -109,13 +109,12 @@ public class NpcIndicatorsPluginTest when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0 - when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()}); + MenuEntry entry = new TestMenuEntry(); + when(client.getMenuEntries()).thenReturn(new MenuEntry[]{entry}); MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1); npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded); - MenuEntry target = new MenuEntry(); - target.setTarget("Goblin"); // red - verify(client).setMenuEntries(new MenuEntry[]{target}); + assertEquals("Goblin", entry.getTarget()); // red } @Test @@ -133,13 +132,12 @@ public class NpcIndicatorsPluginTest when(client.getCachedNPCs()).thenReturn(new NPC[]{npc}); // id 0 - when(client.getMenuEntries()).thenReturn(new MenuEntry[]{new MenuEntry()}); + MenuEntry entry = new TestMenuEntry(); + when(client.getMenuEntries()).thenReturn(new MenuEntry[]{entry}); MenuEntryAdded menuEntryAdded = new MenuEntryAdded("", "Goblin", MenuAction.NPC_FIRST_OPTION.getId(), 0, -1, -1); npcIndicatorsPlugin.onMenuEntryAdded(menuEntryAdded); - MenuEntry target = new MenuEntry(); - target.setTarget("Goblin"); // blue - verify(client).setMenuEntries(new MenuEntry[]{target}); + assertEquals("Goblin", entry.getTarget()); // blue } @Test