add hytale configurable docs

This commit is contained in:
PiggyPiglet
2026-02-08 22:57:53 +08:00
parent 90908e30fe
commit 91b6d615bf
3 changed files with 78 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
---
description: How to create configurable expansions in Hytale.
---
# The Configurable<T> Interface
Unlike in spigot, in Hytale PAPI does not forward through Hytale's configuration API and instead implements its own. Effectively you'll be required to create a class representing your configuration section in PlaceholderAPI's main config.yml, and PAPI will handle the rest.
## Create Your Config Class
```java { .annotate title="CoolExpansionConfig.java" }
public final class CoolExpansionConfig {
private String test;
private String dateFormat;
public CoolExpansionConfig(String test, String dateFormat) {
this.test = test;
this.dateFormat = dateFormat;
}
public String test() {
return test;
}
public String dateFormat() {
return dateFormat;
}
}
```
Your config class needs to represent your config structure exactly. The only difference is in naming, in the above example, dateFormat will be converted to snake case (date_format) when reading the yaml. The above class will look like this in PAPI's config:
```yaml { .annotate title="HelpChat_PlaceholderAPI/config.yml" }
expansions:
coolexpansion:
test: wew
date_format: "dd/mm/yyyy"
```
## Using Your Config Class
Once created, we need to tell PAPI about it. In your PlaceholderExpansion class, implement `Configurable<CoolExpansionConfig>`, you'll then need to also implement the 2 required methods.
```java { .annotate title="CoolExpansion.java" }
public final class CoolExpansion extends PlaceholderExpansion implements Configurable<CoolExpansionConfig> {
@Override
public Class<CoolExpansionConfig> provideConfigType() {
return CoolExpansionConfig.class;
}
@Override
public CoolExpansionConfig provideDefault() {
return new CoolExpansionConfig("wew", "dd/mm/yyyy");
}
@Override
public String onPlaceholderRequest(PlayerRef player, String params) {
final CoolExpansionConfig config = getExpansionConfig(CoolExpansion.class);
return switch(params) {
case "test" -> config.test();
case "date_format" -> config.dateFormat();
default -> null;
};
}
}
```
That's pretty much it. PAPI will generate the default yaml from the values you provide in `provideDefault()` and write it to the PAPI config, then whenever your expansion starts it'll read the values from the config and put them into a CoolExpansionConfig object accessible via `PlaceholderExpansion<T>.getExpansionConfig(Class<T extends Configurable<T>>)`

View File

@@ -26,6 +26,14 @@ The pages listed under this section are meant for developers of plugins who want
- [:octicons-chevron-right-16: Go to Page](creating-a-placeholderexpansion.md)
- ### Using the Hytale Configuration API
----
How to create a configurable expansion for Hytale
- [:octicons-chevron-right-16: Go to Page](configuration-api-hytale.md)
- ### eCloud
----

View File

@@ -32,6 +32,7 @@ It also has a community-curated list of all available Placeholder expansions and
- [:octicons-chevron-right-16: Using PlaceholderAPI](developers/using-placeholderapi.md)
- [:octicons-chevron-right-16: Creating a PlaceholderExpansion](developers/creating-a-placeholderexpansion.md)
- [:octicons-chevron-right-16: Using the Hytale Configuration API](developers/configuration-api-hytale.md)
- [:octicons-chevron-right-16: eCloud](developers/expansion-cloud.md)
- ### :material-alert-circle-outline: Common Issues