Need help with a config

Discussion in 'Plugin Development' started by willeb96, Nov 25, 2012.

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

    willeb96

    I have a config that looks like this:

    Code:
    quests:
      miner:
        1:
          item: IRON_PICKAXE
          amount: 5
          award: 75
          amount-randomness: 1
          award-randomness: 8
        2:
          item: DIAMOND_PICKAXE
          amount: 2
          award: 185
          amount-randomness: 0
          award-randomness: 10
      farmer:
        1:
          item: DIAMOND_HOE
          amount: 2
          award: 170
          amount-randomness: 1
          award-randomness: 10
        2:
          item: MELON_SEEDS
          amount: 192
          award: 40
          amount-randomness: 12
          award-randomness: 10
    
    How do I read all quests? (Like quests.miner.x, all of them)

    Should I use a loop and check if the number is there or are there better ways?

    Thanks :)
     
  2. Offline

    Tzeentchful

    This is what you want.

    Code:
    getConfig().getConfigurationSection("quests").getKeys(false);
     
    willeb96 likes this.
  3. Offline

    fireblast709

    Almost :p. This would get you miner:
    Code:java
    1. getConfig().getConfigurationSection("quests.miner").getKeys(false);

    and this
    Code:java
    1. ConfigurationSection quests = getConfig().getConfigurationSection("quests");
    2. for(String key : quests.getKeys(false))
    3. {
    4. ConfigurationSection quest = quests.getConfigurationSection(key);
    5. // Etc.
    6. }

    would get you all of them
     
    willeb96 likes this.
  4. Offline

    willeb96

    Thanks for all the help guys, really helpful :D
     
Thread Status:
Not open for further replies.

Share This Page