Solved Check if Zombies are dead every X seconds

Discussion in 'Plugin Development' started by Flysandwings, Jul 23, 2020.

  1. Offline

    Flysandwings

    Hello there beautiful people, first and foremost if you're reading this, thank you for spending the time.

    Now into the issue.

    Precursor:

    I have a zombie spawn on round one.

    Problem:

    On round one, one zombie spawns, and I need to check if it is dead, so I can move to the next round. I spawn this zombie using:

    Zombie z = ( Zombie ) world.spawnEntity(spawnLoc, EntityType.ZOMBIE);

    Now I want to check if this zombie has died every X number of seconds.


    However I get illegalmoniterexception.

    I'm using a bukkit runnable to do these checks my class is setup like this:
    Code:
    public class Rounds extends BukkitRunnable {
    
    
    private final JavaPlugin plugin;
    private static int round; 
     private static Utils util = new Utils(); 
       public Rounds(Zombies plugin){
        this.plugin = plugin;round=0;
      }
    
    
    @Overridepublic void run () {
        util.broadcast("Round: " + round); 
        while (true) {
           World w = Bukkit.getWorld("world");
           Location spawnLoc = new Location(w, 11.0, 101.0 + 2., 6.0);
            Zombie zomb = (Zombie) w.spawnEntity(spawnLoc, EntityType.ZOMBIE); 
            while (zomb.isDead() == false) {
                     if (zomb.isDead()) {
                       round++; 
                       } else {
                             try {
                                    wait(5000);
                             } catch (Exception e) {
                                 util.broadcast("ERROR: " + e);}
                             }
                       }
                 }
    
             }
    
    I have read scheuled programming guide for threads, however it doesn't click with me for some reason. Could someone explain this to me?
     
    Last edited by a moderator: Jul 23, 2020
  2. Offline

    Visualizeding

    I recommend you use a bukkit repeating scheduler instead of a while loop. It seems to me that the wait(5000) is causing the error.
     
  3. Offline

    Dai_Kunai

    Or use the EntityDeathEvent with @EventHandler and check if the entity is that entity (maybe by location or by naming it something unique).
     

Share This Page