Skip to content
/ Rson Public

Gson wrapper that works between Sponge and Bukkit

License

Notifications You must be signed in to change notification settings

redstone/Rson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rson

This library is not a plugin, but a component you could include.

This is made to work between CraftBukkit, Spigot, and Sponge.

Gradle

First add JitPack to your repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Now add Rson to your dependencies

dependencies {
	compile 'com.github.redstone:Rson:1.0.0'
}

Usage

Create a class that you want to be saveable

public class Config extends Rson<Config> {

	// Singleton, you don't have to do this - organise your creation and
	// defining of path however you want
	private static transient Config i;
	public static Config get() {
		if (i == null) {
			// Create an instance
			i = new Config();

			// Call setup to set the path and the charset
			i.setup(Paths.get(Plugin.get().getDataFolder().toString(), "config.json"), Charset.defaultCharset());
		}
		return i;
	}
	public Config() { }

	public Boolean configurationOption = true;
	public Boolean moreConfigurationOptions = false;

	public Double justSomeMoreConfigurationOptions = 55.10;

}

So now you can grab this config and load/save it. If the json file doesn't exist on load it simply loads the defaults.

Config.get().load().save();

Now, we can access any of these fields:

if (Config.get().configurationOption) {
	// .. do something
} else {
	// we can modify and save whenever we want
	Config.get().configurationOption = true;
	Config.get().save();
}