Loop Through Config

Discussion in 'Plugin Development' started by BrennyMullan, Nov 24, 2015.

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

    BrennyMullan

    I am trying to loop through a complicated config that has child elements within child elements.

    A normal config i am used to working with may look like

    Code:
    parent:
      child:
        x: 0
        y: 0
        z: 0
      child2:
        x: 0
        y: 0
        z: 0
    Where i can simply loop through them using
    Code:
    ConfigurationSection section = getConfig().getConfigurationSection("parent");
    for (String key : section.getValues(false).keySet()) {
    // get data based on the key
    }
    Howerver the config i am working with has child elements within child elements

    Code:
    maps:
      map1:
        map1_child1:
          x: 0
          y: 0
          z: 0
        map1_child2:
          x: 0
          y: 0
          z: 0
        map1_child2:
          x: 0
          y: 0
          z: 0
      map2:
        map2_child1:
          x: 0
          y: 0
          z: 0
        map2_child2:
          x: 0
          y: 0
          z: 0
        map2_child2:
          x: 0
          y: 0
          z: 0
    What i am trying to achieve is to select one of the main maps by random "map1" or "map2" in this case and then loop over all of its child elements "mapx_child1" "mapx_child2" and get there coord values.

    Keeping in mind that i can not simply use the name "mapx_child1" to call for it as these names could be anything, they are generated by a command in game

    I am a bit confused on how i would do this, any help would be appreciated.
     
  2. Offline

    Mrs. bwfctower

  3. Offline

    pie_flavor

    @Mrs. bwfctower That isn't all that helpful. It is pretty unreliable.
    @BrennyMullan
    Code:
    ConfigurationSection section = getConfig().getConfigurationSection("parent");
    for (String key : section.getKeys(false)) {
      ConfigurationSection section2 = section.getConfigurationSection(key);
      for (String key2 : section2.getKeys(false)) {
        /*code goes here*/section2.get(key2);
      }
    }
     
Thread Status:
Not open for further replies.

Share This Page