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

The following examples show how to use net.runelite.api.MenuEntry#setParam0() . 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: 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 3
Source File: ChatHistoryPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded entry)
{
	final ChatboxTab tab = ChatboxTab.of(entry.getActionParam1());

	if (tab == null || !config.clearHistory() || !Text.removeTags(entry.getOption()).equals(tab.getAfter()))
	{
		return;
	}

	final MenuEntry clearEntry = new MenuEntry();
	clearEntry.setTarget("");
	clearEntry.setType(MenuAction.RUNELITE.getId());
	clearEntry.setParam0(entry.getActionParam0());
	clearEntry.setParam1(entry.getActionParam1());

	if (tab == ChatboxTab.GAME)
	{
		// keep type as the original CC_OP to correctly group "Game: Clear history" with
		// other tab "Game: *" options.
		clearEntry.setType(entry.getType());
	}

	final StringBuilder messageBuilder = new StringBuilder();

	if (tab != ChatboxTab.ALL)
	{
		messageBuilder.append(ColorUtil.wrapWithColorTag(tab.getName() + ": ", Color.YELLOW));
	}

	messageBuilder.append(CLEAR_HISTORY);
	clearEntry.setOption(messageBuilder.toString());

	final MenuEntry[] menuEntries = client.getMenuEntries();
	client.setMenuEntries(ArrayUtils.insert(menuEntries.length - 1, menuEntries, clearEntry));
}
 
Example 4
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 5
Source File: XpTrackerPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(final MenuEntryAdded event)
{
	int widgetID = event.getActionParam1();

	if (TO_GROUP(widgetID) != WidgetID.SKILLS_GROUP_ID
		|| !event.getOption().startsWith("View")
		|| !xpTrackerConfig.skillTabOverlayMenuOptions())
	{
		return;
	}

	// Get skill from menu option, eg. "View <col=ff981f>Attack</col> guide"
	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);
}
 
Example 6
Source File: FriendNotesPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	final int groupId = WidgetInfo.TO_GROUP(event.getActionParam1());

	// Look for "Message" on friends list
	if ((groupId == WidgetInfo.FRIENDS_LIST.getGroupId() && event.getOption().equals("Message")) ||
			(groupId == WidgetInfo.IGNORE_LIST.getGroupId() && event.getOption().equals("Delete")))
	{
		// Friends have color tags
		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());

		// Add menu entry
		final MenuEntry[] menuEntries = ObjectArrays.concat(client.getMenuEntries(), addNote);
		client.setMenuEntries(menuEntries);
	}
	else if (hoveredFriend != null)
	{
		hoveredFriend = null;
	}
}
 
Example 7
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 8
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 9
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 10
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 11
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 12
Source File: ChatHistoryPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded entry)
{
	final ChatboxTab tab = ChatboxTab.of(entry.getParam1());

	if (tab == null || !config.clearHistory() || !Text.removeTags(entry.getOption()).equals(tab.getAfter()))
	{
		return;
	}

	final MenuEntry clearEntry = new MenuEntry();
	clearEntry.setTarget("");
	clearEntry.setOpcode(MenuOpcode.RUNELITE.getId());
	clearEntry.setParam0(entry.getParam0());
	clearEntry.setParam1(entry.getParam1());

	if (tab == ChatboxTab.GAME)
	{
		// keep type as the original CC_OP to correctly group "Game: Clear history" with
		// other tab "Game: *" options.
		clearEntry.setOpcode(entry.getOpcode());
	}

	final StringBuilder messageBuilder = new StringBuilder();

	if (tab != ChatboxTab.ALL)
	{
		messageBuilder.append(ColorUtil.wrapWithColorTag(tab.getName() + ": ", Color.YELLOW));
	}

	messageBuilder.append(CLEAR_HISTORY);
	clearEntry.setOption(messageBuilder.toString());

	final MenuEntry[] menuEntries = client.getMenuEntries();
	client.setMenuEntries(ArrayUtils.insert(menuEntries.length - 1, menuEntries, clearEntry));
}
 
