Saving config string lists into a hashmap

Discussion in 'Plugin Development' started by MCCoding, Jun 2, 2014.

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

    MCCoding

    I'm trying to get a String list and add them into a HashMap when my server starts, but i'm not sure on how i can get all of the lists correctly. Here is what my config.yml looks like.

    Code:java
    1. Groups:
    2. GroupA:
    3. Members:
    4. - levi12| Leader
    5. - therock124| Recruit
    6. GroupB:
    7. Members:
    8. - MCCoding| Leader
    9.  


    I'm trying to get all of the members name and not include the "| Recruit" part is thats possable, if there is a better way let me know, then add their mc names as the key of the HashMap and the group name as the value, any help is much appreciated!
     
  2. MCCoding Split the String on the | with the split() method, ignore irrelevant part of array.
     
  3. Offline

    MCCoding

    AdamQpzm
    Ah okay i thought there was a method for that, do you know how I could get the string lists and add them into a HashMap?
     
  4. Offline

    MCCoding

    AdamQpzm
    Thanks for that it seems to have worked but the strings it's out putting are wrong and i can't seem to correct them. they are coming out like
    1. [levi12 | Leader, therock124 | Recruit]
    where they need to be all separate so, "levi12 | Leader" then "therock124 | Leader". They can't all be put together as one string they have to be a string each name.
     
  5. Offline

    MCCoding

    AdamQpzm
    Oh wow i forgot the most important part :p here you go

    Code:java
    1. for(String key : getGroupsConfig().getConfigurationSection("Groups.").getKeys(false)) {
    2. System.out.println(key);
    3.  
    4. System.out.println("Key = " + key + " Value = " + getGroupsConfig().getStringList("Groups." + key + ".Members"));
    5. }
     
  6. MCCoding getStringList() returns a List<String> - you can loop over these values to achieve the desired individual Strings.
     
    MCCoding likes this.
  7. Offline

    MCCoding

    AdamQpzm
    Ah yeah, thanks for that got it all to work!
     
    AdamQpzm likes this.
Thread Status:
Not open for further replies.

Share This Page