Solved Loading All Worlds As Specified in a File

Discussion in 'Plugin Development' started by The Gaming Grunts, Feb 8, 2014.

Thread Status:
Not open for further replies.
  1. Hey everyone! So, I'm making a world manager plugin similar to multiverse and in it I need to load all "imported" worlds on startup. The worlds and their info are stored in a worlds.yml file, which looks like this:

    Code:
    world1:
      //attributes here
    world2:
      //attributes here
     
    //etc.

    However I'm having a little problem creating a method to do so. Here's what I have so far:

    Code:java
    1. public static void loadWorlds(){
    2. File worlds = new File(Main.getInstance().getDataFolder(), "worlds.yml");
    3. FileConfiguration c = YamlConfiguration.loadConfiguration(worlds);
    4.  
    5. for (String str : c.getKeys(false)){
    6. for (int x = 0; x < str.length(); x++){
    7. Bukkit.getServer().createWorld(new WorldCreator(str[x]));
    8. }
    9. }
    10. }


    First of all, I don't even know if that will work because I'm getting an error at str[x] on line 7 saying "The type of the expression must be an array type but it resolved to String" and I don't know how to fix it. If anyone knows how to fix that I'd really appreciate it :)

    Also, as I mentioned, I don't even know if that will work. However, if someone does know how to do such a thing, I'd really appreciate it if you can at least point me in the right direction. Thanks :)

    Note:
    Before anyone says how this can be bad with resources, I created a manager to reduce the impact of such things, so there's nothing to worry about :)
     
  2. Offline

    xTigerRebornx

    The Gaming Grunts Well, the error you get is because you are trying to treat String str as an array (str), you don't need the 2nd for loop, only the first one, and just use str for the WorldCreator
     
  3. xTigerRebornx
    Wow I can't believe that that's all there is to it. I spent the longest time trying to figure this out lol. Thanks for the help :)
     
Thread Status:
Not open for further replies.

Share This Page