Bukkit config is removing all entries

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

  1. Offline

    Shadow_tingBRO

    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. Online

    timtower Ninja on the waves Moderator

    @Shadow_tingBRO What text editor are you using for the configs?
    What code are you using?
     
  3. Offline

    Shadow_tingBRO

    @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. Online

    timtower Ninja on the waves 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. Offline

    Shadow_tingBRO

    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. Online

    timtower Ninja on the waves 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. Offline

    Shadow_tingBRO

    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. Online

    timtower Ninja on the waves Moderator

    1. Does config exist and have a value?
    2. Does survivalregions exist in the config?
     
  9. Offline

    Shadow_tingBRO

    Yes, but as I said earlier, the config resets annoying....
     
  10. Online

    timtower Ninja on the waves Moderator

    Then the value doesn't exist in the config.
    Did you look at the terminal already?
     
  11. Offline

    Shadow_tingBRO

    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. Online

    timtower Ninja on the waves Moderator

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

    Shadow_tingBRO

  14. Online

    timtower Ninja on the waves Moderator

  15. Offline

    Shadow_tingBRO

    Ok I am going to DM you as its private
     
  16. Online

    timtower Ninja on the waves Moderator

    Won't help through there.
     
  17. Offline

    Shadow_tingBRO

    I do not want to share my code, what do you need the WHOLE class for?
     
  18. Online

    timtower Ninja on the waves Moderator

    Initialization of variables.
    Chances are great that you did something wrong there.
    Doing things outside the constructor etc.
     
  19. Offline

    Shadow_tingBRO

    I'm not using a constructor, This class should be abstract as its ALL static. What variables?
     
  20. Online

    timtower Ninja on the waves 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.
     
  21. Offline

    Shadow_tingBRO

    @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
  22. Offline

    KarimAKL

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

    timtower Ninja on the waves Moderator

    Do you call save somewhere?
     
  24. Offline

    Shadow_tingBRO

    Yes I call it in the onDisable. I think I should add it to the onEnable as-well?
     
  25. Online

    timtower Ninja on the waves 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.
     
  26. Offline

    Shadow_tingBRO

    So what do I do?? I am still confused!
     
  27. Online

    timtower Ninja on the waves Moderator

    It all depends on your code.
    And till you are sharing that we can't do a lot.
     
  28. Offline

    Shadow_tingBRO

    Ok Im busy Right Now, Ill send the code later.
     

Share This Page