Solved Read yml file

Discussion in 'Spigot Plugin Development' started by _DuB_, Jun 27, 2016.

Thread Status:
Not open for further replies.
  1. So I was wondering how can read a yml file with java when the yml looks like this.

    Code (Text):
         anything: 'text'
         anything: 'text'
         anything: 'text'
    #Code keeps going and going.
    So how can I make the plugin read all configs after "Groups" key?
  2. Use getConfig().getString("Groups.Rank1.anything");

    The "." represents an inheritance.

    Sent from my iPhone using Tapatalk
  3. Yeah I know but I mean "Rank1" can be renamed to anything. and with unlimited groups.
  4. FileConfiguration#getConfigurationSection(String path)
    ConfigurationSection#getKeys(boolean deep)

    If you only want the groups, deep = false
    If you want keys under them, deep = true.
  5. So, just change the string...
    If you want something with rank1, rank2, etc, use a for loop:

    for(int i = 0; i< something; i++){
    getConfig().set("Groups.Rank" + i + ".anything");

    Sent from my iPhone using Tapatalk
  6. That's a bad way.
    Use getKeys(boolean) on the ConfigurationSection "Groups"
  7. So something like this should work?
    for (String s : getConfig().getConfigurationSection("Groups").getKeys(false)) {
  8. Correct. That will return Rank 1-3
  9. Alright! Thank you for incredible fast support!
    • Like Like x 1
    • Friendly Friendly x 1
  10. Correct.
    Correction: All ranks (and anything else) right under Groups.
    Code (YAML):
    : # This is seen by the code
    : '&6&lOwner &e' # Not seen by the code
    : # This is seen by the code
    : '&4&lAdmin &e' #Not seen
    : # This is seen by the code
    : # This is seen by the code
  11. And now you can do like to get a permission under a rank: getStringFromConfig("Groups." + key + ".Permission")

    and the key variable is your configsection etc.

    Thats only with getKeys(true) not getKeys(false)
  12. Mind adding on that? "Thats"?
    The rank or the prefixes?
  13. getKeys(false) will return rank 1-3 if you use configsection("Groups").
    with getKeys(true) it will return rank1-3 and under that so it will return also those prefixes of those ranks.
  14. Ah, you reversed your sentence, then, or I am simply too tired for English today.

    Could OP (@_DuB_) mark the thread as solved?
    • Agree Agree x 1
Thread Status:
Not open for further replies.