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

The following examples show how to use net.runelite.api.events.MenuEntryAdded#getIdentifier() . 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: CorpPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
private void onMenuEntryAdded(MenuEntryAdded event)
{
	if (event.getOpcode() != NPC_SECOND_OPTION.getId()
		|| !config.leftClickCore() || !event.getOption().equals(ATTACK))
	{
		return;
	}

	final int npcIndex = event.getIdentifier();
	final NPC npc = client.getCachedNPCs()[npcIndex];
	if (npc == null || !npc.getName().equals(DARK_ENERGY_CORE))
	{
		return;
	}

	event.setOpcode(NPC_SECOND_OPTION.getId() + MENU_ACTION_DEPRIORITIZE_OFFSET);
	event.setModified();
}
 
Example 2
Source File: OpponentInfoPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded)
{
	if (menuEntryAdded.getType() != MenuAction.NPC_SECOND_OPTION.getId()
		|| !menuEntryAdded.getOption().equals("Attack")
		|| !config.showOpponentsInMenu())
	{
		return;
	}

	int npcIndex = menuEntryAdded.getIdentifier();
	NPC npc = client.getCachedNPCs()[npcIndex];
	if (npc == null)
	{
		return;
	}

	if (npc.getInteracting() == client.getLocalPlayer() || lastOpponent == npc)
	{
		MenuEntry[] menuEntries = client.getMenuEntries();
		menuEntries[menuEntries.length - 1].setTarget("*" + menuEntryAdded.getTarget());
		client.setMenuEntries(menuEntries);
	}
}
 
Example 3
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 4
Source File: RandomEventPlugin.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.NPC_FIRST_OPTION.getId()
		&& event.getOpcode() <= MenuOpcode.NPC_FIFTH_OPTION.getId()
		&& EVENT_OPTIONS.contains(event.getOption()))
	{
		NPC npc = client.getCachedNPCs()[event.getIdentifier()];
		if (npc != null && EVENT_NPCS.contains(npc.getId()) && npc != currentRandomEvent && config.removeMenuOptions())
		{
			client.setMenuEntries(Arrays.copyOf(client.getMenuEntries(), client.getMenuEntries().length - 1));
		}
	}
}
 
Example 5
Source File: DevToolsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	if (!examine.isActive())
	{
		return;
	}

	MenuAction action = MenuAction.of(event.getType());

	if (EXAMINE_MENU_ACTIONS.contains(action))
	{
		MenuEntry[] entries = client.getMenuEntries();
		MenuEntry entry = entries[entries.length - 1];

		final int identifier = event.getIdentifier();
		String info = "ID: ";

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

			if (action == MenuAction.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));
		client.setMenuEntries(entries);
	}
}
 
Example 6
Source File: RandomEventPlugin.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.NPC_FIRST_OPTION.getId()
		&& event.getType() <= MenuAction.NPC_FIFTH_OPTION.getId()
		&& EVENT_OPTIONS.contains(event.getOption()))
	{
		NPC npc = client.getCachedNPCs()[event.getIdentifier()];
		if (npc != null && EVENT_NPCS.contains(npc.getId()) && npc != currentRandomEvent && config.removeMenuOptions())
		{
			client.setMenuEntries(Arrays.copyOf(client.getMenuEntries(), client.getMenuEntries().length - 1));
		}
	}
}
 
Example 7
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 8
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 9
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 10
Source File: GroundItemsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	if (config.itemHighlightMode() != OVERLAY)
	{
		final boolean telegrabEntry = event.getOption().equals("Cast") && event.getTarget().startsWith(TELEGRAB_TEXT) && event.getType() == CAST_ON_ITEM;
		if (!(event.getOption().equals("Take") && event.getType() == THIRD_OPTION) && !telegrabEntry)
		{
			return;
		}

		final int itemId = event.getIdentifier();
		final int sceneX = event.getActionParam0();
		final int sceneY = event.getActionParam1();

		MenuEntry[] menuEntries = client.getMenuEntries();
		MenuEntry lastEntry = menuEntries[menuEntries.length - 1];

		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));
			}

			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);
			}
		}

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

		client.setMenuEntries(menuEntries);
	}
}