Ir para conteúdo
  • 0

Como pegar o player que estou olhando


Pergunta

Postado

Olá galera, gostaria de pedir a ajuda de vocês para pegar o jogador que estou olhando, sei que tenho que usar PlayerMoveEvent mas não faço a menor ideia de como ;-;

6 respostass a esta questão

Posts Recomendados

Postado

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);
	}
Postado (editado)

 

 

 

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
Postado

 

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

Postado

logo-forum.png




Sua dúvida foi marcada como [Resolvido] e movido à área de dúvidas resolvidas.


Atenciosamente,
Gamer's Board
Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...