Solved Having problems deleting a created world

Discussion in 'Plugin Development' started by Ak1ra, Sep 30, 2023.

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


    I create a world using these 2 lines:

    WorldCreator wc = new WorldCreator("minigame");
    World game = wc.createWorld();
    I send players into that world and I want the world to be deleted after so I tried this (for loop cuz before I used a while "minigame" isnt null loop and froze my server lmao)

        public static void GameCancel(){
    //----------getting players out of there --------------------
            gamePlayers[0] = null;
            gamePlayers[1] = null;
    //----------getting players out of there --------------------
            Bukkit.unloadWorld(Bukkit.getWorld("minigame"), false); // unloading the world
            new BukkitRunnable(){
                public void run() {
                    if (Bukkit.getWorld("minigame") == null) return;
                    File folder = Bukkit.getWorld("minigame").getWorldFolder(); //storing the minigame world folder
                    for (int i = 0; i < 50; i++) {
                        folder.delete(); // deleting the folder (never works so I try 50 times for good measure :D )
                        if (Bukkit.getWorld("minigame") == null) return;
    I was never successful in deleting the world, anybody knows a better way? Ive looked over at world creator plugins but never understood the code well enough to implement it
  2. Offline


    This is how I do it. Please know I'm only giving you this code to show you the proper way to unload a world, not because I want to give you the answer. Also please note that, from my understanding, you cannot unload/delete the level world (this is the default world generated on enable).

    // teleport players out of world to be unloaded
    for(Player player : minigamePlayers) {
       player.teleport(loc); // put in appropriate loc
    // unload world
    boolean shouldBeSaved = false; // this means the world will not be saved
    Bukkit.getServer().unloadWorld(worldName, shouldBeSaved);
    // remove from world list
    // delete world folder. The FileUtils package is fantastic and I recommend
    Also, why are you running that task Asynch? There's no need to do that.
    Ak1ra likes this.
Thread Status:
Not open for further replies.

Share This Page