Search in sources :

Example 1 with VisualArmorStand

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VisualArmorStand(com.magmaguy.elitemobs.utils.VisualArmorStand) ArmorStand(org.bukkit.entity.ArmorStand) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Aggregations

VisualArmorStand (com.magmaguy.elitemobs.utils.VisualArmorStand)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Location (org.bukkit.Location)1 ArmorStand (org.bukkit.entity.ArmorStand)1 Vector (org.bukkit.util.Vector)1