Automatically Restoring from a Backup

Discussion in 'Plugin Development' started by compdude5, Jul 25, 2012.

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

    compdude5

    I'm making a PvP arena plugin, and there are several ways the players can modify the map they play on. Obviously, I don't want the changes to stay there (and the changes are too numerous to keep track of and revert one at a time), so I want to unload the world, delete the world folder, copy the backup, and load the world. During the restoration, players are in the "lobby" world instead of the main one.

    Code:
    plugin.getServer().unloadWorld("world", false);
    /* Code that deletes "world", copies "world_backup" in its place.
    I've verified that this code works separately. */
    plugin.getServer().createWorld(new WorldCreator("world"));
    When this part of the code runs, the server complains like crazy that an external source is accessing the map and then it crashes. Am I not unloading the map fully? Is there a better way to accomplish this?
     
  2. Offline

    Scizzr

    Why not save the blocks that players break into a List and revert the changes? It's really not that much work to do this:

    Code:
    when a player breaks a block or lava or water flows in the PvP world:
        store the original data to a list
     
    every 15 seconds:
        save the changes to a file
     
    when the server stops or the event ends:
        save the changes to a file (some changes may have occurred since the last save)
     
    when the server re-loads:
        revert the changes by reading the List
        clear the list
    
     
  3. Offline

    Numenorean95

    I dont know for sure this works, but it should:

    Code:
    //Do this when loading when he server starts:
    this.getServer().getWorld("world").setAutoSave(false);
       
    //Do all other plugin stuff, when over
    //Move all players to lobby and do this, which unloads the
    //World without saving
    this.getServer().unloadWorld("world", false);
       
    //Then reload the world
    this.getServer().createWorld(new WorldCreator("world"));
    Since it never saves the data, on reload it should be the same as when it started. You might need to make sure that chunks stay in memory though, since if they dont save on unload any small changes would dissapear.

    Again, i havent tested it, but it might work
     
Thread Status:
Not open for further replies.

Share This Page