Map rollback method, very simple!

Discussion in 'Resources' started by skipperguy12, Feb 28, 2013.

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

    skipperguy12

    Hey guys, so I noticed a lot of games not being able to rollback maps, and people struggling with it. I made a very simple method that can do this for you:
    Code:
        //Unloading maps, to rollback maps. Will delete all player builds until last server save
        public static void unloadMap(String mapname){
            if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(mapname), false)){
                plugin.getLogger().info("Successfully unloaded " + mapname);
            }else{
                plugin.getLogger().severe("COULD NOT UNLOAD " + mapname);
            }
        }
        //Loading maps (MUST BE CALLED AFTER UNLOAD MAPS TO FINISH THE ROLLBACK PROCESS)
        public static void loadMap(String mapname){
            Bukkit.getServer().createWorld(new WorldCreator(mapname));
        }
     
        //Maprollback method, because were too lazy to type 2 lines
        public static void rollback(String mapname){
            unloadMap(mapname);
            loadMap(mapname);
        }
    Things to keep in mind:
    - This will not roll back main worlds (the levelname defined in server.Properties).
    - Every player must be teleported OUT of the map before rollback.

    Add this somewhere, world.setAutoSave(false);
     
  2. Offline

    RealDope

    Is the false boolean in the unload method for saving changes?
     
  3. Offline

    skipperguy12

    This is to roll it back to the last save (/save-all)

    Soo, it basically unloads the world without saving, then you reload it.
     
  4. Offline

    MrTwiggy

    Are there any ways to intercept the save-all method that's called on command or when you stop the server to cancel it? Would be annoying if you were relying on this method and accidentally did 'stop' on your server before unloading and it saved.
     
  5. Offline

    skipperguy12

    In ondisable make it teleport all players to the main level, and call this method on the world you want to rollback and not auto save.
     
  6. Offline

    CarPet

    Thanks! Great help
     
    BlackVoidMike likes this.
  7. Offline

    skipperguy12

    CarPet
    No problem! Like the post if it helped you!

    :D
     
    BlackVoidMike likes this.
  8. Offline

    Barinade

    Does this just generate a new world or does it literally roll it back? For instance, if I make a castle, save it, then roll it back, will the castle be there?
     
  9. Offline

    skipperguy12

    Barinade

    If you save it, it will be there. This rolls back to the last save.
     
  10. Offline

    Barinade

    Doesn't it save automatically every x minutes?
     
  11. Offline

    skipperguy12

    Barinade

    Theres a command to turn it off, not sure if right but like /save-off?
     
  12. Offline

    Barinade

    Banjer_HD likes this.
  13. Offline

    skipperguy12

    Barinade
    Ok, that's AWESOME. I never knew that! I'll add this to OP.
     
  14. Offline

    hawkfalcon

    This is amazing.
     
  15. Offline

    skipperguy12

    hawkfalcon likes this.
  16. Offline

    hawkfalcon

    It seems to fail every 5-15th time, randomly.
     
  17. Offline

    skipperguy12

    hawkfalcon
    Not for me, I use this method in a server i'm coding. PM me the section of your code that handles map rollback.
     
  18. Offline

    koochi10

    it says could not unload the map can anyone help me figure out why
     
  19. Offline

    dark navi


    If you look here you can see the only circumstances a world will not unload.
     
    koochi10 likes this.
  20. Offline

    Go4Nightfire

    Is there a plugin out there that does this because I really dont know how to let this work without a plugin.
     
  21. Offline

    Wingzzz

    This is in the Plugin Development > Resources. This is a snippet of code for plugin developers to use in their own plugins.
     
  22. Offline

    FozZeW

    Thanks man, you saved my life
     
  23. Offline

    BajanAmerican

  24. Offline

    Wingzzz

    Pastebin/Pastie/Hastebin of the code?
     
  25. Offline

    CraftBang

    Wow seriously just amazing.
    BE SURE to use another world than the one in the properties file.(So I use multiverse and created a new world)
    Very nice man, thanks a lot! This will save A LOT OF LAGG!
     
  26. Offline

    theKevin

    Thanks for this great code! :cool:
     
  27. Offline

    ItsLeoFTW

    Does this totally clear the world? Or does it simply remove any changes? I want to have the world for my minigame rollback every time the game restarts. But I want the actual structures to stay.
     
  28. Offline

    shooterbret

    Thank you so much this will help out with the mini games server I'm attempting to make.
     
  29. Offline

    gentlemon

    For some reaon I got this error after reloading:


    Code:
    [23:48:07 WARN]: net.minecraft.server.v1_7_R1.ExceptionWorldConflict: Failed to check session lock, aborting
    [23:48:07 WARN]:        at net.minecraft.server.v1_7_R1.WorldNBTStorage.checkSession(WorldNBTStorage.java:78)
    [23:48:07 WARN]:        at net.minecraft.server.v1_7_R1.World.F(World.java:2700)
    [23:48:07 WARN]:        at net.minecraft.server.v1_7_R1.ChunkRegionLoader.a(ChunkRegionLoader.java:129)
    [23:48:07 WARN]:        at net.minecraft.server.v1_7_R1.ChunkProviderServer.saveChunk(ChunkProviderServer.java:222)
    [23:48:07 WARN]:        at net.minecraft.server.v1_7_R1.ChunkProviderServer.unloadChunks(ChunkProviderServer.java:315)
    [23:48:07 WARN]:        at net.minecraft.server.v1_7_R1.WorldServer.doTick(WorldServer.java:194)
    [23:48:07 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:659)
    [23:48:07 WARN]:        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:273)
    [23:48:07 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:562)
    [23:48:07 WARN]:        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:469)
    [23:48:07 WARN]:        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617)
    
    Does anyone have a clue why this is happening?
     
  30. Offline

    Justinian6

    I know I'm posting on a tab that has been dead for awhile now, but to awnser gentlemon's question...
    gentlemon There is an issue in your world where your NBT data is corrupt... try resetting your NBT data.
     
Thread Status:
Not open for further replies.

Share This Page