Config Tutorial

Separate configs are really easy to make. All you need to do is create an instance of the Config class, providing the name of the file you want, and treat it the same as the config from your plugin. Example:

Config config = new Config(plugin, "data");
config.getConfig().set("data.me.health", 1000);
config.saveConfig();

You can even create configs in new folders by just adding slashes in the name:

Config config = new Config(plugin, "folder/data");

An optional way to create a config is simply to get it through MCCore. One bonus to this is that the config you get will auto-save any ISavable objects you add to it!

Config config = core.getConfigFile(plugin, "folder/data");

Or if you want to get the configuration section directly:

ConfigurationSection config = core.getConfig(plugin, "folder/data");

You can save the defaults for the config like your normal config as well

config.saveDefaultConfig();

Version 1.3

With version 1.3, there's the new interface "ISavable" that your data can implement. When you do this, you can then add your data to Config objects via the addSavable(ISavable) method. This does one of two things:

  • If you obtained the config through MCCore.getConfig(JavaPlugin plugin, String file) or MCCore.getConfigFile(JavaPlugin, String file), then your config will automatically save when the server reloads or stops.
  • If you created your own instance, then you can just call Config.save() in order to save all of the savables you added to it. Neat!

Comments

Posts Quoted:
Reply
Clear All Quotes