It's a simple class for creating JSON configurations files Minecraft.
Manual
Copy SmartConfiguration.java
in your Plugin.
Register SmartConfiguration in your Minecraft plugin.
Put SmartConfiguration.register(this)
in your onEnable()
.
@Override
public void onEnable() {
SmartConfiguration.register(this);
}
Create Java class than extends of SmartConfiguration.
In constructor initialize default values when JSON file is created.
Use update(this)
method in setters for automatically update JSON file.
public class ConfigurationExample extends SmartConfiguration<ConfigurationExample>{
private boolean pvpMode;
private String mapName;
private List<String> questList;
public ConfigurationExample() {
super("config.json", ConfigurationExample.class);
this.pvpMode = true;
this.mapName = "default-world";
this.questList = new ArrayList<>();
}
public boolean isPvpMode() {
return pvpMode;
}
public String getMapName() {
return mapName;
}
public List<String> getQuestList() {
return questList;
}
public void setMapName(String mapName) {
this.mapName = mapName;
update(this);
}
}
Put in variable new ConfigurationExample().load()
in your onEnable()
.
And now you can use simply your configuration with your getters and setters.
private ConfigurationExample configuration;
@Override
public void onEnable() {
SmartConfiguration.register(this);
this.configuration = new ConfigurationExample().load();
}
{
"pvpMode": true,
"mapName": "default-world",
"questList": []
}