Deleting World

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

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


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

        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)
            // delay reset
            if (world.getPlayers().size() > 0) {
                server.getScheduler().scheduleSyncDelayedTask(plugin, this, 20*60);
            WorldCreator creator = new WorldCreator(worldName);
            creator = creator.copy(world);
            System.out.println("unloading world");
            // Reset world
            if(!server.unloadWorld(world, false))
            System.out.println("deleting world");
            File dir = new File(worldName);
            boolean status = FileControl.removeDir(dir);
            if (!status) // Something went wrong
            System.out.println("creating world");
    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


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


    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


    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


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


    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