Java Code Examples for net.runelite.api.MenuEntry#setIdentifier()

The following examples show how to use net.runelite.api.MenuEntry#setIdentifier() . 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: Runes.java    From ExternalPlugins with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void modifyClick(OneClickPlugin plugin, MenuEntry event)
{
	if (event.getTarget().equals(rune))
	{
		if (plugin.updateSelectedItem(id))
		{
			event.setOpcode(MenuOpcode.ITEM_USE_ON_GAME_OBJECT.getId());
		}
	}
	else if (event.getTarget().equals("<col=ff9040>Magic Imbue<col=ffffff> -> <col=ffff>Yourself"))
	{
		event.setIdentifier(1);
		event.setOpcode(MenuOpcode.CC_OP.getId());
		event.setParam0(-1);
		event.setParam1(WidgetInfo.SPELL_MAGIC_IMBUE.getId());
	}
}
 
Example 2
Source File: OverlayRenderer.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private MenuEntry[] createRightClickMenuEntries(Overlay overlay)
{
	List<OverlayMenuEntry> 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;
}
 
Example 3
Source File: CameraPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private MenuEntry createCameraLookEntry(MenuEntryAdded lookNorth, int identifier, String option)
{
	MenuEntry m = new MenuEntry();
	m.setOption(option);
	m.setTarget(lookNorth.getTarget());
	m.setIdentifier(identifier);
	m.setOpcode(MenuOpcode.CC_OP.getId());
	m.setParam0(lookNorth.getParam0());
	m.setParam1(lookNorth.getParam1());
	return m;
}
 
Example 4
Source File: MenuEntrySwapperPluginTest.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static MenuEntry menu(String option, String target, MenuAction menuAction, int identifier)
{
	MenuEntry menuEntry = new MenuEntry();
	menuEntry.setOption(option);
	menuEntry.setTarget(target);
	menuEntry.setType(menuAction.getId());
	menuEntry.setIdentifier(identifier);
	return menuEntry;
}
 
Example 5
Source File: HiscorePlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	if (!config.menuOption())
	{
		return;
	}

	int groupId = WidgetInfo.TO_GROUP(event.getActionParam1());
	String option = event.getOption();

	if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() || groupId == WidgetInfo.FRIENDS_CHAT.getGroupId() ||
			groupId == WidgetInfo.CHATBOX.getGroupId() && !KICK_OPTION.equals(option) || //prevent from adding for Kick option (interferes with the raiding party one)
			groupId == WidgetInfo.RAIDING_PARTY.getGroupId() || groupId == WidgetInfo.PRIVATE_CHAT_MESSAGE.getGroupId() ||
			groupId == WidgetInfo.IGNORE_LIST.getGroupId())
	{
		if (!AFTER_OPTIONS.contains(option) || (option.equals("Delete") && groupId != WidgetInfo.IGNORE_LIST.getGroupId()))
		{
			return;
		}

		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());
	}
}
 
Example 6
Source File: ObjectIndicatorsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	if (event.getType() != MenuAction.EXAMINE_OBJECT.getId() || !client.isKeyPressed(KeyCode.KC_SHIFT))
	{
		return;
	}

	final Tile tile = client.getScene().getTiles()[client.getPlane()][event.getActionParam0()][event.getActionParam1()];
	final TileObject tileObject = findTileObject(tile, event.getIdentifier());

	if (tileObject == null)
	{
		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);
}
 
Example 7
Source File: BankTagsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	MenuEntry[] entries = client.getMenuEntries();

	if (event.getActionParam1() == WidgetInfo.BANK_ITEM_CONTAINER.getId()
		&& event.getOption().equals("Examine"))
	{
		Widget container = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
		Widget item = container.getChild(event.getActionParam0());
		int itemID = item.getItemId();
		String text = EDIT_TAGS_MENU_OPTION;
		int tagCount = tagManager.getTags(itemID, false).size() + tagManager.getTags(itemID, true).size();

		if (tagCount > 0)
		{
			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);
	}

	tabInterface.handleAdd(event);
}
 
Example 8
Source File: TabInterface.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static MenuEntry[] createMenuEntry(MenuEntryAdded event, String option, String target, MenuEntry[] entries)
{
	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;
}
 
