Solved Looping in config

Discussion in 'Plugin Development' started by guitargun, Mar 19, 2015.

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

    guitargun

    I know this would have been a 1000 times but I can't figure it out.
    I need to loop through the config I created
    this is a sample how it could look like:
    Code:
    '0':
      name: test
      itemin:
        '0':
          ==: org.bukkit.inventory.ItemStack
          type: STONE
        '1':
          ==: org.bukkit.inventory.ItemStack
          type: WOOD
        '2':
          ==: org.bukkit.inventory.ItemStack
          type: DIRT
        '3':
          ==: org.bukkit.inventory.ItemStack
          type: BEDROCK
        '4':
          ==: org.bukkit.inventory.ItemStack
          type: COBBLESTONE
      itemout:
        '0':
          ==: org.bukkit.inventory.ItemStack
          type: COBBLESTONE
        '1':
          ==: org.bukkit.inventory.ItemStack
          type: SAPLING
        '2':
          ==: org.bukkit.inventory.ItemStack
          type: SAPLING
        '3':
          ==: org.bukkit.inventory.ItemStack
          type: BEDROCK
        '4':
          ==: org.bukkit.inventory.ItemStack
          type: WOOD
    
    this is what I tried:
    Code:
           
            for(String keys : config.getKeys(false)){
               
                Map<String, ItemStack> mapin = (Map<String, ItemStack>) config.getMapList(keys + ".itemin");
                Map<String, ItemStack> mapout = (Map<String, ItemStack>) config.getMapList(keys + ".itemout");
                int size = mapin.size() + mapout.size();
                ItemStack[] items = new ItemStack[size];
                int i = 0;
                for(String key : mapin.keySet()){
                    items[i] = mapin.get(key);
                    items[i+1] = mapout.get(key);
                    i+=2;
                }
    Yet I don't know how to access the 2nd list that goes from 0 - 4. please keep in mind that the end number can be much more of less.
     
  2. Code:
    for(String s : config.getConfigurationSection("section.section").getKeys(false)){
    
    //Do stuff
    
    }
    Is that what you are looking for?
     
  3. Offline

    guitargun

Thread Status:
Not open for further replies.

Share This Page