How to save and load a hashmap to config with key player?

Discussion in 'Spigot Plugin Help' started by Bluehawk409, Sep 11, 2020.

  1. I have seen many examples of saving hashmaps and have tried to replicate them, but I can't seem to figure out how to have a hashmap with the key: Player and the value: Integer. How would I save this hashmap and load it from the config file?

    Hashmap:
    Code (Text):
    public static Map<Player, Integer> soulsmap = new HashMap<>();
     
  2. This is the wrong section to ask help for this kind of matters, Please use `Spigot Plugin Development` for this type of problems next time, anyways

    I suggest using UUID instead of Player

    You can loop through all the values in the Map using entrySet()
    Example:
    Code (Java):
    for (Map.Entry<UUID, Integer> entry: map.entrySet()) {
             // Your code here
    }
    Don't forget to save your config after inserting the values inside the config.

    To read all the information that you saved in the config, we simple use Configuration#getConfigurationSection(String path)
    Example:
    Code (Java):
    for (String uuid: getConfig().getConfigurationSection("path").getKeys(false)) {
             // Your code here
    }
    Hope this helps
     
    #2 Invvk, Sep 11, 2020
    Last edited: Sep 11, 2020