Skip to content

Commit

Permalink
Merge pull request BetonQuest#2530 from Wolf2323/APIDocsRework
Browse files Browse the repository at this point in the history
basic rework of the API docs and how to get an API part
  • Loading branch information
Wolf2323 authored Oct 5, 2023
2 parents 0c95e84 + 733f752 commit 127acac
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 177 deletions.
109 changes: 0 additions & 109 deletions docs/API/API.md

This file was deleted.

34 changes: 22 additions & 12 deletions docs/API/ConfigurationFile.md → docs/API/ConfigurationFiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ icon: material/note-edit
---
@snippet:api-state:draft@

!!! abstract "[ServicesManager](Obtaining-API.md) API Classes"
* `org.betonquest.betonquest.api.config.ConfigurationFileFactory`
---

BetonQuest provides the `ConfigurationFile`, a simple API to load, reload, save and delete configuration files.
It extends `ConfigurationSection` and therefore also provides the well-known Bukkit methods to access and modify the configuration.
Additionally, it takes care of patching the config whenever syntax or content changes need to be made.
Expand All @@ -11,12 +15,14 @@ Additionally, it takes care of patching the config whenever syntax or content ch

By creating a ConfigurationFile you either load an existing config or create the default one from your plugin's resources.
```java
ConfigurationFileFactory configurationFileFactory; //(1)!
Plugin plugin = MyBQAddonPlugin.getInstance();
File configFile = new File(plugin.getDataFolder(), "config.yml"); // (1)!
ConfigurationFile config = new ConfigurationFile(configFile, plugin, "defaultConfig.yml");
File configFile = new File(plugin.getDataFolder(), "config.yml"); // (2)!
ConfigurationFile config = configurationFileFactory.create(configFile, plugin, "defaultConfig.yml");
```

1. This is the location the config will be saved to. In this case it's a file named "_config.yml_" in your plugin's folder.
1. Obtained via the ServicesManager, see the [Obtaining API](Obtaining-API.md) page.
2. This is the location the config will be saved to. In this case it's a file named "_config.yml_" in your plugin's folder.

Additionally, the ConfigurationFile will attempt to patch itself with a patch file. See [updating ConfigurationFiles](#updating-configurationfiles) for more information.

Expand All @@ -27,6 +33,13 @@ You can reload, save and delete the ConfigurationFile by calling it's correspond
methods.

Make sure to add a `configVersion` key with an empty string as it's value when adding a new config resource file.

``` YAML title="Example config.yml"
configVersion: ""
language: en
# ...
```

The patcher will then automatically set the version to the newest available patch version.
This frees you from the hassle of updating the `configVersion` key in the default resource file every time you add a patch.

Expand Down Expand Up @@ -259,15 +272,12 @@ This is just a functional interface, that registers additional transformers.
Utilizing this possibility will however override the default transformers. You need to re-add them explicitly.

```JAVA title="Anonymous PatchTransformerRegisterer Example"
config = ConfigurationFile.create(configFile, MyPlugin.getInstance(), "config.yml",
new PatchTransformerRegisterer() {
@Override
public void registerTransformers(final Patcher patcher) {
PatchTransformerRegisterer.super.registerTransformers(patcher); //(1)!
// Register your own transformers here:
patcher.registerTransformer("myTransformer", new MyTransformer());
}
});
PatchTransformerRegisterer defaultTransformers = new DefaultPatchTransformerRegisterer();
config = ConfigurationFile.create(configFile, MyPlugin.getInstance(), "config.yml", patcher -> {
defaultTransformers.registerTransformers(patcher); //(1)!
// Register your own transformers here:
patcher.registerTransformer("myTransformer", new MyTransformer());
});
```

1. Call this if you want to use the default transformers alongside your own.
Loading

0 comments on commit 127acac

Please sign in to comment.