Example 13
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 14
Source File: XpTrackerPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(final MenuEntryAdded event)
{
	int widgetID = event.getParam1();

	if (TO_GROUP(widgetID) != WidgetID.SKILLS_GROUP_ID
		|| !event.getOption().startsWith("View")
		|| !xpTrackerConfig.skillTabOverlayMenuOptions())
	{
		return;
	}

	// Get skill from menu option, eg. "View <col=ff981f>Attack</col> guide"
	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.getParam0());
	menuEntry.setParam1(widgetID);
	menuEntry.setOpcode(MenuOpcode.RUNELITE.getId());

	client.setMenuEntries(menuEntries);
}
 
Example 15
Source File: SlayermusiqPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private MenuEntry createSlayermusiqOptionMenuEntry(MenuEntryAdded event)
{
	int widgetIndex = event.getParam0();
	int widgetID = event.getParam1();

	MenuEntry menuEntry = new MenuEntry();
	menuEntry.setTarget(event.getTarget());
	menuEntry.setOption(MENUOP_SLAYERMUSIQ);
	menuEntry.setParam0(widgetIndex);
	menuEntry.setParam1(widgetID);
	menuEntry.setOpcode(MenuOpcode.RUNELITE.getId());

	return menuEntry;
}
 
Example 16
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 17
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 18
Source File: WorldHopperPlugin.java    From plugins with GNU General Public License v3.0 4 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())
	{
		boolean after;

		if (AFTER_OPTIONS.contains(option))
		{
			after = true;
		}
		else if (BEFORE_OPTIONS.contains(option))
		{
			after = false;
		}
		else
		{
			return;
		}

		// Don't add entry if user is offline
		ChatPlayer player = getChatPlayerFromName(event.getTarget());
		WorldResult worldResult = worldService.getWorlds();

		if (player == null || player.getWorld() == 0 || player.getWorld() == client.getWorld()
			|| worldResult == null)
		{
			return;
		}

		World currentWorld = worldResult.findWorld(client.getWorld());
		World targetWorld = worldResult.findWorld(player.getWorld());
		if ((targetWorld == null || currentWorld == null)
			|| (config.removePVPWorld() && !currentWorld.getTypes().contains(WorldType.PVP) && targetWorld.getTypes().contains(WorldType.PVP))
			|| (config.removeBHWorld() && !currentWorld.getTypes().contains(WorldType.BOUNTY) && targetWorld.getTypes().contains(WorldType.BOUNTY)))
		{
			// Disable Hop-to a PVP world & BH world from a regular world
			return;
		}


		final MenuEntry hopTo = new MenuEntry();
		hopTo.setOption(HOP_TO);
		hopTo.setTarget(event.getTarget());
		hopTo.setOpcode(MenuOpcode.RUNELITE.getId());
		hopTo.setParam0(event.getParam0());
		hopTo.setParam1(event.getParam1());

		insertMenuEntry(hopTo, client.getMenuEntries(), after);
	}
}
 
Example 19
Source File: WorldHopperPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 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())
	{
		boolean after;

		if (AFTER_OPTIONS.contains(option))
		{
			after = true;
		}
		else if (BEFORE_OPTIONS.contains(option))
		{
			after = false;
		}
		else
		{
			return;
		}

		// Don't add entry if user is offline
		ChatPlayer player = getChatPlayerFromName(event.getTarget());
		WorldResult worldResult = worldService.getWorlds();

		if (player == null || player.getWorld() == 0 || player.getWorld() == client.getWorld()
			|| worldResult == null)
		{
			return;
		}

		World currentWorld = worldResult.findWorld(client.getWorld());
		World targetWorld = worldResult.findWorld(player.getWorld());
		if (targetWorld == null || currentWorld == null
			|| (!currentWorld.getTypes().contains(WorldType.PVP) && targetWorld.getTypes().contains(WorldType.PVP)))
		{
			// Disable Hop-to a PVP world from a regular world
			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());

		insertMenuEntry(hopTo, client.getMenuEntries(), after);
	}
}
 
Example 20
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));
}