Java Code Examples for net.runelite.api.events.MenuOptionClicked#getId()

The following examples show how to use net.runelite.api.events.MenuOptionClicked#getId() . 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: NpcIndicatorsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked click)
{
	if (click.getMenuAction() != MenuAction.RUNELITE ||
		!(click.getMenuOption().equals(TAG) || click.getMenuOption().equals(UNTAG)))
	{
		return;
	}

	final int id = click.getId();
	final boolean removed = npcTags.remove(id);
	final NPC[] cachedNPCs = client.getCachedNPCs();
	final NPC npc = cachedNPCs[id];

	if (npc == null || npc.getName() == null)
	{
		return;
	}

	if (removed)
	{
		highlightedNpcs.remove(npc);
		memorizedNpcs.remove(npc.getIndex());
	}
	else
	{
		if (!client.isInInstancedRegion())
		{
			memorizeNpc(npc);
			npcTags.add(id);
		}
		highlightedNpcs.add(npc);
	}

	click.consume();
}
 
Example 2
Source File: GroundItemsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked menuOptionClicked)
{
	if (menuOptionClicked.getMenuAction() == MenuAction.ITEM_DROP)
	{
		int itemId = menuOptionClicked.getId();
		// Keep a queue of recently dropped items to better detect
		// item spawns that are drops
		droppedItemQueue.add(itemId);
	}
}
 
Example 3
Source File: LootTrackerPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
	// There are some pickpocket targets who show up in the chat box with a different name (e.g. H.A.M. members -> man/woman)
	// We use the value selected from the right-click menu as a fallback for the event lookup in those cases.
	if (event.getMenuOption().equals("Pickpocket"))
	{
		lastPickpocketTarget = Text.removeTags(event.getMenuTarget());
	}

	if (event.getMenuOption().equals("Take") && event.getId() == ItemID.SEED_PACK)
	{
		eventType = SEEDPACK_EVENT;
		lootRecordType = LootRecordType.EVENT;
		takeInventorySnapshot();
	}

	if (event.getMenuOption().equals("Open") && SHADE_CHEST_OBJECTS.containsKey(event.getId()))
	{
		eventType = SHADE_CHEST_OBJECTS.get(event.getId());
		lootRecordType = LootRecordType.EVENT;
		takeInventorySnapshot();
	}

	if (event.getMenuOption().equals("Open") && event.getId() == ItemID.CASKET)
	{
		eventType = CASKET_EVENT;
		lootRecordType = LootRecordType.EVENT;
		takeInventorySnapshot();
	}
}
 
Example 4
Source File: ExaminePlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
	if (!Text.removeTags(event.getMenuOption()).equals("Examine"))
	{
		return;
	}

	ExamineType type;
	int id, quantity = -1;
	switch (event.getMenuAction())
	{
		case EXAMINE_ITEM:
		{
			type = ExamineType.ITEM;
			id = event.getId();

			int widgetId = event.getWidgetId();
			int widgetGroup = TO_GROUP(widgetId);
			int widgetChild = TO_CHILD(widgetId);
			Widget widget = client.getWidget(widgetGroup, widgetChild);
			WidgetItem widgetItem = widget.getWidgetItem(event.getActionParam());
			quantity = widgetItem != null && widgetItem.getId() >= 0 ? widgetItem.getQuantity() : 1;
			break;
		}
		case EXAMINE_ITEM_GROUND:
			type = ExamineType.ITEM;
			id = event.getId();
			break;
		case CC_OP_LOW_PRIORITY:
		{
			type = ExamineType.ITEM_BANK_EQ;
			int[] qi = findItemFromWidget(event.getWidgetId(), event.getActionParam());
			if (qi == null)
			{
				log.debug("Examine for item with unknown widget: {}", event);
				return;
			}
			quantity = qi[0];
			id = qi[1];
			break;
		}
		case EXAMINE_OBJECT:
			type = ExamineType.OBJECT;
			id = event.getId();
			break;
		case EXAMINE_NPC:
			type = ExamineType.NPC;
			id = event.getId();
			break;
		default:
			return;
	}

	PendingExamine pendingExamine = new PendingExamine();
	pendingExamine.setType(type);
	pendingExamine.setId(id);
	pendingExamine.setQuantity(quantity);
	pendingExamine.setCreated(Instant.now());
	pending.push(pendingExamine);
}
 
