Custom Config

Discussion in 'Plugin Development' started by 97WaterPolo, Jan 10, 2015.

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

    97WaterPolo

    Hello!

    I am having an issue saving something to my config, not sure why it isn't working at all. It was working before but I changed a bunch of stuff and re-wrote it and now it doesn't save anything to the file. The file IS being created but nothing is being written in it.

    [​IMG]
    Code:
        public static void updateConfig(Player player){
            File file = new File(Particles.get().getDataFolder() + "/effects.yml");
            c = YamlConfiguration.loadConfiguration(file);
            List<String> active = new ArrayList<String>();
            for (ParticleType pt : Particles.get().active.get(player.getName()).getActiveParticles())
                active.add(pt.toString());
            Bukkit.broadcastMessage("LIST: " + active);
            c.set(player.getUniqueId().toString()+".effects", active);   
            try{
                c.save(file);
            }catch (IOException e){
                e.printStackTrace();
            }
        }
    So the picture is proof that the active list is NOT empty, and when I view the file, there is absolutely nothing in it.
     
  2. Offline

    1Rogue

    Always use braces on for-loops and if statements. Even if it's one line.Also, you should stop using public mutable fields in your classes (e.g. "active"), and use accessor methods.

    At any rate, what's calling updateConfig()?
     
  3. Offline

    97WaterPolo

    @1Rogue
    Every time an effect is created. A method in another class, is the one that's calling it.
     
  4. @97WaterPolo You are getting a new yaml every time. Instead check if it exists, if so do the sets. If it doesn't create then do the sets. Also you need to reload the yaml.
     
  5. Offline

    97WaterPolo

    @bwfcwalshy
    Well it creates it by default if it doesn't exist and it doesn't seem to generate a new one each time as I saved a test message within the YAML and its still their. I usually never reload the YAML, it worked pretty well until I redid it, I didn't reload it, but what do you mean entirely? If I get a new File Configuration won't that technically reload it?
     
  6. @97WaterPolo When you load it, it technically reloads it but you are loading before adding so you are reloading it, adding to it then saving it. You should reload after the save.
     
  7. Offline

    97WaterPolo

    @bwfcwalshy
    Okay, but why isn't saving the stringlist working?
     
Thread Status:
Not open for further replies.

Share This Page