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.
Nope, it's a sync task. I understand that the unloading is unsuccessful, I just don't know what would cause it to fail.
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
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.