Solved .size of a config file

Discussion in 'Plugin Development' started by Deleted user, Dec 11, 2013.

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

    Deleted user

    If you have a config file that looks like this:
    Code:
    '0':
      hi: hello
      hello: hi
    '1':
      no: yes
      yes: no
    How can you check the size of the main sections (0 and 1) and then how do you iterate through them?
     
  2. Offline

    zeeveener

    Try getConfig().getConfigurationSection("0").getKeys(true).size()
     
  3. Offline

    1Rogue

    Or just use an enhanced loop:

    Code:java
    1. for (String s : getConfig().getConfigurationSection("0").getKeys(false)) {
    2. //will give "hi" and "hello"
    3. }
     
  4. Offline

    Deleted user

    1Rogue zeeveener
    Its more complex, and I want to loop through ever value in the config
    Aka get all values from '0' and '1'
    And they aren't all strings
     
  5. Offline

    zeeveener

    JHG0

    The getConfiguration("").getKeys().size() gives you how many elements are in the section. Every element NAME is a string or represented as a string. You use that name to get to the actual value you want.

    To go through every element you use the method 1Rogue gave you.
     
  6. Offline

    Deleted user

  7. Offline

    zeeveener

  8. Offline

    1Rogue


    Code:java
    1. for (String s : getConfig().getKeys(false)) {
    2. // returns "0", "1", etc
    3. }


    It's pretty straightforward, and if each number has a similar structure then it does work.
     
  9. Offline

    Deleted user

  10. Offline

    zeeveener

    JHG0

    What are you referring to by custom config?
    What I said works. I use it in my own plugins so I can assure you I know how to do it for the Bukkit FileConfiguration.
     
  11. Offline

    Deleted user

Thread Status:
Not open for further replies.

Share This Page