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

The following examples show how to use net.runelite.api.MenuEntry#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: MenuEntrySwapperPlugin.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void bankModeSwap(int entryTypeId, int entryIdentifier)
{
	MenuEntry[] menuEntries = client.getMenuEntries();

	for (int i = menuEntries.length - 1; i >= 0; --i)
	{
		MenuEntry entry = menuEntries[i];

		if (entry.getType() == entryTypeId && entry.getIdentifier() == entryIdentifier)
		{
			// Raise the priority of the op so it doesn't get sorted later
			entry.setType(MenuAction.CC_OP.getId());

			menuEntries[i] = menuEntries[menuEntries.length - 1];
			menuEntries[menuEntries.length - 1] = entry;

			client.setMenuEntries(menuEntries);
			break;
		}
	}
}
 
Example 2
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();
	}
}
 
Example 3
Source File: OpponentInfoPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private boolean modify(MenuEntry entry)
{
	if (isNotAttackEntry(entry))
	{
		return false;
	}

	boolean changed = false;

	int index = entry.getIdentifier();
	Actor actor = getActorFromIndex(index);

	if (actor == null)
	{
		return false;
	}

	if (actor instanceof Player)
	{
		index -= 32768;
	}

	String target = entry.getTarget();

	if (showAttacking &&
		client.getLocalPlayer().getRSInteracting() == index)
	{
		target = attackingColTag + target.substring(COLOR_TAG_LENGTH);
		changed = true;
	}

	if (showAttackers &&
		actor.getRSInteracting() - 32768 == client.getLocalPlayerIndex())
	{
		target = '*' + target;
		changed = true;
	}

	if (showHitpoints &&
		actor.getHealthScale() > 0)
	{
		int lvlIndex = target.lastIndexOf("(level-");
		if (lvlIndex != -1)
		{
			String levelReplacement = getHpString(actor, true);

			target = target.substring(0, lvlIndex) + levelReplacement;
			changed = true;
		}
	}

	if (changed)
	{
		entry.setTarget(target);
		return true;
	}

	return false;
}
 
Example 4
Source File: OpponentInfoPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private boolean fixup(MenuEntry entry)
{
	if (isNotAttackEntry(entry))
	{
		return false;
	}

	int index = entry.getIdentifier();

	Actor actor = getActorFromIndex(index);

	if (actor == null)
	{
		return false;
	}

	if (actor instanceof Player)
	{
		index -= 32768;
	}

	String target = entry.getTarget();

	boolean hasAggro = actor.getRSInteracting() - 32768 == client.getLocalPlayerIndex();
	boolean hadAggro = target.charAt(0) == '*';
	boolean isTarget = client.getLocalPlayer().getRSInteracting() == index;
	boolean hasHp = showHitpoints && actor instanceof NPC && actor.getHealthScale() > 0;

	boolean aggroChanged = showAttackers && hasAggro != hadAggro;
	boolean targetChanged = showAttacking && isTarget != target.startsWith(attackingColTag, aggroChanged ? 1 : 0);
	boolean hpChanged = showHitpoints && hasHp == target.contains("(level-");

	if (!aggroChanged &&
		!targetChanged &&
		!hasHp &&
		!hpChanged)
	{
		return false;
	}

	if (targetChanged)
	{
		boolean player = actor instanceof Player;
		final int start = hadAggro ? 1 + COLOR_TAG_LENGTH : COLOR_TAG_LENGTH;
		target =
			(hasAggro ? '*' : "") +
				(isTarget ? attackingColTag :
					player ? ColorUtil.colorStartTag(0xffffff) : ColorUtil.colorStartTag(0xffff00)) +
				target.substring(start);
	}
	else if (aggroChanged)
	{
		if (hasAggro)
		{
			target = '*' + target;
		}
		else
		{
			target = target.substring(1);
		}
	}

	if (hpChanged || hasHp)
	{
		final int braceIdx;

		if (!hasHp)
		{
			braceIdx = target.lastIndexOf("<col=ff0000>(");
			if (braceIdx != -1)
			{
				target = target.substring(0, braceIdx - 1) + "(level-" + actor.getCombatLevel() + ")";
			}
		}
		else if ((braceIdx = target.lastIndexOf('(')) != -1)
		{
			final String hpString = getHpString(actor, hpChanged);

			target = target.substring(0, braceIdx) + hpString;
		}
	}

	entry.setTarget(target);
	return true;
}
 
Example 5
Source File: DarkEssence.java    From ExternalPlugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isEntryValid(MenuEntry event)
{
	return event.getOpcode() == MenuOpcode.ITEM_USE.getId() &&
		event.getIdentifier() == ItemID.CHISEL;
}
 
