Bukkit config is removing all entries

Discussion in 'Plugin Development' started by Shadow_tingBRO, May 4, 2019.

Thread Status:
Not open for further replies.
  1. I have a config file and each time i put it on the server it only shows the text lines (#hi etc..) and no entries. Upon that, saving hashmaps to a config is not working, I can save but cannot load I keep getting null. Could anybody teach me how to properly save hashmaps to config cuz i watched videos and they dont help.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Shadow_tingBRO What text editor are you using for the configs?
    What code are you using?
     
  3. @timtower Sorry for the late reply, I am using YamlEditor (a red Y and white background) which I got from the eclipse marketplace. I have:

    Code:
    
    public static void saveConfig() {
    
    
    }
    
    
    public static void loadConfig() {
    
    
    }
    
    
    I have this in a Kit PvP class and I want to save the players uuid/name and the number of kills (the hashmap works in-game). I have tried looping through all keys in the map and putting in the config the key the its value. Saving works but loading does not it just returns null. I cannot remember the code as I deleted it. Any ideas?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Shadow_tingBRO Deleted code doesn't tell a lot.
    Write new code and try again.
    And try to stay away from static, you never need it with Bukkit
     
  5. Code:
    
    public static void saveConfig() {
    
    for(Player p : kills.keySet()) {
    
    config.set("kitpvp.kills." + p.getUniqueId(), kills.get(p).get(KillType.KILL));//hashmap<player, hashmap<killtype, int>>
    
    //killtype is either kilstreak or kill. (dont ask)
    
    }
    
    }
    
    
    public static void loadConfig() {
    
    for(String s : config.getConfigurationSection("kitpvp.kills").getKeys(true)) {
    
    Player p = Bukkit.getPlayer(UUID.fromString(s));
    
    if(p == null) continue;
    
    kills.put(p, new HashMap<KillType, Integer>());
    
    kills.get(p).put(KillType.KILL, config.getInt("kitpvp.kills." + p.getUniqueId()));
    
    }
    
    }
    
    Thats what I have, Im using static as I do not want to create instances, Kit PvP is ONE game not many.
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Shadow_tingBRO You can then still make 1 variable in your main class. Because this requires a lot of static variables, doubt it that you clean them. Bukkit doesn't do that for you.
    You never save the config visible.
    And why do you have getKeys(true)
    Then you get all values and sub-values. With false you only get the next values.
     
  7. Oh... I did not know that I will go try In a second!

    Still not working.... Null pointer on (im trying on another plugin using the same code):

    Code:
    
    for(String s : config.getConfigurationSection("survivalregions").getKeys(false)) {
    
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 6, 2019
  8. Offline

    timtower Administrator Administrator Moderator

    1. Does config exist and have a value?
    2. Does survivalregions exist in the config?
     
  9. Yes, but as I said earlier, the config resets annoying....
     
  10. Offline

    timtower Administrator Administrator Moderator

    Then the value doesn't exist in the config.
    Did you look at the terminal already?
     
  11. Yes I get a Null Pointer when saving, It says when I try to do config.set(blah) that it is null for some wierd reason
     
  12. Offline

    timtower Administrator Administrator Moderator

    Then post the full class and the full stack trace.
    Both using https://pastebin.com please
     
  13. Offline

    timtower Administrator Administrator Moderator

  14. Ok I am going to DM you as its private
     
  15. Offline

    timtower Administrator Administrator Moderator

    Won't help through there.
     
  16. I do not want to share my code, what do you need the WHOLE class for?
     
  17. Offline

    timtower Administrator Administrator Moderator

    Initialization of variables.
    Chances are great that you did something wrong there.
    Doing things outside the constructor etc.
     
  18. I'm not using a constructor, This class should be abstract as its ALL static. What variables?
     
  19. Offline

    timtower Administrator Administrator Moderator

    @Shadow_tingBRO The all static is far from needed.
    The all static is what is causing the issues.
    You are probably setting the config somewhere in a place where the class is loaded but not started.
     
  20. @timtower I have changed it all to a instance and stored it etc and accessed it from other class by getting it from the config etc... But it's stil not SAVING. The config is empty. None of the values are there. even values i set in the config in elipse editor and in the code it JUST says comments (#somethin)
     
    Last edited: May 7, 2019
  21. Offline

    KarimAKL

    @Shadow_tingBRO It's pretty hard to help you if you don't share any code.
     
  22. Offline

    timtower Administrator Administrator Moderator

    Do you call save somewhere?
     
  23. Yes I call it in the onDisable. I think I should add it to the onEnable as-well?
     
  24. Offline

    timtower Administrator Administrator Moderator

    Saving in the onEnable without changes doesn't do a lot.
    And it all depends on your code.
    Saving after a couple changes is not bad either.
     
  25. So what do I do?? I am still confused!
     
  26. Offline

    timtower Administrator Administrator Moderator

    It all depends on your code.
    And till you are sharing that we can't do a lot.
     
  27. Ok Im busy Right Now, Ill send the code later.
     
Thread Status:
Not open for further replies.

Share This Page