Java Code Examples for net.runelite.api.Actor#getName()

The following examples show how to use net.runelite.api.Actor#getName() . 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: BarbarianAssaultPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe
private void onProjectileSpawned(ProjectileSpawned event)
{
	if (!isInGame())
	{
		return;
	}

	Actor target = event.getProjectile().getInteracting();
	if (target == null)
	{
		return;
	}

	String name = target.getName();
	if ("Penance Fighter".equals(name) || "Penance Ranger".equals(name))
	{
		projectiles.put(((NPC) target).getIndex(), event.getProjectile());
	}
}
 
Example 2
Source File: PlayerIndicatorsPlugin.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks if a player is a caller
 *
 * @param player The player to check
 * @return true if they are, false otherwise
 */
boolean isCaller(Actor player)
{
	if (player == null || player.getName() == null)
	{
		return false;
	}

	if (callers.size() > 0)
	{
		for (String name : callers)
		{
			String finalName = Text.standardize(name.trim());
			if (Text.standardize(player.getName()).equals(finalName))
			{
				return true;
			}
		}
	}

	return false;
}
 
Example 3
Source File: PohPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onAnimationChanged(AnimationChanged event)
{
	final Actor actor = event.getActor();
	final String actorName = actor.getName();

	if (!(actor instanceof Player) || actor.getAnimation() != AnimationID.INCENSE_BURNER)
	{
		return;
	}

	final LocalPoint loc = actor.getLocalLocation();

	// Find burner closest to player
	incenseBurners.keySet()
		.stream()
		.min(Comparator.comparingInt(a -> loc.distanceTo(a.getLocalLocation())))
		.ifPresent(tile ->
		{
			final IncenseBurner incenseBurner = incenseBurners.get(tile);

			if (actor == client.getLocalPlayer())
			{
				int level = client.getRealSkillLevel(net.runelite.api.Skill.FIREMAKING);
				updateBurner(incenseBurner, level);
			}
			else if (actorName != null)
			{
				lookupPlayer(actorName, incenseBurner);
			}
		});

}
 
Example 4
Source File: PohPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onAnimationChanged(AnimationChanged event)
{
	final Actor actor = event.getActor();
	final String actorName = actor.getName();

	if (!(actor instanceof Player) || actor.getAnimation() != AnimationID.INCENSE_BURNER)
	{
		return;
	}

	final LocalPoint loc = actor.getLocalLocation();

	// Find burner closest to player
	incenseBurners.keySet()
		.stream()
		.min(Comparator.comparingInt(a -> loc.distanceTo(a.getLocalLocation())))
		.ifPresent(tile ->
		{
			final IncenseBurner incenseBurner = incenseBurners.get(tile);

			if (actor == client.getLocalPlayer())
			{
				int level = client.getRealSkillLevel(net.runelite.api.Skill.FIREMAKING);
				updateBurner(incenseBurner, level);
			}
			else if (actorName != null)
			{
				lookupPlayer(actorName, incenseBurner);
			}
		});

}
 
Example 5
Source File: DevToolsOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private void renderProjectiles(Graphics2D graphics)
{
	List<Projectile> projectiles = client.getProjectiles();

	for (Projectile projectile : projectiles)
	{
		int originX = projectile.getX1();
		int originY = projectile.getY1();

		LocalPoint tilePoint = new LocalPoint(originX, originY);
		Polygon poly = Perspective.getCanvasTilePoly(client, tilePoint);

		if (poly != null)
		{
			OverlayUtil.renderPolygon(graphics, poly, Color.RED);
		}

		int projectileId = projectile.getId();
		Actor projectileInteracting = projectile.getInteracting();

		String infoString = "";

		if (projectileInteracting == null)
		{
			infoString += "AoE";
		}
		else
		{
			infoString += "Targeted (T: " + projectileInteracting.getName() + ")";
		}

		infoString += " (ID: " + projectileId + ")";

		if (projectileInteracting != null)
		{
			OverlayUtil.renderActorOverlay(graphics, projectile.getInteracting(), infoString, Color.RED);
		}
		else
		{
			LocalPoint projectilePoint = new LocalPoint((int) projectile.getX(), (int) projectile.getY());
			Point textLocation = Perspective.getCanvasTextLocation(client, graphics, projectilePoint, infoString, 0);

			if (textLocation != null)
			{
				OverlayUtil.renderTextLocation(graphics, textLocation, infoString, Color.RED);
			}
		}
	}
}
 
