Get world from file

Discussion in 'Plugin Development' started by MCCoding, Feb 10, 2015.

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

    MCCoding

    I'm wanting to know how I'm able to get a world from a external file through the path, I'm creating a mini-games plugin and I'm wanting to load up all the worlds for the specific game. The path I have for the worlds is

    C:\Users\Greg\Desktop\Server\Game Worlds\GAME NAME HERE\

    I have a method to get the world path where it will input the game name of the game I'm trying to start, but i'm waning to know on how I'm able to get all the worlds in the folder and load them all so I can save them in my object.
     
  2. Offline

    Skionz

  3. Offline

    MCCoding

    @Skionz
    I did look into that before posting but i thought it only listed file and no folders
     
  4. Offline

    Konato_K

    @MCCoding Everything is a File in java, whether the file is a Directory is not is something apart.
     
    MCCoding likes this.
  5. Offline

    MCCoding

    @Konato_K
    Awesome, Thanks for that info. One last thing how do I load the world from the file location.
     
  6. Offline

    Konato_K

    @MCCoding I believe you can't load a world in any directory you want, you need to copy your world to the world container (which in bukkit it's the server root directory), then use the WorldCreate class
     
  7. Offline

    MCCoding

    @Konato_K
    Ah okay that's annoying, how would that process work? so every world needs to be located where the default world is? So every world cycle I would need to copy the world to the root location then after that game is over delete it then copy and load the next map?
     
  8. Offline

    Konato_K

  9. Offline

    Skionz

    @MCCoding You could look into how Bukkit load the worlds. If you don't figure it out by tomorrow I will look into it for you.
     
  10. Offline

    MCCoding

    @Skionz
    I have tried looking into it all have not figured any other way to do it, maybe you could have a look if you're still up for it.
     
  11. Offline

    Skionz

    @MCCoding The Javadocs don't seem to be loading right now.
     
  12. Offline

    Konato_K

    @MCCoding Have you tried something with the WorldCreator class?
     
  13. Offline

    MCCoding

    @Konato_K
    Yes but it would still need to be in the root file from what I have tried. @Skionz I'm having the same issue as well.
     
  14. Offline

    MCCoding

    I have got the worlds copying down but the issue i'm having is that the worlds are not loading, all the files are there and I'm not getting any errors until I try do something with the work then it returns null here is my world copying/loading method

    Code:
        public static World loadWorld(String name) {
         
            File folder = new File("E:/Coding/server/Game Worlds/" + name);
    
            try {
                new File("E:/Coding/server/" + name).mkdir();
                FileUtils.copyDirectory(folder, new File("E:/Coding/server/" + name));
                World world = Bukkit.getServer().createWorld(new WorldCreator(name));
                System.out.println("Loading world " + name);
             
                return world;
            } catch (IOException ex) {
                Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex);
            }
            return null;
        }
     
  15. Offline

    nj2miami

    Curious, why are you deleting and moving the world?

    Why not load the world, set the auto save to false. When your mini game is over, simply unload and load it again. It will be back to its original state.
     
  16. Offline

    MCCoding

    @nj2miami
    Because there will be multiple servers running the same games so I don't want to have 20 worlds saved for every server that is running the game since it will use to much disk space, so copying then deleting is better since there is 1 set of worlds only rather than a set per server.
     
  17. Offline

    timtower Administrator Administrator Moderator

    @MCCoding You are talking about multiple servers, does that mean that it is for a bungeecord network?
     
  18. Offline

    MCCoding

    @timtower
    No, me and a friend are sharing a dedicated server and are wanting to share worlds. So I'm trying to code a command that allows us to load each others worlds up.
     
Thread Status:
Not open for further replies.

Share This Page