#FileConfiguration Set

1 messages ยท Page 1 of 1 (latest)

sudden fiber
#

Hi ๐Ÿ‘‹ i'm creating my plugin and i can't find why FileConfiguration#Set doesn't work. I tried many variants with paths etc. but nothing.

public class EventsFile {

    private final Main plugin;
    private FileConfiguration customFile;
    private File file;
    String fileName = "events.yml";


    public EventsFile(Main plugin) {
        this.plugin = plugin;

        reloadFiles();
    }

    public void reloadFiles() {
        if (file == null)
            file = new File(this.plugin.getDataFolder().getPath(), fileName);

        customFile = YamlConfiguration.loadConfiguration(file);
        saveDefault();
        saveFiles();

    }

    public void saveFiles() {
        if (customFile == null) {
            return;
        }

        try {
            customFile.save(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void saveDefault() {
        if (file == null) {
            file = new File(this.plugin.getDataFolder().getPath(), fileName);
        }

        if (!file.exists()) {
            this.plugin.saveResource(fileName, true);
        }
    }

    public FileConfiguration get() {
        if (customFile == null)
            reloadFiles();

        return customFile;
    }
}```
This is my config class. I'm using get().set(path, value);

No error in console, nothing. It just didn't write anything.
echo valve
#

i think you need to save it

#

before it loads it to disk

digital leaf
#

you need to check if file.exists()

#
if (!file.exists()) {
  plugin.saveResource("file name", false);
}```
#

and then the YamlConfig.load bla bla bla

sudden fiber
#

Ok now it set the value but when i reload file, it deforms the file.
Original:

#

Deformed:

digital leaf
#

ah empty nodes are cleared

#

that's just the api

#

you could make a configuration api yourself but yea

sudden fiber
#

Is there something to somehow solve it? ๐Ÿ˜…

digital leaf
sudden fiber
digital leaf
#

Not really

sudden fiber
#

Ok, so can i reload the config withou using .save()?