Example 6
Source File: IdleNotifierPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Subscribe
void onInteractingChanged(InteractingChanged event)
{
	final Actor source = event.getSource();
	if (source != client.getLocalPlayer())
	{
		return;
	}

	final Actor target = event.getTarget();

	// Reset last interact
	if (target != null)
	{
		lastInteract = null;
	}
	else
	{
		lastInteracting = Instant.now();
	}

	final boolean isNpc = target instanceof NPC;

	// If this is not NPC, do not process as we are not interested in other entities
	if (!isNpc)
	{
		return;
	}

	final NPC npc = (NPC) target;
	final NPCDefinition npcComposition = npc.getDefinition();
	final List<String> npcMenuActions = Arrays.asList(npcComposition.getActions());

	if (npcMenuActions.contains("Attack"))
	{
		// Player is most likely in combat with attack-able NPC
		resetTimers();
		lastInteract = target;
		lastInteracting = Instant.now();
		lastInteractWasCombat = true;
	}
	else if (target.getName() != null && target.getName().contains(FISHING_SPOT))
	{
		// Player is fishing
		resetTimers();
		lastInteract = target;
		lastInteracting = Instant.now();
		lastInteractWasCombat = false;
	}
}
 
Example 7
Source File: OpponentInfoOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	final Actor opponent = opponentInfoPlugin.getLastOpponent();

	if (opponent == null)
	{
		opponentName = null;
		return null;
	}

	if (opponent.getName() != null && opponent.getHealthScale() > 0)
	{
		lastRatio = opponent.getHealthRatio();
		lastHealthScale = opponent.getHealthScale();
		opponentName = Text.removeTags(opponent.getName());

		lastMaxHealth = opponentInfoPlugin.getMaxHp(opponent);
	}

	if (opponentName == null)
	{
		return null;
	}

	final FontMetrics fontMetrics = graphics.getFontMetrics();

	// Opponent name
	int panelWidth = Math.max(ComponentConstants.STANDARD_WIDTH, fontMetrics.stringWidth(opponentName) + ComponentConstants.STANDARD_BORDER + ComponentConstants.STANDARD_BORDER);
	panelComponent.setPreferredSize(new Dimension(panelWidth, 0));
	panelComponent.getChildren().add(TitleComponent.builder()
		.text(opponentName)
		.build());

	// Health bar
	if (lastRatio >= 0 && lastHealthScale > 0)
	{
		final ProgressBarComponent progressBarComponent = new ProgressBarComponent();
		progressBarComponent.setBackgroundColor(HP_RED);
		progressBarComponent.setForegroundColor(HP_GREEN);

		final HitpointsDisplayStyle displayStyle = opponentInfoConfig.hitpointsDisplayStyle();

		if ((displayStyle == HitpointsDisplayStyle.HITPOINTS || displayStyle == HitpointsDisplayStyle.BOTH)
			&& lastMaxHealth != -1)
		{
			int health = getExactHp(lastRatio, lastHealthScale, lastMaxHealth);

			// Show both the hitpoint and percentage values if enabled in the config
			final ProgressBarComponent.LabelDisplayMode progressBarDisplayMode = displayStyle == HitpointsDisplayStyle.BOTH ?
				ProgressBarComponent.LabelDisplayMode.BOTH : ProgressBarComponent.LabelDisplayMode.FULL;

			progressBarComponent.setLabelDisplayMode(progressBarDisplayMode);
			progressBarComponent.setMaximum(lastMaxHealth);
			progressBarComponent.setValue(health);
		}
		else
		{
			float floatRatio = (float) lastRatio / (float) lastHealthScale;
			progressBarComponent.setValue(floatRatio * 100d);
		}

		panelComponent.getChildren().add(progressBarComponent);
	}

	// Opponents opponent
	if (opponentsOpponentName != null)
	{
		panelWidth = Math.max(panelWidth, fontMetrics.stringWidth(opponentsOpponentName) + ComponentConstants.STANDARD_BORDER + ComponentConstants.STANDARD_BORDER);
		panelComponent.setPreferredSize(new Dimension(panelWidth, 0));
		panelComponent.getChildren().add(TitleComponent.builder()
			.text(opponentsOpponentName)
			.build());
	}

	return super.render(graphics);
}
 
Example 8
Source File: IdleNotifierPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Subscribe
public void onInteractingChanged(InteractingChanged event)
{
	final Actor source = event.getSource();
	if (source != client.getLocalPlayer())
	{
		return;
	}

	final Actor target = event.getTarget();

	// Reset last interact
	if (target != null)
	{
		lastInteract = null;
	}
	else
	{
		lastInteracting = Instant.now();
	}

	final boolean isNpc = target instanceof NPC;

	// If this is not NPC, do not process as we are not interested in other entities
	if (!isNpc)
	{
		return;
	}

	final NPC npc = (NPC) target;
	final NPCComposition npcComposition = npc.getComposition();
	final List<String> npcMenuActions = Arrays.asList(npcComposition.getActions());

	if (npcMenuActions.contains("Attack"))
	{
		// Player is most likely in combat with attack-able NPC
		resetTimers();
		lastInteract = target;
		lastInteracting = Instant.now();
		lastInteractWasCombat = true;
	}
	else if (target.getName() != null && target.getName().contains(FISHING_SPOT))
	{
		// Player is fishing
		resetTimers();
		lastInteract = target;
		lastInteracting = Instant.now();
		lastInteractWasCombat = false;
	}
}