|
|
@ -17,7 +17,7 @@ added to this class and which are not `final`, `static` or `transient` can autom
|
|
|
|
|
|
|
|
|
|
|
|
##### Saving and loading a configuration
|
|
|
|
##### Saving and loading a configuration
|
|
|
|
Instances of your configuration class have a `load`, `save` and `loadAndSave` method:
|
|
|
|
Instances of your configuration class have a `load`, `save` and `loadAndSave` method:
|
|
|
|
- `load` reads the configuration file and updates the field values of your instance.
|
|
|
|
- `load` updates all fields of an instance with the values read from the configuration file.
|
|
|
|
- `save` dumps all field names and values to a configuration file. If the file exists, it is
|
|
|
|
- `save` dumps all field names and values to a configuration file. If the file exists, it is
|
|
|
|
overridden; otherwise, it is created.
|
|
|
|
overridden; otherwise, it is created.
|
|
|
|
- `loadAndSave` first calls `load` and then `save`, which is useful when you have added or
|
|
|
|
- `loadAndSave` first calls `load` and then `save`, which is useful when you have added or
|
|
|
@ -64,13 +64,14 @@ public final class DatabaseConfig extends Configuration {
|
|
|
|
/* optional GETTER and SETTER methods */
|
|
|
|
/* optional GETTER and SETTER methods */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
```
|
|
|
|
#### Example usage
|
|
|
|
#### Example Bukkit plugin
|
|
|
|
```java
|
|
|
|
```java
|
|
|
|
public class Plugin {
|
|
|
|
public class ExamplePlugin extends JavaPlugin {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
@Override
|
|
|
|
Path path = Paths.get("/dir1/dir2/config.yml");
|
|
|
|
public void onEnable() {
|
|
|
|
|
|
|
|
Path configPath = new File(getDataFolder(), "config.yml").toPath();
|
|
|
|
|
|
|
|
|
|
|
|
DatabaseConfig config = new DatabaseConfig(path);
|
|
|
|
DatabaseConfig config = new DatabaseConfig(configPath);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
config.loadAndSave();
|
|
|
|
config.loadAndSave();
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|