Skip to content

Configuration API

Andre_601 edited this page Jan 3, 2019 · 1 revision

The Configuration API allows you to generate a config file with all values and comments you define.
This API only allows creation and load of the file.

Configuration notes and value paths are delimited by .-characters.
For example: Value1.Value2 becomes:

Value1:
  Value2: //something here

Table of content

FileConfiguration

Used to set a yaml file to the load or write the values too.

Example:

FileConfiguration config = new FileConfiguration(this, "config.yml");
Parameter: Type:
JavaPlugin Instance of your plugin
String Name of the file (with extension)

#load();

Loads the FileConfiguration file, if it exists.

#set(String, Object);

Sets values of the FileConfiguration file.
You have to run the #save(); after you set the values, to generate the file.

Example:

config.set("SomeKey", 1);
Parameter: Type:
String Name of the key
Object The value of the key

#save();

Saves the set values from #set(String, Object); to the actual file (Generates it).

#get(String, Object);

Gets the value from the provided key, or sets the default one, if none is set (non-existant).
Run #save(); after this method, to directly save the missing keys.

Example:

config.get("SomeKey", 5);
Parameter: Type:
String Name of the key to get the value from
Object Default value, if key doesn't exist
Clone this wiki locally