Solved Help With Loading Worlds as Specified in a YAML file

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

Thread Status:
Not open for further replies.
  1. Hey everyone! So, I'm having trouble loading worlds based on the name that is specified in a file called "worlds.yml".

    When I try to load a world from the file, using a command like "/world load <world>", it creates a world titled "MemorySection[path='world', root='YamlConfiguration']", instead of loading the actual world that was specified in the file. This is the method I'm using:

    Code:java
    1. public static void loadWorld(String name){
    2. File worlds = new File(Main.getInstance().getDataFolder(), "worlds.yml");
    3. FileConfiguration c = YamlConfiguration.loadConfiguration(worlds);
    4.  
    5. Bukkit.getServer().createWorld(new WorldCreator(c.getString(name)));
    6. System.out.println("[WorldManager] Loaded world " + name);
    7. }


    Any ideas how I can fix this? Thanks :)
     
  2. Offline

    1Rogue

    Can you show your yaml file?
     
  3. 1Rogue
    Whoops forgot to put it in the main post

    Code:
    otherworld:
      weather: false
     
    #going to add more stuff later
     
  4. Offline

    1Rogue

    Looks like your path is "world". Which, depending if that's your full config or not, would either return a map in string form or you entered a non-existant path. Try printing the value of "name"
     
  5. 1Rogue
    Thanks. I realized how stupid my mistake was and fixed it. Had to change:

    Code:java
    1. Bukkit.getServer().createWorld(new WorldCreator(c.getString(name)));


    to

    Code:java
    1. Bukkit.getServer().createWorld(new WorldCreator(c.getConfigurationSection(name).toString()));


    While we're on this, any idea why this could be throwing an NPE?

    Code:java
    1. public static void playerTeleportWorld(Player player, String name){
    2. World world = Bukkit.getServer().getWorld(name);
    3.  
    4. player.teleport(world.getSpawnLocation());
    5. }
     
  6. Offline

    travja

  7. travja
    The problem is that the world exists and is loaded (using the above method, which now works)
     
  8. Offline

    travja

    The Gaming Grunts K, wait... so have you tested it since you fixed the loading code?
     
  9. travja
    Yes that's how I know
     
  10. Offline

    travja

    Do you know what exact line it is pointing to?
     
  11. travja
    Whoops I edited that and the comment I put in disappeared. Here:

    Code:java
    1. public static void playerTeleportWorld(Player player, String name){
    2. World world = Bukkit.getServer().getWorld(name);
    3.  
    4. player.teleport(world.getSpawnLocation()); //NPE
    5. }
     
  12. Offline

    travja

    So either, the player, world or spawn location are null, you can add debug messages to find out which one.
     
  13. travja
    Nvm I figured it out. Thanks for the help though :)
     
Thread Status:
Not open for further replies.

Share This Page