deleting old world and creating new one

Discussion in 'Plugin Development' started by lrdemolition, Aug 26, 2014.

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

    lrdemolition

    i need to delete an old world or at least delete the files inside the world folder and then i need to generate new files or a new world file that is new and has completely different terrain.
    this happens after every game of my hg like game is done.
    i currently found this:
    Bukkit.getServer().unloadWorld("arena", (Boolean) null);
    Bukkit.getServer().unloadWorld("arena_nether", (Boolean) null);
    and then when a new game starts i do this:
    if(Bukkit.getWorld("arena") == null){
    Bukkit.getServer().createWorld(new WorldCreator("arena").environment(World.Environment.NORMAL));
    Bukkit.getServer().createWorld(new WorldCreator("arena_nether").environment(World.Environment.NETHER));

    oops. after i unload the world do i have to delete the file?

    help!!!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  2. Offline

    teej107

  3. Offline

    lrdemolition

    teej107
    so how can i do this.

    teej107
    is this the way?
    Code:
                    Bukkit.getServer().unloadWorld("arena", (Boolean) true);
                    Bukkit.getServer().unloadWorld("arena_nether", (Boolean) true);
                    Bukkit.getWorld("arena").getWorldFolder().delete();
                    Bukkit.getWorld("arena_nether").getWorldFolder().delete();
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  4. Offline

    teej107

    lrdemolition You need to delete all of the files/directories in each folder and sub-folder
     
  5. Offline

    fireblast709

    lrdemolition
    Code:
    function delete(file)
    {
        if file is directory
            foreach f in file // There is a method for getting all the files in a directory!
                delete(f) // Whooh! Recursion!
        delete(file)
    }
    This is basically what you do, but then written in pseudo :3
     
  6. Offline

    lrdemolition

    ohhh
    ive seen this before
    lemme go see if i can find it fireblast709 fireblast709 teej107

    if (f.isDirectory()) {
    for (File c : f.listFiles())
    delete(c);

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
  7. Offline

    fireblast709

    lrdemolition that is indeed the recursive part. Now add the last part, wrap it in a delete method, and you should be good to go.
     
  8. Offline

    teej107

    @lrdemolition Close but you get the idea. Assuming delete(file) is your method, you also need to check if the file is a file or a directory. If it is a directory, use recursion (make sure you delete the folder too). If not, then just delete the file. (Yes I did just say the exact same thing as in the other thread post) http://forums.bukkit.org/threads/delete-world-folder.263346/
     
Thread Status:
Not open for further replies.

Share This Page