Save/Load world in Jar

Discussion in 'Plugin Development' started by ChazSchmidt, May 30, 2014.

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


    I know this has been asked but in my searches I couldn't find what I'm looking for. If you have a think just shoot it at me.

    I want to load a world from the jar of my mini game plugin. I need to know what is the best way to store the world (zip the folder or what?) and load it up onEnable

    Sorry if there is an easy resource that explains this that I missed.
  2. Offline


    store it in gzip or something, but after first run of plugin you should copy and unzip it (eg: to your plugin folder)
  3. Offline


    Smerfa would I want it in the plugin folder? And that would be registered in the plugin how? WorldCreator?
  4. Offline


    eeem... you wrote that you want load world form your .jar file? so you want store it in plugin Yep?

    Or maybe you just want load world using own plugin?
    Then everything you have in Bukkit like Bukkit.loadWorld
  5. Offline


    Smerfa Please quit wasting both our time with your condescending comments and just move on from this thread.

    Anyone else want to actually be useful?
  6. Offline


    A JAR is just a zip file, technically, so you can store anything in it and it'll be on the classpath, so you could access it with the usual getClass().getResource() method. However, I would not do this with large files, especially large binary files.

    You should compress the file with an algorithm that focuses on saving space above all. LZMA is good for this: it's slow at compression, but pretty fast at decompressing and gets very good compression ratios.

    If you're using linux, tar can do lzma for you. If you're on windows, 7zip can probably do lzma, but I'm not sure- I don't use 7zip or windows.

    I guess you could also just use zip, but that's slow, bad, and boring.

    Anyway, just compress the world and distribute it with your plugin. Have your plugin decompress it, then copy it to the worlds folder, then do whatever you need to with it.
  7. Offline


    What you SHOULD do is store the world in a folder inside your plugin's base folder, then, if you have them compressed, copy to the server root, unzip, rename to world (this is all done in onLoad(), before the server decides to load the main world, "world", or otherwise stated int the file), so that way, the chosen world will be loaded when the server starts. It makes more sense to do this than to save the world to the plugin jar itself.

    in the onLoad() method, you would copy the zip to the server root, decompress it, rename the folder to the default level's name, commonly "world", and that would be it. Unless you want to have a lobby world, and the world loaded from the plugin, just don't rename it after decompressing it, then use WorldCreator to load the world, and onDisable(), just delete the world folder that's from the plugin.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jul 1, 2016
Thread Status:
Not open for further replies.

Share This Page