Ir para conteúdo
  • 0

Como pegar o player que estou olhando


Muloo

Pergunta

6 respostass a esta questão

Posts Recomendados

Obrigado, mais eu gostaria de fazer um plugin sem o uso de APIs

 

Tenta isso ai então, eu uso esse método

	@SuppressWarnings({ "unused" })
	public <T extends Player> T getTarget(final Player entity, final Iterable<T> entities) {
		if (entity == null) {
			return null;
		}
		T target = null;
		final double threshold = 1.0;
		for (final T other : entities) {
			final Vector n = other.getLocation().toVector().subtract(entity.getLocation().toVector());
			if (entity.getLocation().getDirection().normalize().crossProduct(n).lengthSquared() < 1.0 && n.normalize().dot(entity.getLocation().getDirection().normalize()) >= 0.0) {
				if (target == null || target.getLocation().distanceSquared(entity.getLocation()) > other.getLocation().distanceSquared(entity.getLocation())) {
					target = other;
				}
				// aqui é o código!
			}
		}
		return target;
	}

	public Player getTargetPlayer(final Player player) {
		return this.getTarget(player, (Iterable<Player>) player.getWorld().getPlayers());
	}

	@EventHandler
	public void PlayerMoveEvent(final PlayerMoveEvent e) {
		final Player p = e.getPlayer();
		this.getTargetPlayer(p);
	}
Link para o comentário
Compartilhar em outros sites

 

 

 

Tenta isso ai então, eu uso esse método

@SuppressWarnings({ "unused" })
	public <T extends Player> T getTarget(final Player entity, final Iterable<T> entities) {
		if (entity == null) {
			return null;
		}
		T target = null;
		final double threshold = 1.0;
		for (final T other : entities) {
			final Vector n = other.getLocation().toVector().subtract(entity.getLocation().toVector());
			if (entity.getLocation().getDirection().normalize().crossProduct(n).lengthSquared() < 1.0 && n.normalize().dot(entity.getLocation().getDirection().normalize()) >= 0.0) {
				if (target == null || target.getLocation().distanceSquared(entity.getLocation()) > other.getLocation().distanceSquared(entity.getLocation())) {
					target = other;
				}
				// aqui é o código!
			}
		}
		return target;
	}

	public Player getTargetPlayer(final Player player) {
		return this.getTarget(player, (Iterable<Player>) player.getWorld().getPlayers());
	}

	@EventHandler
	public void PlayerMoveEvent(final PlayerMoveEvent e) {
		final Player p = e.getPlayer();
		this.getTargetPlayer(p);
	}

Recomendo fazer um sistema de cooldown,se não pode lagar.

Editado por n00bmobile
Link para o comentário
Compartilhar em outros sites

 

Tenta isso ai então, eu uso esse método

	@SuppressWarnings({ "unused" })
	public <T extends Player> T getTarget(final Player entity, final Iterable<T> entities) {
		if (entity == null) {
			return null;
		}
		T target = null;
		final double threshold = 1.0;
		for (final T other : entities) {
			final Vector n = other.getLocation().toVector().subtract(entity.getLocation().toVector());
			if (entity.getLocation().getDirection().normalize().crossProduct(n).lengthSquared() < 1.0 && n.normalize().dot(entity.getLocation().getDirection().normalize()) >= 0.0) {
				if (target == null || target.getLocation().distanceSquared(entity.getLocation()) > other.getLocation().distanceSquared(entity.getLocation())) {
					target = other;
				}
				// aqui é o código!
			}
		}
		return target;
	}

	public Player getTargetPlayer(final Player player) {
		return this.getTarget(player, (Iterable<Player>) player.getWorld().getPlayers());
	}

	@EventHandler
	public void PlayerMoveEvent(final PlayerMoveEvent e) {
		final Player p = e.getPlayer();
		this.getTargetPlayer(p);
	}

Obrigado

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...