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

The following examples show how to use net.runelite.api.events.MenuEntryAdded#getOpcode() . 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: CameraPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded)
{
	if (menuEntryAdded.getOpcode() == MenuOpcode.CC_OP.getId() && menuEntryAdded.getOption().equals(LOOK_NORTH) && config.compassLook())
	{
		MenuEntry[] menuEntries = client.getMenuEntries();
		int len = menuEntries.length;
		MenuEntry north = menuEntries[len - 1];

		menuEntries = Arrays.copyOf(menuEntries, len + 3);

		// The handling for these entries is done in ToplevelCompassOp.rs2asm
		menuEntries[--len] = createCameraLookEntry(menuEntryAdded, 4, LOOK_WEST);
		menuEntries[++len] = createCameraLookEntry(menuEntryAdded, 3, LOOK_EAST);
		menuEntries[++len] = createCameraLookEntry(menuEntryAdded, 2, LOOK_SOUTH);
		menuEntries[++len] = north;

		client.setMenuEntries(menuEntries);
	}
}
 
Example 2
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 3
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 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: 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 6
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 7
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 8
Source File: LeftClickCast.java    From ExternalPlugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
	if (event.getOpcode() == MenuOpcode.PLAYER_SECOND_OPTION.getId() && isMage)
	{
		final String name = Text.standardize(event.getTarget(), true);

		if (!config.disableFriendlyRegionChecks() && (client.getVar(Varbits.LMS_IN_GAME) == 0 && (client.isFriended(name, false) ||
			friendsManager.isMember(name))))
		{
			return;
		}

		if (!config.disableFriendlyRegionChecks())
		{
			try
			{
				boolean b = (!PvPUtil.isAttackable(client, client.getCachedPlayers()[event.getIdentifier()]));
			}
			catch (IndexOutOfBoundsException ex)
			{
				return;
			}
		}

		event.setModified();
		setSelectSpell(currentSpell.getSpell());
		event.setOption("(P) Left Click " + client.getSelectedSpellName() + " -> ");
	}
	else if (event.getOpcode() == MenuOpcode.NPC_SECOND_OPTION.getId() && isMage)
	{
		try
		{
			NPC npc = validateNpc(event.getIdentifier());

			if (npc == null)
			{
				return;
			}

			if (config.disableStaffChecks() && !whitelist.contains(npc.getId()))
			{
				return;
			}

			event.setModified();
			setSelectSpell(currentSpell.getSpell());
			event.setOption("(N) Left Click " + client.getSelectedSpellName() + " -> ");
		}
		catch (IndexOutOfBoundsException ignored)
		{
		}
	}
}