Solved Saving HashMaps to Config Issue

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

  1. Offline



    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):
    public HashMap<String, Integer> bounties = new HashMap<String, Integer>();
    Here are my methods to save & load in the onEnable and onDisable:

    public void onEnable() {
            for(String str : getConfig().getKeys(true)) {
                int p = getConfig().getInt(str);
                bounties.put(str, p);
    public void onDisable() {
            for(Entry<String, Integer> a1 : bounties.entrySet()) {
                getConfig().set(a1.getKey(), a1.getValue());
    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. Offline

    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


    @timtower Ah, you're completely right. Thanks a lot brother :)

Share This Page