Solved Armorstand got deleted right after spawning

Discussion in 'Spigot Plugin Development' started by Carster, Feb 8, 2020.

  1. Hi my armorstand despawn right after spawning and i want it to despawn like 10 secunds after
    Code (Text):

    import org.bukkit.Material;
    import org.bukkit.entity.ArmorStand;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;

    import java.util.List;

    public class EntityMoveEvent implements Listener {

        public void onPlayerMove(PlayerMoveEvent e) throws InterruptedException {

            Player player = e.getPlayer();
            Player p = e.getPlayer();
            ArmorStand armorstand = (ArmorStand) player.getWorld().spawnEntity(player.getLocation(), EntityType.ARMOR_STAND);
            armorstand.setHelmet(new ItemStack(Material.REDSTONE_BLOCK));

            List<Entity> nearbyEntities = p.getNearbyEntities(10, 10, 10);
            for (Entity entity: nearbyEntities) {
                if (entity.getType() == EntityType.ARMOR_STAND) entity.remove();


  2. Schedule a task with a delay of 20*10 ticks that you put your removal-code inside
  3. hOw Do I dO iT?
  4. Code (Java):
    new BukkitRunnable() {
        public void run() {
            // your code here        
    }.runTaskLater(<plugin instance>, 20*10);
  5. Thx u the best