Save/Load Hashmaps

Discussion in 'Plugin Development' started by x128, Sep 11, 2013.

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

    x128

    Hi,
    I've been searching for a few days to try to figure this out. I have not been able to and thought some of you guys would be able to help me out.

    I have a HashMap called "ChannelData" with the format String, String. I put player names in this hashmap, and set the value to what chat channel they enter. Everything works perfectly until it comes to a server reload/restart. How would I go about doing this? I couldn't care less if it is saved to the config.yml or another data.yml file.

    Thanks!
     
  2. Offline

    tommycake50

    How big will it be? rough estimate?
     
  3. Offline

    Chinwe

    You should be able to simply add it to the config with getConfig().set("path.to.map", yourMap), and get it with something like getConfig().getMapList(path)
     
  4. Offline

    dillyg10

    2 ways to do it:

    1: ConfigurationSerialization, google it.

    2:

    List<HashMap<?,?>> tempMaps = new ArrayList<HashMap<?,?>>();
    tempMaps.add(yourmap);
    getConfig().set("mapdata",yourmap);

    then to load...

    try {
    yourmap = getConfig().getMapList("mapdata").get(0);
    } catch (Exception someException){
    yourmap = new HashMap<?,?>();
    }

    Note that ?, ? equals what your data in your hashmap is. (HashMap<String,ItemStack>) etc.
     
Thread Status:
Not open for further replies.

Share This Page