CreatureSpawner getDelay

Discussion in 'Plugin Development' started by Kevinzuman22, Jun 27, 2019.

  1. Offline

    Kevinzuman22

    In one of my plugins I had a feature where the remaining delay for a spawner was showed above the spawner with the help of HolographicDisplays. Up until now, that has worked just fine. But now that I am updating the plugin to 1.14.2, the number returned by CreatureSpawner.getDelay() is only updated after a spawner has spawned entities. I have not changed the code for it in any way, yet the outcome is different.

    So simply put, when a spawner has spawned entities, the delay will reset to for example 25. After that, the CreatureSpawner.getDelay() will continuously return 25 until the spawner has spawned new entities. Only then will the method return a new Integer. This happens constantly.

    My current runnable:
    Code:
    package me.greenadine.advancedspawners.runnable;
    
    import me.greenadine.advancedspawners.AdvancedSpawners;
    import me.greenadine.advancedspawners.spawner.Spawner;
    
    public class SpawnerShowDelayScheduler implements Runnable {
    
        private AdvancedSpawners main;
       
        public SpawnerShowDelayScheduler(AdvancedSpawners as) {
            main = as;
        }
       
        @Override
        public void run() {
            for (Spawner spawner : main.getData().getSpawners().values()) {
                if (!spawner.isEnabled() || !spawner.getShowDelay()) {
                    if (spawner.getHologram().size() > 0) {
                        spawner.getHologram().clearLines();
                    }
                    continue;
                }
               
                if (spawner.getHologram().size() > 0) {
                    spawner.getHologram().clearLines();
                    spawner.getHologram().appendTextLine(String.valueOf(spawner.getDelayInSeconds()));
                } else {
                    spawner.getHologram().appendTextLine(String.valueOf(spawner.getDelayInSeconds()));
                }
            }
        }
    }
    
    My method Spawner.getDelayInSeconds() is simply using the Spawner's associated CreatureSpawner.getDelay() method and dividing the number by 20.
    Code:
    /**
    * Get the delay of the spawner in seconds.
    * @return int
    */
    public int getDelayInSeconds() {
        return spawner.getDelay() / 20;
    }
    The 'spawner' field above is the instance of a CreatureSpawner.
     
  2. Offline

    Kars

    You're sure getDelay returns the same value always? It isn't due to the hologram or something else not working?
     
  3. Offline

    Kevinzuman22

    Yes. I've tried printing the delay and it constantly prints the same number until a spawn has happened.
     
  4. Offline

    Kars

  5. Offline

    Kevinzuman22

    I indeed made sure I only called the method directly every time I needed it, without variables.
    I tested it with logging the spawner's delay directly like this:
    Code:
    getLogger().log(Level.INFO, String.valueOf(spawner.getDelay()));
    and this prints the same number several times until the spawner spawns new entities, and then continues to repeat that number.
    It has to be a bug, I have no idea anymore on what I could be doing wrong.
     
  6. Offline

    Kars

    @Kevinzuman22 Sounds like you know what you are doing. And it indeed sounds like a bug.

    No idea how this works with Bukkit but you could try reporting it.
     

Share This Page