Example 9
Source File: CameraPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private MenuEntry createCameraLookEntry(MenuEntryAdded lookNorth, int identifier, String option)
{
	MenuEntry m = new MenuEntry();
	m.setOption(option);
	m.setTarget(lookNorth.getTarget());
	m.setIdentifier(identifier);
	m.setType(MenuAction.CC_OP.getId());
	m.setParam0(lookNorth.getActionParam0());
	m.setParam1(lookNorth.getActionParam1());
	return m;
}
 
Example 10
Source File: Spell.java    From ExternalPlugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void modifyClick(OneClickPlugin plugin, MenuEntry event)
{
	if (cast.test(event))
	{
		if (plugin.getClickItem() == null)
		{
			return;
		}

		final Pair<Integer, Integer> pair = plugin.findItem(plugin.getClickItem().getId());

		if (pair.getLeft() != -1)
		{
			event.setOpcode(MenuOpcode.ITEM_USE_ON_WIDGET.getId());
			event.setIdentifier(pair.getLeft());
			event.setParam0(pair.getRight());
			event.setParam1(WidgetInfo.INVENTORY.getId());
			plugin.getClient().setSelectedSpellName("<col=00ff00>" + spell + "</col>" + "<col=ffffff>");
			plugin.getClient().setSelectedSpellWidget(plugin.getSpellSelection().getWidgetInfo().getId());
		}
	}
	else if (reset.test(event))
	{
		plugin.setClickItem(null);
	}
	else if (set.test(event))
	{
		final String itemName = event.getTarget().split("->")[1];
		plugin.setClickItem(new ClickItem(itemName, event.getIdentifier()));
	}
}
 
Example 11
Source File: HiscorePlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded event)
{
	if (!config.menuOption())
	{
		return;
	}

	int groupId = WidgetInfo.TO_GROUP(event.getParam1());
	String option = event.getOption();

	if (groupId == WidgetInfo.FRIENDS_LIST.getGroupId() || groupId == WidgetInfo.FRIENDS_CHAT.getGroupId() ||
		groupId == WidgetInfo.CHATBOX.getGroupId() && !KICK_OPTION.equals(option) || //prevent from adding for Kick option (interferes with the raiding party one)
		groupId == WidgetInfo.RAIDING_PARTY.getGroupId() || groupId == WidgetInfo.PRIVATE_CHAT_MESSAGE.getGroupId() ||
		groupId == WidgetInfo.IGNORE_LIST.getGroupId())
	{
		if (!AFTER_OPTIONS.contains(option) || (option.equals("Delete") && groupId != WidgetInfo.IGNORE_LIST.getGroupId()))
		{
			return;
		}

		final MenuEntry lookup = new MenuEntry();
		lookup.setOption(LOOKUP);
		lookup.setTarget(event.getTarget());
		lookup.setOpcode(MenuOpcode.RUNELITE.getId());
		lookup.setParam0(event.getParam0());
		lookup.setParam1(event.getParam1());
		lookup.setIdentifier(event.getIdentifier());

		if (client != null)
		{
			insertMenuEntry(lookup, client.getMenuEntries());
		}
	}
}
 
Example 12
Source File: ObjectIndicatorsPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded event)
{
	if (event.getOpcode() != MenuOpcode.EXAMINE_OBJECT.getId() || !client.isKeyPressed(KeyCode.KC_SHIFT))
	{
		return;
	}

	final Tile tile = client.getScene().getTiles()[client.getPlane()][event.getParam0()][event.getParam1()];
	final TileObject tileObject = findTileObject(tile, event.getIdentifier());

	if (tileObject == null)
	{
		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.getParam0());
	menuEntry.setParam1(event.getParam1());
	menuEntry.setIdentifier(event.getIdentifier());
	menuEntry.setOpcode(MenuOpcode.RUNELITE.getId());
	client.setMenuEntries(menuEntries);
}
 
Example 13
Source File: InventoryTagsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@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 14
Source File: ChatHistoryPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@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 15
Source File: MenuEntrySwapperPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@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 16
Source File: ChatHistoryPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@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));
}
 
Example 17
Source File: InventoryTagsPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@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();
	}
}