How to detect mob's despawn?

Discussion in 'Spigot Plugin Development' started by PvPNiK, Apr 16, 2018.

  1. Hello,
    i have a spawning system,
    the admin creates new spawner sets it's max number of mobs and the locations.
    when a mob dies i'm removing him from the spawner, and so there is free space for another mob to spawn.

    the problem is when the mobs are despawning it do not removes them from the spawner, so the plugin thinks it is full..
    so in real, there are no mobs but the plugins there is.

    any suggestions?
     
  2. listen ChunkUnloadEvent may be :unsure:
     
  3. maby add a boolean, isLoaded to the spawner, and dont spawn mobs if the chunk isn't loaded, and remove all the mobs there were
     
    • Like Like x 1
  4. You could add metadata to the to the entities your spawner spawns (to associate the entity with the spawner) and as suggested use ChunkUnloadEvent and check if any entities belong to the spawner and if so remove them (this does require you to keep the object you use to represent your spawner loaded (i.e. in memory rather then just in your config file) even though the chunk which contains your spawner is unloaded, this is why you typically check for entities within range of a spawner as it's simpler).
     

Share This Page