Saving worlds to new files?

Discussion in 'Plugin Development' started by Kakarot798, Feb 7, 2015.

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

    Kakarot798

    Hello, I'm trying to make a really neat plugin that will save all the loaded worlds on the server, and save them in a new file so they can be called for traveling to, but I'm not sure on how-to do it.
    Could I get some help here?
     
  2. Offline

    gal0511Dev

  3. Offline

    ProStriker123

    Last edited by a moderator: Feb 7, 2015
  4. Offline

    mrCookieSlime

  5. Offline

    Kakarot798

    Ok, woops. My bad, didn't quite know where to put it. Atleast it's in the correct spot now.
     
  6. Offline

    teej107

  7. Offline

    Kakarot798

    yah, I wanna be-able to get the list of the loaded worlds, and then copy their current data, make a new world folder for them, and store them.

    Like making a new world, but not with new data.
     
  8. Offline

    teej107

    @Kakarot798 You would have to unload the worlds, and copy every file from the folder and subfolders to a new folder.
     
    Konato_K likes this.
  9. Offline

    Kakarot798

    But how would I do this?
     
  10. Offline

    Skionz

    @Kakarot798 Read Bukkit's Javadocs and look into Java's file I/O API and you will know ;)
     
  11. Offline

    Kakarot798

    How?
     
  12. Offline

    Kakarot798

    I have no idea what I'm even looking at, or looking for when I looked at those. Can someone just tell me or give me an example of some sort so I can get this hard part out of the way? D:
     
  13. Offline

    teej107

  14. Offline

    Kakarot798

    I'm still absolutely confused.
     
  15. Offline

    nverdier

    @Kakarot798 If you don't know how to read JavaDocs, know what to look for in them, or even know what they are, then you certainly don't have enough Java knowledge to be doing this. Please learn Java before attempting to make a Bukkit plugin.
     
  16. Offline

    Totom3

    Guys cmon... -.-'

    @Kakarot798
    There are multiple ways of copying a File, and one of them is to use an InputStream and an OutputStream. You basically read from the original file and write to the copy. It's simpler for directories, as you only need to create a new one with the same name. It gets a more complicated when you have to consider sub-folders and their contents. In Java you can list all files and directories of a directory using File#listFiles(). Also keep in mind that this will not return sub-directories and their contents, so you'll have to fix that manually. Here's a pseudo-code of the average copy algorithm:

    Copy directory pseudo-code (open)
    PHP:
    void copy(File sourceDirFile destDir) {
        for-
    each file in sourceDir.listFiles()
             if 
    file.isDirectory()
                 
    // [ Insert code to create new directory ]
                 
    copy(file, new File(destDirfile))
             else
                 
    // [Insert code to create & copy new file ]
    }


    Hope it helped. If not, Google is your best friend. Try this, this, this, if you're still stuck after that, this one, this, or finally that one. :p
     
Thread Status:
Not open for further replies.

Share This Page