Java Code Examples for net.runelite.api.events.MenuOpened#getMenuEntries()
The following examples show how to use
net.runelite.api.events.MenuOpened#getMenuEntries() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChatTranslationPlugin.java From plugins with GNU General Public License v3.0 | 6 votes |
private void onMenuOpened(MenuOpened event) { MenuEntry[] entries = event.getMenuEntries(); for (int i = 0; i < event.getMenuEntries().length; i++) { if (!AFTER_OPTIONS.contains(entries[i].getOption())) { continue; } MenuEntry[] newEntries = new MenuEntry[entries.length + 1]; System.arraycopy(entries, 0, newEntries, 0, i + 1); System.arraycopy(entries, i, newEntries, i + 1, entries.length - i); newEntries[i] = newEntries[i].clone(); newEntries[i].setOption(TRANSLATE); newEntries[i].setOpcode(MenuOpcode.RUNELITE.getId()); event.setMenuEntries(newEntries); event.setModified(); return; } }
Example 2
Source File: OpponentInfoPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
private void onMenuOpened(MenuOpened event) { boolean changed = false; for (MenuEntry entry : event.getMenuEntries()) { changed |= modify(entry); } if (changed) { event.setModified(); } }
Example 3
Source File: AgilityPlugin.java From plugins with GNU General Public License v3.0 | 5 votes |
private void onMenuOpened(MenuOpened event) { boolean changed = false; for (MenuEntry entry : event.getMenuEntries()) { changed |= checkAndModify(entry); } if (changed) { event.setModified(); } }
Example 4
Source File: InventoryTagsPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
@Subscribe private void onMenuOpened(final MenuOpened event) { final MenuEntry firstEntry = event.getFirstEntry(); if (firstEntry == null) { return; } final int widgetId = firstEntry.getParam1(); // Inventory item menu if (widgetId == WidgetInfo.INVENTORY.getId() && editorMode) { int itemId = firstEntry.getIdentifier(); if (itemId == -1) { return; } MenuEntry[] menuList = new MenuEntry[config.getAmount().toInt() + 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]; List<String> groups = GROUPS.subList(Math.max(GROUPS.size() - config.getAmount().toInt(), 0), GROUPS.size()); 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, Objects.requireNonNullElse(color, Color.WHITE))); newMenu.setIdentifier(itemId); newMenu.setParam1(widgetId); newMenu.setOpcode(MenuOpcode.RUNELITE.getId()); menuList[num++] = newMenu; } // Need to set the event entries to prevent conflicts event.setMenuEntries(menuList); event.setModified(); } }
Example 5
Source File: MenuEntrySwapperPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
@Subscribe private void onMenuOpened(MenuOpened event) { Player localPlayer = client.getLocalPlayer(); if (localPlayer == null) { return; } List<MenuEntry> menu_entries = new ArrayList<>(); for (MenuEntry entry : event.getMenuEntries()) { String option = Text.removeTags(entry.getOption()).toLowerCase(); if (option.contains("examine") && config.hideExamine()) { continue; } if (option.contains("net") && config.hideNet()) { continue; } if (option.contains("bait") && config.hideBait()) { continue; } if (option.contains("destroy")) { if (config.hideDestroyRunepouch() && entry.getTarget().contains("Rune pouch")) { continue; } if (config.hideDestroyCoalbag() && (entry.getTarget().contains("Coal bag") || entry.getTarget().contains("Open coal sack"))) { continue; } if (config.hideDestroyHerbsack() && (entry.getTarget().contains("Herb sack") || entry.getTarget().contains("Open herb sack"))) { continue; } if (config.hideDestroyBoltpouch() && entry.getTarget().contains("Bolt pouch")) { continue; } if (config.hideDestroyLootingBag() && entry.getTarget().contains("Looting bag")) { continue; } if (config.hideDestroyGembag() && (entry.getTarget().contains("Gem bag") || entry.getTarget().contains("Open gem bag"))) { continue; } } if (option.contains("restore")) { if (config.hideRestoreTanzaniteHelm() && entry.getTarget().contains("Tanzanite helm")) { continue; } if (config.hideRestoreMagmaHelm() && entry.getTarget().contains("Magma helm")) { continue; } } if (option.contains("drop")) { if (config.hideDropRunecraftingPouch() && ( entry.getTarget().contains("Small pouch") || entry.getTarget().contains("Medium pouch") || entry.getTarget().contains("Large pouch") || entry.getTarget().contains("Giant pouch"))) { continue; } } menu_entries.add(entry); } event.setMenuEntries(menu_entries.toArray(new MenuEntry[0])); event.setModified(); }
Example 6
Source File: ChatHistoryPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
@Subscribe public void onMenuOpened(MenuOpened event) { if (event.getMenuEntries().length < 2 || !config.copyToClipboard()) { return; } // Use second entry as first one can be walk here with transparent chatbox final MenuEntry entry = event.getMenuEntries()[event.getMenuEntries().length - 2]; if (entry.getOpcode() != MenuOpcode.CC_OP_LOW_PRIORITY.getId() && entry.getOpcode() != MenuOpcode.RUNELITE.getId()) { return; } final int groupId = TO_GROUP(entry.getParam1()); final int childId = TO_CHILD(entry.getParam1()); if (groupId != WidgetInfo.CHATBOX.getGroupId()) { return; } final Widget widget = client.getWidget(groupId, childId); final Widget parent = widget.getParent(); if (WidgetInfo.CHATBOX_MESSAGE_LINES.getId() != parent.getId()) { return; } // Get child id of first chat message static child so we can substract this offset to link to dynamic child // later final int first = WidgetInfo.CHATBOX_FIRST_MESSAGE.getChildId(); // Convert current message static widget id to dynamic widget id of message node with message contents // When message is right clicked, we are actually right clicking static widget that contains only sender. // The actual message contents are stored in dynamic widgets that follow same order as static widgets. // Every first dynamic widget is message sender and every second one is message contents. final int dynamicChildId = (childId - first) * 2 + 1; // Extract and store message contents when menu is opened because dynamic children can change while right click // menu is open and dynamicChildId will be outdated final Widget messageContents = parent.getChild(dynamicChildId); if (messageContents == null) { return; } currentMessage = messageContents.getText(); final MenuEntry menuEntry = new MenuEntry(); menuEntry.setOption(COPY_TO_CLIPBOARD); menuEntry.setTarget(entry.getTarget()); menuEntry.setOpcode(MenuOpcode.RUNELITE.getId()); menuEntry.setParam0(entry.getParam0()); menuEntry.setParam1(entry.getParam1()); menuEntry.setIdentifier(entry.getIdentifier()); client.setMenuEntries(ArrayUtils.insert(1, client.getMenuEntries(), menuEntry)); }
Example 7
Source File: InventoryTagsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Subscribe public void onMenuOpened(final MenuOpened event) { final MenuEntry firstEntry = event.getFirstEntry(); if (firstEntry == null) { return; } final int widgetId = firstEntry.getParam1(); // Inventory item menu if (widgetId == WidgetInfo.INVENTORY.getId() && editorMode) { int itemId = firstEntry.getIdentifier(); if (itemId == -1) { 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]; 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); } }
Example 8
Source File: MenuEntrySwapperPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Subscribe public void onMenuOpened(MenuOpened event) { if (!configuringShiftClick) { return; } MenuEntry firstEntry = event.getFirstEntry(); if (firstEntry == null) { return; } int widgetId = firstEntry.getParam1(); if (widgetId != WidgetInfo.INVENTORY.getId()) { return; } int itemId = firstEntry.getIdentifier(); if (itemId == -1) { return; } ItemComposition itemComposition = client.getItemDefinition(itemId); String itemName = itemComposition.getName(); String option = "Use"; int shiftClickActionIndex = itemComposition.getShiftClickActionIndex(); String[] inventoryActions = itemComposition.getInventoryActions(); if (shiftClickActionIndex >= 0 && shiftClickActionIndex < inventoryActions.length) { option = inventoryActions[shiftClickActionIndex]; } MenuEntry[] entries = event.getMenuEntries(); for (MenuEntry entry : entries) { if (itemName.equals(Text.removeTags(entry.getTarget()))) { entry.setType(MenuAction.RUNELITE.getId()); if (option.equals(entry.getOption())) { entry.setOption("* " + option); } } } final MenuEntry resetShiftClickEntry = new MenuEntry(); resetShiftClickEntry.setOption(RESET); resetShiftClickEntry.setTarget(MENU_TARGET); resetShiftClickEntry.setIdentifier(itemId); resetShiftClickEntry.setParam1(widgetId); resetShiftClickEntry.setType(MenuAction.RUNELITE.getId()); client.setMenuEntries(ArrayUtils.addAll(entries, resetShiftClickEntry)); }
Example 9
Source File: ChatHistoryPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Subscribe public void onMenuOpened(MenuOpened event) { if (event.getMenuEntries().length < 2 || !config.copyToClipboard()) { return; } // 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()) { return; } final int groupId = TO_GROUP(entry.getParam1()); final int childId = TO_CHILD(entry.getParam1()); if (groupId != WidgetInfo.CHATBOX.getGroupId()) { return; } final Widget widget = client.getWidget(groupId, childId); final Widget parent = widget.getParent(); if (WidgetInfo.CHATBOX_MESSAGE_LINES.getId() != parent.getId()) { return; } // Get child id of first chat message static child so we can substract this offset to link to dynamic child // later final int first = WidgetInfo.CHATBOX_FIRST_MESSAGE.getChildId(); // Convert current message static widget id to dynamic widget id of message node with message contents // When message is right clicked, we are actually right clicking static widget that contains only sender. // The actual message contents are stored in dynamic widgets that follow same order as static widgets. // Every first dynamic widget is message sender and every second one is message contents. final int dynamicChildId = (childId - first) * 2 + 1; // Extract and store message contents when menu is opened because dynamic children can change while right click // menu is open and dynamicChildId will be outdated final Widget messageContents = parent.getChild(dynamicChildId); if (messageContents == null) { return; } 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)); }