Solved Saving/loading multiple values for a player with the config

Discussion in 'Plugin Development' started by ocomobock, Jul 9, 2013.

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

    ocomobock

    So basically, I'm trying to have it so when a player does this:

    /buykit ghoul

    it adds to this HashMap:

    HashMap<String, ArrayList<String>> playerKits = new HashMap<String, ArrayList<String>>();

    So that hashmap should store the player's name as the key, and a list of their kits. When a player runs '/buykit ghoul', it does this:

    Code:java
    1. public void addKit(String name, Kit kit)
    2. {
    3. if (playerKits.get(name)==null)
    4. {
    5. playerKits.put(name, new ArrayList<String>());
    6. }
    7. playerKits.get(name).add(Kit.toString(kit));
    8. }


    That adds to the list of their kits. I know this works because I have a command to view your kit list.

    I just need to figure out how to save an ArrayList to the config. I've tried everything and have already removed all the config stuff in my code so I don't feel like giving an example, but could anyone tell me how to do this?

    I would like for the config.yml to look like this:

    Code:yaml
    1.  
    2. playerkits:
    3. ocomobock:
    4. - GHOUL
    5. - POSEIDON
    6. - MINER
    7. otherusername:
    8. - JUMPER
    9. - THOR
    10.  


    And then when the server is enabled, it gets all the player names from there and packs the values into the HashMap again.

    Bump.

    Also, TL;DR:

    I want to be able to save a list to the config, and use the list in the config when onEnable is called.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  2. Offline

    SnipsRevival

    To set a list, do getConfig().set("playerkits." + playername, list).

    To get each element in the list, do
    Code:
    for(String kit : getConfig().getStringList("playerkits." + playername)) {
    //do whatever you want with each kit
    }
     
  3. Offline

    ocomobock

    Thank you very much, I got it figured out.
     
Thread Status:
Not open for further replies.

Share This Page