Running through a config list help

Discussion in 'Plugin Development' started by np98765, Aug 26, 2012.

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

    np98765

    (I apologize for the terrible title. >.<)

    So, I think the best way to describe this is with an example. Let's say I'm making a class plugin (similar to MobArena classes, I guess):

    Code:
    warrior:
      enabled: true
      items:
        - 1
        - 2
        - 3
    barbarian:
      enabled: true
      items: 25
    
    Let's say I want the command '/class warrior' to give those items. How would I run through the list to check? This way, users can add an unlimited amount of their own 'classes' in the config, and the plugin would handle them accordingly.

    Thanks!
     
  2. Offline

    Sagacious_Zed Bukkit Docs

    If at compile time you do not know the set of keys for the root section, the only option is to ask the FileConfig object for the set of keys for the root section non recursively. Then with that set of keys you will able to retrieve the map for that key.
     
  3. Offline

    np98765

    Could you give an example please? :) I kind of understand what you're saying, but certainly not enough to be able to do it.

    Anyone can give an example (wasn't directing that exclusively) :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  4. Offline

    Chiller

    Code:
    //Gets each key such as: warrior or barbarian
    for (String ti : getConfig().getKeys(false))
    {
        //Gets the items as a list and iterates through them
        for (Object o : getConfig().getList(ti + ".items"))
        {
            //For your sake you can cast it to an Integer
            log.info("Key: " + (Integer) o);
        }
    }
    
     
  5. Offline

    np98765

    Awesome -- Thank you so much :)
     
  6. Offline

    Chiller

    Yup :)
     
Thread Status:
Not open for further replies.

Share This Page