Solved Config not saving

Discussion in 'Plugin Development' started by sebcio98, Apr 13, 2016.

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

    sebcio98

    Hi. I don't know how to start, so I'll just provide some code (from the main class):
    Code:
    private static FileConfiguration getConfig;
    private static final TreeMap<Integer,TreeMap<Integer,Block>> mahConfigsInThaVariabel = new TreeMap<Integer,TreeMap<Integer,Block>>();
    
    public void onDisable()
    {
       (new File(getDataFolder(), "config.yml")).delete();
    
       System.out.println("## saving conf ##");
    
       for (Entry<Integer,TreeMap<Integer,Block>> list : mahConfigsInThaVariabel.entrySet())
       {
         System.out.println(list.getKey());
      
         for (Entry<Integer,Block> entry : list.getValue().entrySet())
         {
           getConfig.set("lists." + list.getKey().toString() + "." + entry.getKey().toString() + ".w", entry.getValue().getWorld().getName());
           getConfig.set("lists." + list.getKey().toString() + "." + entry.getKey().toString() + ".x", entry.getValue().getX());
           getConfig.set("lists." + list.getKey().toString() + "." + entry.getKey().toString() + ".y", entry.getValue().getY());
           getConfig.set("lists." + list.getKey().toString() + "." + entry.getKey().toString() + ".z", entry.getValue().getZ());
        
           System.out.println(list.getKey() + " " + entry.getKey());
         }
       }
    
       System.out.println("## done saving conf ##");
    
       saveConfig();
    }
    
    When I loop through the mahConfigsInThaVariabel (with the exact same iteration as in onDisable) while executing a command it works perfectly fine listing all of the contents of that map. But after I put some things in it and stop the server, an empty config is created with no trace of printing out anything interesting in the logs , just "## saving conf ##" and "## done saving conf ##" (and no errors).

    Help, please? I have no idea why it's not working.

    EDIT: The imports are all the most basic ones, I don't think they're necessary here.
     
  2. hmmm... probably .. uhh .. because you delete the config before saving to it?!?1111!1
     
  3. Offline

    sebcio98

    Hmm.. well.. maybe I delete the file, because I want to remove the old values, which are not removed by "getConfig.set"?!?1111!1 <- I can do that too, you know?
    And I delete it before setting any values and the actual saveConfig(), which should create the file if it doesn't exist...

    Just in case you intend to keep fighting with !'s and 1's I have removed that line and tested the code again. And.. well, as expected, now the config contains everything it did before the restart of the server. Who could've guessed.
     
  4. Offline

    ShowbizLocket61

    @sebcio98
    Did you update the getConfig variable?
     
  5. Then do saveDefaultConfig() after deleting it. and if you are deleting it on every restart why dont you just store the variables in the memory?

    config.set("key", null); to remove a value and ofcourse save the config after youre done
     
    Last edited: Apr 13, 2016
  6. Offline

    sebcio98

    saveDefaultConfig() copies the config.yml in your plugin.jar to the plugin folder's directory without replacing any existing values. And, as I said before, the file is created (if not existing already) by the methods I use after deleting the file.
    What do you mean by that? I am clearly storing all the config data in a variable and I can't use the memory when the server restarts (duh).

    Why should I update the variable? And when?



    EDIT: Okay, so I decided to use a kinda popular solution known as "screw this, I'll do it in Java". And so I did. Instead of using getConfig(), which I am not familiar with, I just called java.nio.file.Files.write(pathToConfig, theInsides). Works perfectly and everyone's happy. Me for solving the problem, you guys, for not having to argue with me anymore, and the config for not having any problems.

    "And it livd happy ever after"
    - "Shots Fiyerd", Noble - Lost Pause



    Thank you for participating in this Bukkit Forum activity. Good bye.
     
    Last edited: Apr 14, 2016
Thread Status:
Not open for further replies.

Share This Page