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

The following examples show how to use net.runelite.api.MenuEntry#setOpcode() . 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: Seeds.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().toLowerCase().contains("tithe"))
	{
		if (plugin.updateSelectedItem(SEED_SET))
		{
			event.setOpcode(MenuOpcode.ITEM_USE_ON_GAME_OBJECT.getId());
		}
	}
	else if (event.getTarget().toLowerCase().contains("water barrel"))
	{
		if (plugin.updateSelectedItem(WATERING_CANS))
		{
			event.setOpcode(MenuOpcode.ITEM_USE_ON_GAME_OBJECT.getId());
		}
	}
}
 
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: Birdhouses.java    From ExternalPlugins with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void modifyEntry(OneClickPlugin plugin, MenuEntry event)
{
	if (plugin.findItem(HOPS_SEED).getLeft() == -1)
	{
		return;
	}

	event.setOption("Use");
	event.setTarget("<col=ff9040>Hops seed<col=ffffff> -> " + plugin.getTargetMap().get(event.getIdentifier()));
	event.setOpcode(MenuOpcode.ITEM_USE_ON_GAME_OBJECT.getId());
	event.setForceLeftClick(true);
}
 
Example 5
Source File: Tiara.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 (plugin.updateSelectedItem(ItemID.TIARA))
	{
		event.setOpcode(MenuOpcode.ITEM_USE_ON_GAME_OBJECT.getId());
	}
}
 
Example 6
Source File: Healer.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 (event.getTarget().equalsIgnoreCase("<col=ff9040>Food<col=ffffff> -> <col=ffff00>Penance Healer"))
	{
		if (plugin.updateSelectedItem(ITEMS.getOrDefault(plugin.getRoleText(), -1)))
		{
			event.setOpcode(MenuOpcode.ITEM_USE_ON_NPC.getId());
		}
	}
}
 
Example 7
Source File: Herbtar.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 (plugin.updateSelectedItem(ItemID.SWAMP_TAR))
	{
		event.setOpcode(MenuOpcode.ITEM_USE_ON_WIDGET_ITEM.getId());
	}
}
 
Example 8
Source File: Darts.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 (plugin.updateSelectedItem(ItemID.FEATHER))
	{
		event.setOpcode(MenuOpcode.ITEM_USE_ON_WIDGET_ITEM.getId());
	}
}
 
Example 9
Source File: DarkEssence.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 (plugin.updateSelectedItem(ItemID.DARK_ESSENCE_BLOCK))
	{
		event.setOpcode(MenuOpcode.ITEM_USE_ON_WIDGET_ITEM.getId());
	}
}
 
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: 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 12
Source File: Bones.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 (plugin.updateSelectedItem(BONE_SET))
	{
		event.setOpcode(MenuOpcode.ITEM_USE_ON_GAME_OBJECT.getId());
	}
}
 
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: Compost.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 (plugin.updateSelectedItem(ItemID.SALTPETRE))
	{
		event.setOpcode(MenuOpcode.ITEM_USE_ON_WIDGET_ITEM.getId());
	}
}
 
Example 15
Source File: Karambwans.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 (plugin.updateSelectedItem(ItemID.RAW_KARAMBWAN))
	{
		event.setOpcode(MenuOpcode.ITEM_USE_ON_GAME_OBJECT.getId());
		plugin.setTick(true);
	}
}
 
Example 16
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 17
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 18
Source File: Firemaking.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 (plugin.updateSelectedItem(ItemID.TINDERBOX))
	{
		event.setOpcode(MenuOpcode.ITEM_USE_ON_WIDGET_ITEM.getId());
	}
}
 
Example 19
Source File: OneClickPlugin.java    From ExternalPlugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	final int id = event.getIdentifier();
	targetMap.put(id, event.getTarget());

	if (config.customInvSwap() && customClickMap.getOrDefault(id, null) != null)
	{
		if (event.getOpcode() == MenuOpcode.ITEM_USE.getId() && customClickMap.containsKey(id))
		{
			int item = findItem(customClickMap.get(id)).getLeft();
			if (item == -1)
			{
				return;
			}
			final String name = client.getItemDefinition(item).getName();
			event.setTarget("<col=ff9040>" + name + "<col=ffffff> -> " + targetMap.get(id));
			event.setForceLeftClick(true);
			event.setModified();
			return;
		}
	}

	switch (type)
	{
		case SEED_SET:
		case BA_HEALER:
			if (event.getOpcode() == MenuOpcode.WALK.getId())
			{
				MenuEntry menuEntry = client.getLeftClickMenuEntry();
				menuEntry.setOpcode(MenuOpcode.WALK.getId() + MENU_ACTION_DEPRIORITIZE_OFFSET);
				client.setLeftClickMenuEntry(menuEntry);
			}
			break;
		default:
			break;
	}

	if (comparable == null)
	{
		log.error("This should not be possible.");
		throw new AssertionError();
	}

	if (type == Types.SPELL && clickItem == null)
	{
		return;
	}

	if (comparable.isEntryValid(event))
	{
		comparable.modifyEntry(this, event);
		event.setModified();
	}
}
 
Example 20
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();
	}
}