-
Notifications
You must be signed in to change notification settings - Fork 13
ISerializable.java (WIP)
Recursive G edited this page Nov 18, 2017
·
1 revision
ISerializable
, together with it's variants FileConfigure
and PluginConfigure
, are the core components for plugin configuration serialization/deserialization. They are extensively used by all NyaaCat plugins and you may want to check source codes and JavaDoc for details.
public class Configuration extends PluginConfigure { // create your own config class
private final NyaaUtils plugin;
public Configuration(NyaaUtils plugin) {
this.plugin = plugin;
}
@Override
protected JavaPlugin getPlugin() {
return plugin;
}
@Serializable
public String language = "en_US"; // config item and default value
// ... more items
}
@Override
public void onEnable() {
this.cfg = new Configuration(this);
this.cfg.load(); // load your config when server starts
}
@Override
public void onDisable() {
this.cfg.save(); // save your config when server stops
}
private String changeLanguage(String newLang) {
String oldLang = this.cfg.language; // you can directly access the config item
this.cfg.language = newLang; // you can modify the config value
this.cfg.save(); // and you may want to save it immediately
return oldLang;
}