Copying a world doesnt work

Discussion in 'Plugin Development' started by VNGC, Jul 6, 2020.

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

    VNGC

    hey, i want to make a ffa world. on /reset i want to delete the world, and copy over an existing world from by Backup Folder.

    i tried like this:

    Code:
    for (Player players : Bukkit.getOnlinePlayers()) {
                   players.kickPlayer("Welt wird zurückgesetzt...");
                    players.sendMessage("§7[§bFFA§7] §bDie Welt wird zurückgesetzt. Bitte warte einen Moment...");
                }
                Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() {
                    @Override
                    public void run() {
                        Bukkit.unloadWorld("world", true);
                    }
                }, 100L);
                Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() {
                    @Override
                    public void run() {
                        File from = new File("Backup/world/");
                        File to = new File("world/");
    
                        try {
                            FileUtils.deleteDirectory(new File("/world"));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        try {
                            FileUtils.forceMkdir(new File("/world"));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
    
                        try {
                            FileUtils.copyDirectory(from, to);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        Main.getPlugin().getServer().createWorld(new WorldCreator("world"));
                    }
                }, 200L);
    but its spamming this error into console:

    Code:
    [13:36:25 WARN]: net.minecraft.server.v1_8_R1.ExceptionWorldConflict: The save for world located at ./world is being accessed from another location, aborting
    [13:36:25 WARN]:        at net.minecraft.server.v1_8_R1.WorldNBTStorage.checkSession(WorldNBTStorage.java:72)
    [13:36:25 WARN]:        at net.minecraft.server.v1_8_R1.World.checkSession(World.java:2786)
    [13:36:25 WARN]:        at net.minecraft.server.v1_8_R1.WorldServer.a(WorldServer.java:934)
    [13:36:25 WARN]:        at net.minecraft.server.v1_8_R1.WorldServer.save(WorldServer.java:906)
    [13:36:25 WARN]:        at org.bukkit.craftbukkit.v1_8_R1.CraftWorld.save(CraftWorld.java:731)
    [13:36:25 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:659)
    [13:36:25 WARN]:        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537)
    [13:36:25 WARN]:        at java.lang.Thread.run(Thread.java:748)
    
     
  2. Offline

    timtower Administrator Administrator Moderator

    @VNGC Wait till the world is unloaded.
     
  3. Offline

    VNGC

    how long does this take usually? or can i check that? because i am already giving it 10 seconds to unload... should not take so much time i think
     
  4. Offline

    timtower Administrator Administrator Moderator

    @VNGC Just move the part from the second scheduler into the first one.
     
  5. Offline

    VNGC

    @timtower
    Still the same Error. Spamming about 20-30 times in the console. Im showing the full class:

    Code:
    package de.rivex.ffa.commands;
    
    import org.apache.commons.io.FileUtils;
    import org.bukkit.Bukkit;
    import org.bukkit.WorldCreator;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    import java.io.File;
    import java.io.IOException;
    
    @Deprecated
    public class FFAReset implements CommandExecutor {
    
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (sender instanceof Player) {
                if (args.length == 0) {
                    for (Player players : Bukkit.getOnlinePlayers()) {
                        players.kickPlayer("Welt wird zurückgesetzt...");
                        players.sendMessage("§7[§bFFA§7] §bDie Welt wird zurückgesetzt. Bitte warte einen Moment...");
                    }
                    Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() {
                        @Override
                        public void run() {
                            Bukkit.unloadWorld("world", true);
                            File from = new File("Backup/world/");
                            File to = new File("world/");
    
                            try {
                                FileUtils.deleteDirectory(new File("/world"));
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            try {
                                FileUtils.forceMkdir(new File("/world"));
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
    
                            try {
                                FileUtils.copyDirectory(from, to);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            Main.getPlugin().getServer().createWorld(new WorldCreator("world"));
                        }
                    }, 100L);
                }
            }
            return false;
        }
    }
    
     
    Last edited: Jul 7, 2020
  6. Offline

    timtower Administrator Administrator Moderator

    @VNGC Check the return value of the unload call.
     
  7. Offline

    VNGC

    alright ive got it working with this in my command-class:
    Code:
     if (sender instanceof Player) {
                if (args.length == 0) {
                    for (Player players : Bukkit.getOnlinePlayers()) {
                        players.kickPlayer("Welt wird zurückgesetzt...");
                        players.sendMessage("§7[§bFFA§7] §bDie Welt wird zurückgesetzt. Bitte warte einen Moment...");
                    }
                    Bukkit.getScheduler().runTaskLater(Main.getPlugin(), new Runnable() {
                        @Override
                        public void run() {
                            Bukkit.unloadWorld("world", true);
                            Main.getPlugin().getConfig().set("reset", true);
                            Bukkit.shutdown();
                        }
                    }, 100L);
                }
            }
    and this in my onEnable:

    Code:
     File from = new File("Backup/world/");
            File to = new File("world/");
    
            try {
                FileUtils.deleteDirectory(new File("/world"));
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                FileUtils.forceMkdir(new File("/world"));
            } catch (IOException e) {
                e.printStackTrace();
            }
    
            try {
                FileUtils.copyDirectory(from, to);
            } catch (IOException e) {
                e.printStackTrace();
            }
            getConfig().set("reset", false);

    Edit: @timtower nevermind, it only resets a few chunks, the rest doesnt get resetted. why?
     
    Last edited: Jul 7, 2020
Thread Status:
Not open for further replies.

Share This Page