Tracking Mob De-Spawning

Discussion in 'Plugin Development' started by Scullyking, Jun 28, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Scullyking

    So in my plugin I have mob regions.
    A region has a constant number of spawned mobs (such as 4 zombies), which are tracked by a hashmap.

    The problem:
    Mobs de-spawn when there are no players within 128 blocks of them.
    I need to remove mobs from the tracking hashmap when they despawn.

    How can I do this?

    Before you suggest ChunkUnloadEvent - this doesn't work because mobs usually despawn BEFORE the chunk they're in unloads.
     
  2. Offline

    Zombie_Striker

    @Scullyking
    Add some form of "checking" event, that will loop through all the entities in the map. For each entitiy, try to look in that world to see if an entity with the same UUID as the one in the map. If there is no matching UUID, remove them from the map.
     
    Scullyking likes this.
  3. Offline

    Scullyking

    @Zombie_Striker
    Ah I can't believe I didn't see that. This has been puzzling me for a while, thanks!
     
Thread Status:
Not open for further replies.

Share This Page