Saving/Loading HashMap

Discussion in 'Plugin Development' started by Jamscott, Dec 26, 2014.

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

    Jamscott

    I have a hash map which contains an UUID as the Key and a Enum Rank as the value how would I save and load this to a config?

    Code:
    public static HashMap<UUID, Rank> CurRank = new HashMap<UUID, Rank>();
     
  2. Offline

    SuperOriginal

    why is it static ._.

    Loop through all keys using Map#keySet(), with those keys get their respective values and then call the Configuration#set(path,value) method with path equal to the key and value equal to its respective value.

    Then save.

    For loading use the Configuration#getKeys(false) method in order to get all those keys again. While looping through those keys call the Configuration#getString(path) method with path equal to the key. Then you can put the key into the hashmap along with Enum#valueOf(value you retrieved).
     
Thread Status:
Not open for further replies.

Share This Page