Deleting World

Discussion in 'Plugin Development' started by phrstbrn, Nov 26, 2011.

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

    phrstbrn

    I'm trying to figure out how to unload, delete, and reset a world map.

    Code:
        public void run() {
            MyConfig myConfig = plugin.getMyConfig();
            String worldName = myConfig.getString(ConfigValue.WORLD_NAME);
            Server server = plugin.getServer();
            World world = server.getWorld(worldName);
            if (world == null)
                return;
    
            // delay reset
            if (world.getPlayers().size() > 0) {
                server.getScheduler().scheduleSyncDelayedTask(plugin, this, 20*60);
                return;
            }
    
            WorldCreator creator = new WorldCreator(worldName);
            creator = creator.copy(world);
    
            System.out.println("unloading world");
    
            // Reset world
            if(!server.unloadWorld(world, false))
                return;
    
            System.out.println("deleting world");
    
            File dir = new File(worldName);
            boolean status = FileControl.removeDir(dir);
    
            if (!status) // Something went wrong
                return;
            System.out.println("creating world");
    
            creator.createWorld();
        }
    When this code runs, it outputs to the command line just the first line, "unloading world" and never reaches "deleting world". Not sure what could be going wrong.
     
  2. Offline

    bleachisback

    The world unloading was unsuccessful it seems. Are you, by any chance, using an Async task?
     
  3. Offline

    phrstbrn

    Nope, it's a sync task. I understand that the unloading is unsuccessful, I just don't know what would cause it to fail.
     
  4. Offline

    Raphfrk

    According to the source code, world unload will fail if

    - world doesn't exist
    - dimension is not > 1 (presumably means you can't delete the default world or nether)
    - there are players in the world
    - world unload event is cancelled
     
  5. Offline

    phrstbrn

    Okay, that would make some sense, as I'm trying to delete a non-Bukkit generated world.
     
  6. Offline

    bergerkiller

    Not sure if it's related, but after unloading a world the 'RegionLoader' keeps the file locked. (it doesn't close the stream). In MyWorlds I implemented my own code to close these streams to make it possible to delete worlds after they were unloaded. MyWorlds' source code is on GitHub in the 'Worldmanager' class. Everything (from renaming to loading worlds) is in that class.
     
Thread Status:
Not open for further replies.

Share This Page