Menu Entry Manipulator

AdvancedUtility

Modifies right-click menu entries. Demonstrates how to add, remove, or reorder menu options using MenuEntryAdded events.

20 min read

What It Does

Modifies right-click menu entries. Demonstrates how to add, remove, or reorder menu options using MenuEntryAdded events.

Source Code

java
1package com.example;
2
3import net.runelite.api.Client;
4import net.runelite.api.MenuEntry;
5import net.runelite.api.events.MenuEntryAdded;
6import net.runelite.client.eventbus.Subscribe;
7import net.runelite.client.plugins.Plugin;
8import net.runelite.client.plugins.PluginDescriptor;
9import net.runelite.client.menus.MenuManager;
10import javax.inject.Inject;
11
12@PluginDescriptor(
13    name = "Menu Entry Manipulator",
14    description = "Modifies right-click menus"
15)
16public class MenuEntryManipulatorPlugin extends Plugin {
17    @Inject
18    private Client client;
19
20    @Inject
21    private MenuManager menuManager;
22
23    @Override
24    protected void startUp() {
25        // Use MenuManager's priority system for safer menu manipulation
26        // This adds a menu entry with higher priority (appears first)
27        menuManager.addPriorityEntry("Custom Action", "NPC");
28        
29        // Alternative: Use MenuEntrySwapper for swapping menu positions
30        // menuManager.addSwappableEntry("Attack", "NPC");
31    }
32
33    @Subscribe
34    public void onMenuEntryAdded(MenuEntryAdded event) {
35        // MenuManager handles menu modifications safely
36        // You can filter or modify entries here, but prefer MenuManager methods
37        if (event.getOption().equals("Attack") && event.getTarget().contains("Goblin")) {
38            // MenuManager priority system handles this automatically
39            // No need for direct client manipulation
40        }
41    }
42
43    @Override
44    protected void shutDown() {
45        // Clean up menu modifications
46        menuManager.removePriorityEntry("Custom Action", "NPC");
47    }
48}

Code Annotations

Line 20

Listen for MenuEntryAdded events

Line 21

Get current menu entries

Line 24

Create a new menu entry

API Classes Used

Key Concepts

  • Listen for MenuEntryAdded events
  • Get current menu entries
  • Create a new menu entry

Next Steps

  • Learn about MenuEntry API
  • Filter menu entries by type
  • Reorder menu entries