Solved Saving HashMaps to Config Issue

Discussion in 'Plugin Development' started by Zqckk, Jan 3, 2019.

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

    Zqckk

    Hey!

    I'm currently developing a Bounty plugin for my friend's server, just for fun. Usually, the method I'm using will work. After working on this one bug for the past couple hours, I just really can't figure it out.

    Here's the HashMap I've got (the string is the player's name, the int is the bounty ammount):
    Code:
    public HashMap<String, Integer> bounties = new HashMap<String, Integer>();
    Here are my methods to save & load in the onEnable and onDisable:

    Code:
    public void onEnable() {
          
            for(String str : getConfig().getKeys(true)) {
                int p = getConfig().getInt(str);
                bounties.put(str, p);
            }
    Code:
    public void onDisable() {
          
            for(Entry<String, Integer> a1 : bounties.entrySet()) {
                getConfig().set(a1.getKey(), a1.getValue());
            }
          
            saveConfig();
          
        }
    After a bounty has been claimed and it > HAS been removed from the HashMap, < it will still show up in the config & load into the HashMap after a reload or restart. I'm not sure if there's any helpful information I've missed, please let me know. Thanks.
     
  2. Online

    timtower Ninja on the waves Moderator

    @Zqckk That is because the bounty that is removed from the hashmap still exists in the config itself.
    You need to clear the config before you save.
     
  3. Offline

    Zqckk

    @timtower Ah, you're completely right. Thanks a lot brother :)
     
Thread Status:
Not open for further replies.

Share This Page