Config Duplicating itself

Discussion in 'Plugin Development' started by rocket138, Dec 29, 2013.

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

    rocket138

    So, I am trying (still) to make a points system on my server, but I'm having a minor error that will become a big error.

    When I restart or reload the server, the list of players and their points doesn't reset, it just gets added on to. So say that 2 people got on, then I restarted, they got back on, then I restart again, it would look like this:

    - *dude1*:2
    - *dude2*:3
    This is where I restart
    - *dude1*:3
    - *dude2*:3

    The scores are just random and such, but basically it doesn't clear the file when it saves the data, it just adds on.

    Code:java
    1. public void onEnable(){
    2. saveDefaultConfig();
    3. scores.clear();
    4. List<String> s = getConfig().getStringList("scores");
    5.  
    6. for(String str : s){
    7. String[] words = str.split(":");
    8. scores.remove(Bukkit.getOfflinePlayer(words[0]));
    9. scores.put(Bukkit.getOfflinePlayer(words[0]), Integer.parseInt(words[1]));
    10.  
    11. }
    12.  
    13.  
    14.  
    15. }
    16.  
    17. public void onDisable(){
    18.  
    19. List<String> s = getConfig().getStringList("scores");
    20.  
    21. for(OfflinePlayer p : scores.keySet()){
    22. s.add(p.getName() + ":" + scores.get(p));
    23. }
    24.  
    25. getConfig().set("scores", null);
    26.  
    27. getConfig().set("scores", s);
    28. saveConfig();
    29. }


    The "Scores" HashMap is an <OfflinePlayer, Integer> HashMap (I am aware that OfflinePlayer is more memory intensive)

    Anybody know what I'm missing?
     
  2. Offline

    xTrollxDudex

    rocket138
    Try saving the file after setting the list to null onDisable
     
  3. Offline

    rocket138

    Didn't work
     
Thread Status:
Not open for further replies.

Share This Page