Loading a <string, Integer> HashMap data from a configurationsection.

Discussion in 'Plugin Development' started by MasterGlueXX, Mar 30, 2016.

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

    MasterGlueXX

    Code:
    public void loadPoints() {
            if(getConfig().getConfigurationSection("points") != null ) {
                Set<String> set = getConfig().getConfigurationSection("points").getKeys(false);
                for(String credit : set) {
                    int value = getConfig().getInt(credit);
                    points.put(credit, value);
                }
            }
        }
       
        public void loadPlayers() {
            if(getConfig().getConfigurationSection("players") != null ) {
                Set<String> set = getConfig().getConfigurationSection("players").getKeys(false);
                for(String credit : set) {
                    int value = getConfig().getInt(credit);
                    players.put(credit, value);
                }
            }
        }
       
        public void savePoints() {
            for(String point : points.keySet()) {
                int value = points.get(point);
                getConfig().set("points." + point, value);
            }
            saveConfig();
        }
       
        public void savePlayers() {
            for(String player : players.keySet()) {
                int value = players.get(player);
                getConfig().set("players." + player, value);
            }
            saveConfig();
        }
    So I can save the data successfully and I made sure of this by checking the config.yml, but when I go to load it, the key shows up just fine but the value remains at 0 even though the value in the config is still a different number. It's probably a problem in my loadPoints. Thanks in advance.
     
  2. Offline

    mcdorli

    Show us your config
     
  3. Offline

    MasterGlueXX

    Code:
    points:
      MasterGlueXX: 10
    players:
      HollowMasterGlueXX: 0
    
    When I do the command to show me the points and players it shows them as empty (MasterGlueXX = 0)(HollowMasterGlueXX = 0) even when there are points in the value.
     
  4. Offline

    TheDiamond06

    In your loadPoints, you grab the key from config. Your config does not have the key. You must specify where this key is coming from.

    instead of getConfig().getInt(credit); do getConfig().getInt("points." + credit);
    This will then look under the points section instead of finding "MasterGlueXX" outside of "points."
     
Thread Status:
Not open for further replies.

Share This Page