Example 6
Source File: Compost.java    From ExternalPlugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isEntryValid(MenuEntry event)
{
	return event.getOpcode() == MenuOpcode.ITEM_USE.getId() &&
		event.getIdentifier() == ItemID.COMPOST;
}
 
Example 7
Source File: Compost.java    From ExternalPlugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean isClickValid(MenuEntry event)
{
	return event.getOpcode() == MenuOpcode.ITEM_USE.getId() &&
		event.getIdentifier() == ItemID.COMPOST;
}
 
Example 8
Source File: PlayerIndicatorsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onClientTick(ClientTick clientTick)
{
	if (client.isMenuOpen())
	{
		return;
	}

	MenuEntry[] menuEntries = client.getMenuEntries();
	boolean modified = false;

	for (MenuEntry entry : menuEntries)
	{
		int type = entry.getType();

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

		if (type == WALK.getId()
			|| type == SPELL_CAST_ON_PLAYER.getId()
			|| type == ITEM_USE_ON_PLAYER.getId()
			|| type == PLAYER_FIRST_OPTION.getId()
			|| type == PLAYER_SECOND_OPTION.getId()
			|| type == PLAYER_THIRD_OPTION.getId()
			|| type == PLAYER_FOURTH_OPTION.getId()
			|| type == PLAYER_FIFTH_OPTION.getId()
			|| type == PLAYER_SIXTH_OPTION.getId()
			|| type == PLAYER_SEVENTH_OPTION.getId()
			|| type == PLAYER_EIGTH_OPTION.getId()
			|| type == RUNELITE_PLAYER.getId())
		{
			Player[] players = client.getCachedPlayers();
			Player player = null;

			int identifier = entry.getIdentifier();

			// 'Walk here' identifiers are offset by 1 because the default
			// identifier for this option is 0, which is also a player index.
			if (type == WALK.getId())
			{
				identifier--;
			}

			if (identifier >= 0 && identifier < players.length)
			{
				player = players[identifier];
			}

			if (player == null)
			{
				continue;
			}

			Decorations decorations = getDecorations(player);

			if (decorations == null)
			{
				continue;
			}

			String oldTarget = entry.getTarget();
			String newTarget = decorateTarget(oldTarget, decorations);

			entry.setTarget(newTarget);
			modified = true;
		}
	}

	if (modified)
	{
		client.setMenuEntries(menuEntries);
	}
}
 
Example 9
Source File: InventoryTagsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public 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[GROUPS.size() + 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];

		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, MoreObjects.firstNonNull(color, Color.WHITE)));
			newMenu.setIdentifier(itemId);
			newMenu.setParam1(widgetId);
			newMenu.setType(MenuAction.RUNELITE.getId());
			menuList[num++] = newMenu;
		}

		client.setMenuEntries(menuList);
	}
}
 
Example 10
Source File: MenuEntrySwapperPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onMenuOpened(MenuOpened event)
{
	if (!configuringShiftClick)
	{
		return;
	}

	MenuEntry firstEntry = event.getFirstEntry();
	if (firstEntry == null)
	{
		return;
	}

	int widgetId = firstEntry.getParam1();
	if (widgetId != WidgetInfo.INVENTORY.getId())
	{
		return;
	}

	int itemId = firstEntry.getIdentifier();
	if (itemId == -1)
	{
		return;
	}

	ItemComposition itemComposition = client.getItemDefinition(itemId);
	String itemName = itemComposition.getName();
	String option = "Use";
	int shiftClickActionIndex = itemComposition.getShiftClickActionIndex();
	String[] inventoryActions = itemComposition.getInventoryActions();

	if (shiftClickActionIndex >= 0 && shiftClickActionIndex < inventoryActions.length)
	{
		option = inventoryActions[shiftClickActionIndex];
	}

	MenuEntry[] entries = event.getMenuEntries();

	for (MenuEntry entry : entries)
	{
		if (itemName.equals(Text.removeTags(entry.getTarget())))
		{
			entry.setType(MenuAction.RUNELITE.getId());

			if (option.equals(entry.getOption()))
			{
				entry.setOption("* " + option);
			}
		}
	}

	final MenuEntry resetShiftClickEntry = new MenuEntry();
	resetShiftClickEntry.setOption(RESET);
	resetShiftClickEntry.setTarget(MENU_TARGET);
	resetShiftClickEntry.setIdentifier(itemId);
	resetShiftClickEntry.setParam1(widgetId);
	resetShiftClickEntry.setType(MenuAction.RUNELITE.getId());
	client.setMenuEntries(ArrayUtils.addAll(entries, resetShiftClickEntry));
}