Help Me Understand Configuration

I started working with the configuration stuff with the API release 1.0, and it kinda made sense, but wasn’t quite clicking. I noticed that 1.1-Snapshot (I’m talking Maven builds in case anyone is confused about these names) got rid of some of the old configuration stuff, and now I am completely lost and have resorted to making my own config system with a plain text file and text parser. But before I go head first into the DIY sector of plugins (we all know from Bukkit that things can go south on this path real quick) I wanted to reach out and see if anyone who actually has a clue about the config stuff could help explain it?

Footnote: Yes, I read the docs on the interfaces, and to be honest, they only confused me more.

I have to say that I don’t like the type-safe lib as well… . It doesn’t give you as save(File file) method.
But for sponge you normally would get an object of this:
https://github.com/SpongePowered/SpongeAPI/blob/master/src/main/java/org/spongepowered/api/util/config/ConfigFile.java
What is rather simple I guess :smile:. I only wonder why the constructor is private :worried:. This class can be really useful.

The constructor is private, but there is a static method to parse a file:
public static ConfigFile parseFile(File file)

I’m using the class in my project:

It’s also showing how to use a fallback config/default values

1 Like

So in Bukkit, in order to unpack the config file from the plugin jar, one would have to call JavaPlugin.saveDefaultConfig(). Is something like this going to be necessary in Sponge? Or is this now an extraneous task that will be done silently in the background for us?

I guess not. You will need to extract the resource by yourself. I don’t like it either. Lets make a pull request :smile:.

This way you only need to check if the file exist and call either parsefile or parseresourse. When you save the ConfigFile from a resource it will do parsefile next time the server starts up :smile:.

2 Likes