[Help]Get all the villagers and replace it

Discussion in 'Plugin Development' started by LordManegane, Jul 5, 2013.

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

    LordManegane

    Well, i have a plugin that plays with villagers and names.
    The renamed villagers do special things on right click.
    But on reload they are normal villagers.
    So i want a way to get all the villagers on the world and replace them with a new group or renamed villagers. So they do the interesting stuff again
     
  2. Offline

    Compressions

    LordManegane
    Code:
    for(Entity en : world.getEntities()) {
    if(en instanceof Villager) {
    //do something
    }
    }
     
  3. Offline

    Warreo

    LordManegane
    The reason that is happening is a reload is the equivalent of a server restart. (Almost) And Entities lose there metadata on restarts, just the way minecraft/Craftbukkit works. What you're gonna want to do is in you onDisable method get all the villagers on the map with Compressions code. With each villager your gonna want to save it someway. Maybe with strings that represent their Locations/Name/World. Then in your onEnable you will want to respawn in all those villagers with the data you saved :D
     
  4. Offline

    LordManegane

    Warreo Well i do it in other way because i have renamed villagers.
    So i get the custom name.
    Replace it and its all.
    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page