use of com.magmaguy.elitemobs.utils.VisualArmorStand in project EliteMobs by MagmaGuy.
the class NPCProximitySensor method generateIndicator.
private void generateIndicator(NPCEntity npcEntity, Player player, String messageUp, String messageDown) {
Location newLocation = npcEntity.getVillager().getEyeLocation().clone().add(player.getLocation().clone().subtract(npcEntity.getVillager().getLocation()).toVector().normalize().multiply(0.5)).add(new Vector(0, -0.1, 0));
ArmorStand visualArmorStand = VisualArmorStand.VisualArmorStand(newLocation, messageUp);
AtomicInteger counter = new AtomicInteger();
AtomicBoolean up = new AtomicBoolean(true);
Bukkit.getScheduler().runTaskTimer(MetadataHandler.PLUGIN, task -> {
if (!player.isValid() || npcEntity.getVillager() == null || !npcEntity.getVillager().isValid() || !npcEntity.getVillager().getWorld().equals(player.getWorld()) || npcEntity.getVillager().getLocation().distance(player.getLocation()) > npcEntity.getNpCsConfigFields().getActivationRadius()) {
task.cancel();
EntityTracker.unregister(visualArmorStand, RemovalReason.EFFECT_TIMEOUT);
return;
}
counter.getAndIncrement();
if (counter.get() % 20 == 0) {
up.getAndSet(!up.get());
if (up.get())
visualArmorStand.setCustomName(messageUp);
else
visualArmorStand.setCustomName(messageDown);
}
visualArmorStand.teleport(visualArmorStand.getLocation().clone().add(new Vector(0, up.get() ? 0.01 : -0.01, 0)));
}, 0L, 1L);
}
Aggregations