Copy world on Start; Delete world on Exit

Discussion in 'Plugin Development' started by CoderMusgrove, Mar 15, 2014.

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

    CoderMusgrove

    I am working on a minigame, and what I need is for the world to be reset. I have a schematic world file currently, which is the world that I want to copy over. "world" would be the name of the copied file, which I can do, except it generates the world with nothing in it.

    As well, I need the server to delete the world when it is shutting down, but that is throwing an exception when checking the session.lock file.

    Now time for the code...

    This is the code I am using to DELETE the world on server shutdown. The error received follows.
    Code:java
    1. @Override
    2. public void onDisable() {
    3. World w = Bukkit.getWorld(getConfig().getString("world-name"));
    4. Bukkit.unloadWorld(w.getName(), false); // I try to make sure the world is unloaded before deletion, but it doesn't seem to work.
    5. File worldFile = new File(w.getName());
    6. deleteWorld(worldFile);
    7. }
    8.  
    9. // I found a tutorial for how to do this thing.
    10. private boolean deleteWorld(File file) {
    11. if (file.exists()) {
    12. File files[] = file.listFiles();
    13. for (int i = 0; i < files.length; i++) {
    14. if (files[I].isDirectory()) {[/I]
    15. [I] deleteWorld(files[I]);[/I][/I]
    16. [I] } else {[/I]
    17. [I] files[I].delete();[/I][/I]
    18. [I] }[/I]
    19. [I] }[/I]
    20. [I] }[/I]
    21. [I] return (file.delete());[/I]
    22. [I]}[/I]
    23. [I]// Annoying -> [/I]

    The error:
    Code:
    [18:40:33 ERROR]: Exception stopping the server
    net.minecraft.server.v1_7_R1.ExceptionWorldConflict: Failed to check session loc
    k, aborting
            at net.minecraft.server.v1_7_R1.WorldNBTStorage.checkSession(WorldNBTSto
    rage.java:78) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.World.F(World.java:2542) ~[craftbukkit.j
    ar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.WorldServer.a(WorldServer.java:778) ~[cr
    aftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.WorldServer.save(WorldServer.java:762) ~
    [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.saveChunks(MinecraftServ
    er.java:359) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.stop(MinecraftServer.jav
    a:390) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :488) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-b3020jnks]
    Creation of the world, from copying.

    Now for what I am doing on the server startup is attempting to copy a world. As I said before, it generates it, but leaves a blank canvas.
    Code:
    Code:java
    1. private void generateWorld() {
    2. Bukkit.createWorld(new WorldCreator(getConfig().getString("world-schematic")));
    3. for (int i = 0; i < getServer().getWorlds().size(); i++) {
    4. System.out.println(getServer().getWorlds().get(i).getName());
    5. }
    6. World schematic = Bukkit.getWorld(getConfig().getString("world-schematic"));
    7. if (schematic == null) {
    8. getLogger().severe("NO WORLD TO COPY FROM! The plugin will still run, but the game WILL NOT start.");
    9. getLogger().severe("We don't want to destory that lovely world you worked so hard on. :)");
    10. return;
    11. }
    12. WorldCreator creator = new WorldCreator(getConfig().getString("world-name"));
    13. creator.copy(schematic);
    14. enabled = true;
    15. }


    basically, I need to know how to copy a world on startup AND delete a world on shutdown correctly.
     
Thread Status:
Not open for further replies.

Share This Page