Example 5
Source File: TimersPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
	if (config.showStamina()
		&& event.getMenuOption().contains("Drink")
		&& (event.getId() == ItemID.STAMINA_MIX1
		|| event.getId() == ItemID.STAMINA_MIX2
		|| event.getId() == ItemID.EGNIOL_POTION_1
		|| event.getId() == ItemID.EGNIOL_POTION_2
		|| event.getId() == ItemID.EGNIOL_POTION_3
		|| event.getId() == ItemID.EGNIOL_POTION_4))
	{
		// Needs menu option hook because mixes use a common drink message, distinct from their standard potion messages
		createStaminaTimer();
		return;
	}

	if (config.showAntiFire()
		&& event.getMenuOption().contains("Drink")
		&& (event.getId() == ItemID.ANTIFIRE_MIX1
		|| event.getId() == ItemID.ANTIFIRE_MIX2))
	{
		// Needs menu option hook because mixes use a common drink message, distinct from their standard potion messages
		createGameTimer(ANTIFIRE);
		return;
	}

	if (config.showAntiFire()
		&& event.getMenuOption().contains("Drink")
		&& (event.getId() == ItemID.EXTENDED_ANTIFIRE_MIX1
		|| event.getId() == ItemID.EXTENDED_ANTIFIRE_MIX2))
	{
		// Needs menu option hook because mixes use a common drink message, distinct from their standard potion messages
		createGameTimer(EXANTIFIRE);
		return;
	}

	if (config.showAntiFire()
		&& event.getMenuOption().contains("Drink")
		&& (event.getId() == ItemID.SUPER_ANTIFIRE_MIX1
		|| event.getId() == ItemID.SUPER_ANTIFIRE_MIX2))
	{
		// Needs menu option hook because mixes use a common drink message, distinct from their standard potion messages
		createGameTimer(SUPERANTIFIRE);
		return;
	}

	if (config.showAntiFire()
		&& event.getMenuOption().contains("Drink")
		&& (event.getId() == ItemID.EXTENDED_SUPER_ANTIFIRE_MIX1
		|| event.getId() == ItemID.EXTENDED_SUPER_ANTIFIRE_MIX2))
	{
		// Needs menu option hook because mixes use a common drink message, distinct from their standard potion messages
		createGameTimer(EXSUPERANTIFIRE);
		return;
	}

	TeleportWidget teleportWidget = TeleportWidget.of(event.getWidgetId());
	if (teleportWidget != null)
	{
		lastTeleportClicked = teleportWidget;
	}
}
 
Example 6
Source File: MenuEntrySwapperPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
	if (event.getMenuAction() != MenuAction.RUNELITE || event.getWidgetId() != WidgetInfo.INVENTORY.getId())
	{
		return;
	}

	int itemId = event.getId();

	if (itemId == -1)
	{
		return;
	}

	String option = event.getMenuOption();
	String target = event.getMenuTarget();
	ItemComposition itemComposition = client.getItemDefinition(itemId);

	if (option.equals(RESET) && target.equals(MENU_TARGET))
	{
		unsetSwapConfig(itemId);
		return;
	}

	if (!itemComposition.getName().equals(Text.removeTags(target)))
	{
		return;
	}

	if (option.equals("Use")) //because "Use" is not in inventoryActions
	{
		setSwapConfig(itemId, -1);
	}
	else
	{
		String[] inventoryActions = itemComposition.getInventoryActions();

		for (int index = 0; index < inventoryActions.length; index++)
		{
			if (option.equals(inventoryActions[index]))
			{
				setSwapConfig(itemId, index);
				break;
			}
		}
	}
}