World Copying

Discussion in 'Spigot Plugin Development' started by DotRar, May 20, 2015.

  1. So, I created these classes for my new minigame:
    https://github.com/RWCraft/PlzFix
    But the thing is, it just generates a random minecraft world. Can anyone help?
     
  2. This doesn't give us any context at all. What are you trying to achieve, and what specifically is going wrong?
     
  3. I'm trying to copy a template world folder and then create a world from that, but a random minecraft world is generated.
     
  4. https://github.com/RWCraft/PlzFix/blob/master/FileHandler.java
    Your order of operations:
    - Plugin loads
    - Overwrite loaded world files
    - Disable autosave on a world that's already loaded
    - Create new world as the world is already loaded

    You don't seem to be unloading the world you're trying to replace.
     
    • Like Like x 1
  5. Is this better?

    Code (Text):
    private FileHandler() {}
        private static FileHandler instance = new FileHandler();
        public static FileHandler getInstance() {
            return instance;
        }
       
        public void setAutoSave() {
            Bukkit.getWorld("world").setAutoSave(false);
        }
       
        public void create() {
            WorldCreator wc = new WorldCreator("world");
            wc.createWorld();
        }
       
        public void boot(Plugin p) {
            Bukkit.unloadWorld("world", false);
            Bukkit.getWorlds().remove("world");
            File world = new File(Bukkit.getWorldContainer(), "world");
            try {
                FileUtils.deleteDirectory(world);
            } catch (IOException e) {
                e.printStackTrace();
            }
            File src = new File(Bukkit.getWorldContainer(), "backup");
            File dest = new File(Bukkit.getWorldContainer(), "world");
            try {
                FileUtils.copyDirectory(src, dest);
            } catch (IOException e) {
                e.printStackTrace();
            }
            setAutoSave();
            create();
        }
     
  6. Have you tested it? It looks like it could work.

    *could because I have no idea how Bukkit handles world loading, unloading, etc
     
    • Like Like x 1
  7. Yeah, I did, it works. Thanks!