Save a world to reload it later...

Discussion in 'Plugin Development' started by Matthiaantje, Sep 10, 2016.

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

    Matthiaantje

    Is there any resource wich will teach you how to save a world, and reload it later, like with SkyWars???
     
  2. Offline

    MordorKing78

    @Matthiaantje What do you mean by saving a world? Once you create a world it will be loaded as soon as the server starts.
     
  3. Offline

    Matthiaantje

    if a player executes a command, the world will be stored somewhere...
    Then, players can break blocks, build anything they want,
    at a certain moment, the saved world will OVERWRITE the curren world where players have build stuff
     
  4. Offline

    AlvinB

    @Matthiaantje
    Well, storing the entire world is a bit excessive isn't it, could you just not store a certain region, and then reload it back?
     
  5. Offline

    Matthiaantje

    But how?
    using a selection with WE and then reloading it... Tought of that, but I don't know how...
     
  6. Offline

    Zombie_Striker

    @Matthiaantje
    1. Create a config for each section you want to save. There should be one config for every area you want to save.
    2. Create three for loops. They will represent the X Y and Z of a block. This will loop through all the locations that you want to save.
    3. Every time it loops, save that block to the config above.
    4. When you want to reload the area, read the config load all the blocks.
     
  7. Offline

    timtower Moderator Moderator

    @Zombie_Striker Can be nasty when dealing with inventories if you didn't take those into account yet.
     
    Rayzr522 and Zombie_Striker like this.
  8. Offline

    Rayzr522

    @Zombie_Striker Not just that. You also have to account for Player heads and their data, banners, all inventory types, and I'm probably forgetting something else. It's quite difficult. There doesn't happen to be a Block.serialize method does there? :p
     
  9. Offline

    Zombie_Striker

    @Rayzr522 @timtower
    Blocks and blockstates should be serialize-able though. If you save the block/blockstate to a config, you should be able to load all the values for the block.
     
  10. Offline

    Rayzr522

    I checked the Javadocs, the don't appear to be serializable. Is there some method I'm missing?
     
  11. Offline

    Matthiaantje

    How does Skywars do it?
    Isn't that just the most easy way?
     
  12. Offline

    I Al Istannen

    @Rayzr522
    You can grab the NBT from the TileEntity, store it somehow (it is a binary format, so you can write it directly to a file or convert it to base64 or something) and then reload and reset it.

    This utility class(es) I made is capable of getting and setting the NBT as well as giving you an easy way to modify NBT tags by providing Wrappers with the same name and functionality as the nms classes (afaik :p).
    You need the NBTWrappers and the TileEntityNBTUtil. Then either grab my ReflectionUtil or change the calls to suit your own. First is easier.

    @Matthiaantje
    Probably differently. Maybe they store the map data and then load it? Like a schematic.
    And they don't have to care about inventories and such.
    For this you could use WorldEdit, check out their docs.
     
    Rayzr522 likes this.
  13. Offline

    Matthiaantje

    And how would I have to do it then!?
    I can't find anything in their docs wich tells me how to save a region to a schematic
     
  14. Offline

    Rayzr522

    That's a tad complicated, don't you think? Sounds like too much for me. Remember, I'm lazy ;)
     
  15. Offline

    I Al Istannen

    @Rayzr522
    It is probably too complicated :p
    The schematic is an easier way.

    Or you backup the region files from the worlds, if the plugin has access to that, which I don't know.
     
  16. Offline

    Matthiaantje

    But how to save a schematic file with code!?
     
  17. Offline

    I Al Istannen

  18. Offline

    Rayzr522

    Why wouldn't they have access to region files? new File(getDataFolder, "../../<world>/<wherever the regions are stored>");

    I think the question would be how to make sure they are up to date (saved)... Can you force a chunk to save with the Bukkit API?
     
  19. Offline

    Matthiaantje

    Could someone please make an example, I'm a wreck when it comes on the WE Api
     
  20. Offline

    I Al Istannen

    @Rayzr522
    Because Bukkit might install a security provider to prevent modification of files outside the plugin folder.

    And I don't know about the second thing.
     
Thread Status:
Not open for further replies.

Share This Page