Solved Scanning through sections in a YML file

Discussion in 'Plugin Development' started by TopTobster5, May 25, 2014.

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

    TopTobster5

    Hi.

    In my plugin, I am storing arena data in a yml file. However, when I load it up, I need a way to loop through the arena information in order to turn them into an arena object. However, the only way I can think of doing it is via a for loop and using numbers as the name for my arenas, which I don't really want to do unless I have to. Any ideas.

    Here is how my yml file is laid out if it helps:
    Code:
    testarena1:
      world: world
      loc1:
        x: -233.0
        y: 72.0
        z: -38.0
      loc2:
        x: -239.0
        y: 66.0
        z: -43.0
    testarena2:
      world: world
      loc1:
        x: 3.0
        y: 74.0
        z: 58.0
      loc2:
        x: 74.0
        y: 66.0
        z: 43.0
    Thanks in advance for any help.
     
  2. Offline

    Mrawesomecookie

    TopTobster5
    Try using this (From the MemorySection class).
    Code:java
    1. public Set<String> getKeys(boolean deep) {
    2. Set result = new LinkedHashSet();
    3.  
    4. Configuration root = getRoot();
    5. if ((root != null) && (root.options().copyDefaults())) {
    6. ConfigurationSection defaults = getDefaultSection();
    7.  
    8. if (defaults != null) {
    9. result.addAll(defaults.getKeys(deep));
    10. }
    11. }
    12.  
    13. mapChildrenKeys(result, this, deep);
    14.  
    15. return result;
    16. }
     
    TopTobster5 likes this.
  3. Offline

    TopTobster5

    Mrawesomecookie I have done a bit of googling before you answered, and got this so far:
    Code:
            for (String key : getArenas().getConfigurationSection("Arenas").getKeys(false)) {
                Location loc1 = new Location(Bukkit.getWorld(getArenas().getString("Arenas." + key + ".world")), getArenas().getDouble("Arenas." + key + ".loc1.x"), getArenas().getDouble("Arenas." + key + ".loc1.y"), getArenas().getDouble("Arenas." + key + ".loc1.z"));
                Location loc2 = new Location(Bukkit.getWorld(getArenas().getString("Arenas." + key + ".world")), getArenas().getDouble("Arenas." + key + ".loc2.x"), getArenas().getDouble("Arenas." + key + ".loc2.y"), getArenas().getDouble("Arenas." + key + ".loc2.z"));
                Arena a = new Arena(key, loc1, loc2);
                arenalist.add(a);
            }
    However, I am getting a NullPointerException on the first line of this code. Any ideas?

    EDIT: Nevermind, a typo later on in the code was messing up the file. I found it, and now the problem is fixed.
     
Thread Status:
Not open for further replies.

Share This Page