Bukkit Config, Values and Keys

Discussion in 'Plugin Development' started by Ezzy, Dec 11, 2011.

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

    Ezzy

    I'm probably making this all REALLY hard on myself, but this code is my baby.

    I'm trying to grab the key and value from a config that looks like this:

    Group:
    Crafter: 3
    Renovator: 4
    (Crafter and Renovator are tabbed in)

    I have been successful in grabbing the key with:

    Code:
            ArrayList GroupKeyL = new ArrayList();
            GroupKeyL.add(Conf.getConfigurationSection("Group").getKeys(true));
    However, I can't seem to use the results from that, to grab the value of the key. How can I do this?
    Thanks
     
  2. Offline

    ItsHarry

    Use a hashmap
     
  3. Code:java
    1. ConfigurationSection groupSection = Conf.getConfigurationSection("Group"); //saves the section we are in for re-use
    2. List<String> list = groupSection.getKeys(false); //grabs all keys in the section
    3. LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>(); //this is the map we will store the keys and values in
    4.  
    5. for (String key : list) { //iterate over all keys
    6. map.put(key, groupSection.getInt(key)); //save the values of the keys in our map, assuming that all values are integers
    7. }


    And what do you want to do now?
     
  4. Offline

    Ezzy

    I'm trying to develop my plugin modularly, so all the above code will be used to load the config back into the plugin.
    Thank you, I had been staring at this code blankly for about a day now. Just one last question:

    I was getting an error with line 2 of your code but Eclipse suggested I change the 'List<String>' to 'Set<String>', will this cause any issues I should know about?
     
  5. I wrote that code by heart, so it might be a set aswell, yeah.
    Just use a set instead.
     
Thread Status:
Not open for further replies.

Share This Page