Solved not writing to YAML Config?

Discussion in 'Spigot Plugin Development' started by Aspens, Apr 27, 2017.

  1. Ok so I have this code, but every time its ran the config stays with 0 bytes of data, but no exceptions are called.
    Code (Java):

            if (!(Main.q.contains(p.getUniqueId() + ".currency"))) { // Not sure if this is the correct if statement to use.
                p.sendMessage("Working | " + p.getUniqueId().toString()); // User gets this message
                Main.q.createSection(p.getUniqueId().toString());
                Main.q.set(p.getUniqueId().toString() + ".currency", 0);                        
            }
           
    - The UUID.toString() does not return null, tested and confirmed.
    - The file path is correct, tested and confirmed.

    Main.q :
    Code (Java):

    public static FileConfiguration q;

    ...

    File fl = new File(Bukkit.getServer().getPluginManager().getPlugin("Shen").getDataFolder(), File.separator + "Shen.yml");
            if (!(fl.exists())) {
                try {
                    fl.createNewFile(); // This works
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            q = YamlConfiguration.loadConfiguration(fl);
    Thanks in advance, not sure what im doing wrong here :\
     
    #1 Aspens, Apr 27, 2017
    Last edited: Apr 27, 2017
  2. You forgot to save the config when you wrote the data.
     
    • Agree Agree x 3
    • Like Like x 1
  3. To elaborate on previous answer. Configs are loaded to a Map in memory. You must explicitly call saveConfig() (or whatever save method you created if you made your own implementation) to write any changes to disk that you made with set().
     
    • Like Like x 1