How to make a working configuration mechanism? [solved]

All I want to do is create a config file under serverroot/config/Spongy/spongy.conf but I can’t seem to get any of the tutorials on this site to work. Is there somewhere I could find some basic examples of just something that creates the config file? I know how to edit the config file (.getNode(“bleh”)…), so I don’t need that.

@Inject @ConfigDir(sharedRoot = false) File configDir;

public boolean createConfigFile(String fileName) throws IOException { //Assume 'fileName' is spongy.conf
    File config = new File(this.configDir, fileName);

    if (config.exists) {
        return true;
    }

    return config.createNewFile();
}

You can, of course, get the config file directly, and use the above method like this:

if (this.configFile.exists() {
    return true;
}

return this.configFile.createNewFile();

However, as you can only grab the config file as a File object, anyways, and you later have to convert it to the configuration parameters, I prefer to just get the directory, and then name my own configuration files.

If you wan to create a config file with a custom name, look at my example plugin: SimpleMail/SimpleMailPlugin.java at master · boformer/SimpleMail · GitHub

1 Like