Saving a Mob's Location

Discussion in 'Plugin Development' started by LordVakar, Dec 8, 2013.

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

    LordVakar

    So I'm coding this plugin where you type in a command and it spawns a villager. (Have that working)
    How would I save that villager so when you reload or stop and start the server, it will still be there?
     
  2. I'm pretty experienced with entities, buut im not at home and i dont have IDE now. I guess you could do:

    Entity e = Entity.VILLAGER;

    Spawn e and after that you can get it's location.
     
  3. Offline

    DCDJ

    Reloading the plugins is basically the same as stopping and starting your server - nothing you create dynamically is REALLY saved unless you store it somewhere external other than within the plugin itself - for example, a saves.yml file.

    You should look into the Configuration API Reference to see how you can store information in a yml file.

    An alternative is to store the location in a database (x,y,z) such as MySQL or MongoDB. This is a little more complex, however.
     
  4. Villagers stay alive once the server is stopped and restarted. Only hostile mobs (and maybe water mobs) are deleted upon reload. To spawn the mob do :

    world.spawnEntity(Location, EntityType.Villager);

    Now if your villager is getting removed on reload, save the villagers location to a txt file which is written onDisable(). Then in OnEnable write a txt file reader which then interprets your txt file's locations. If you need help with this ask.
     
Thread Status:
Not open for further replies.

Share This Page