Java Code Examples for net.runelite.api.events.MenuEntryAdded#setTarget()

The following examples show how to use net.runelite.api.events.MenuEntryAdded#setTarget() . 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: DevToolsPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded entry)
{
	if (!examine.isActive())
	{
		return;
	}

	MenuOpcode action = MenuOpcode.of(entry.getOpcode());

	if (EXAMINE_MENU_ACTIONS.contains(action))
	{
		final int identifier = entry.getIdentifier();
		String info = "ID: ";

		if (action == MenuOpcode.EXAMINE_NPC)
		{
			NPC npc = client.getCachedNPCs()[identifier];
			info += npc.getId();
		}
		else
		{
			info += identifier;

			if (action == MenuOpcode.EXAMINE_OBJECT)
			{
				WorldPoint point = WorldPoint.fromScene(client, entry.getParam0(), entry.getParam1(), client.getPlane());
				info += " X: " + point.getX() + " Y: " + point.getY();
			}
		}

		entry.setTarget(entry.getTarget() + " " + ColorUtil.prependColorTag("(" + info + ")", JagexColors.MENU_TARGET));
		entry.setModified();
	}
}
 
Example 2
Source File: NpcIndicatorsPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
void onMenuEntryAdded(MenuEntryAdded event)
{
	int type = event.getOpcode();

	if (type >= MENU_ACTION_DEPRIORITIZE_OFFSET)
	{
		type -= MENU_ACTION_DEPRIORITIZE_OFFSET;
	}

	final MenuOpcode menuOpcode = MenuOpcode.of(type);

	if (NPC_MENU_ACTIONS.contains(menuOpcode))
	{
		NPC npc = client.getCachedNPCs()[event.getIdentifier()];

		Color color = null;
		if (npc.isDead())
		{
			color = config.deadNpcMenuColor();
		}

		if (color == null && highlightedNpcs.contains(npc) && config.highlightMenuNames() && (!npc.isDead() || !config.ignoreDeadNpcs()))
		{
			color = config.getHighlightColor();
		}

		if (color != null)
		{
			final String target = ColorUtil.prependColorTag(Text.removeTags(event.getTarget()), color);
			event.setTarget(target);
			event.setModified();
		}
	}
	else if (type == MenuOpcode.EXAMINE_NPC.getId() && client.isKeyPressed(KeyCode.KC_SHIFT))
	{
		// Add tag option
		client.insertMenuItem(
			highlightedNpcs.stream().anyMatch(npc -> npc.getIndex() == event.getIdentifier()) ? UNTAG : TAG,
			event.getTarget(),
			MenuOpcode.RUNELITE.getId(),
			event.getIdentifier(),
			event.getParam0(),
			event.getParam1(),
			false
		);
	}
}
 
Example 3
Source File: GroundItemsPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded lastEntry)
{
	if (config.itemHighlightMode() != OVERLAY)
	{
		final boolean telegrabEntry = lastEntry.getOption().equals("Cast") && lastEntry.getTarget().startsWith(TELEGRAB_TEXT) && lastEntry.getOpcode() == CAST_ON_ITEM;
		if (!(lastEntry.getOption().equals("Take") && lastEntry.getOpcode() == THIRD_OPTION) && !telegrabEntry)
		{
			return;
		}

		final int itemId = lastEntry.getIdentifier();
		final int sceneX = lastEntry.getParam0();
		final int sceneY = lastEntry.getParam1();

		final WorldPoint worldPoint = WorldPoint.fromScene(client, sceneX, sceneY, client.getPlane());
		GroundItem.GroundItemKey groundItemKey = new GroundItem.GroundItemKey(itemId, worldPoint);
		GroundItem groundItem = collectedGroundItems.get(groundItemKey);
		int quantity = groundItem.getQuantity();

		final int gePrice = groundItem.getGePrice();
		final int haPrice = groundItem.getHaPrice();
		final Color hidden = getHidden(new NamedQuantity(groundItem.getName(), quantity), gePrice, haPrice, groundItem.isTradeable());
		final Color highlighted = getHighlighted(new NamedQuantity(groundItem.getName(), quantity), gePrice, haPrice);
		final Color color = getItemColor(highlighted, hidden);
		final boolean canBeRecolored = highlighted != null || (hidden != null && config.recolorMenuHiddenItems());

		if (color != null && canBeRecolored && !color.equals(config.defaultColor()))
		{
			final MenuHighlightMode mode = config.menuHighlightMode();

			if (mode == BOTH || mode == OPTION)
			{
				final String optionText = telegrabEntry ? "Cast" : "Take";
				lastEntry.setOption(ColorUtil.prependColorTag(optionText, color));
				lastEntry.setModified();
			}

			if (mode == BOTH || mode == NAME)
			{
				String target = lastEntry.getTarget();

				if (telegrabEntry)
				{
					target = target.substring(TELEGRAB_TEXT.length());
				}

				target = ColorUtil.prependColorTag(target.substring(target.indexOf('>') + 1), color);

				if (telegrabEntry)
				{
					target = TELEGRAB_TEXT + target;
				}

				lastEntry.setTarget(target);
				lastEntry.setModified();
			}
		}

		if (config.showMenuItemQuantities() && groundItem.isStackable() && quantity > 1)
		{
			lastEntry.setTarget(lastEntry.getTarget() + " (" + quantity + ")");
			lastEntry.setModified();
		}

		if (config.removeIgnored() && lastEntry.getOption().equals("Take") && hiddenItemList.contains(Text.removeTags(lastEntry.getTarget())))
		{
			client.setMenuOptionCount(client.getMenuOptionCount() - 1);
		}
	}
}
 
Example 4
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();
	}
}