Add support for @RegisterCommand, @Key, @Min, and @Max annotations for command registration, custom keys, and configuration bounds.
This commit is contained in:
1 parent
9fcde10fed
commit
9af951b4be
17 files changed
+577
-33
No files matched your search
+28
-2
@@ -186,6 +186,25 @@ Methods of `Mod`, usable from the constructor on, and in field initializers:
|
||||
| `commands()` | `Commands` | admin commands for chat, the server console, and RCON |
|
||||
| `clientCommands()` | `ClientCommands` | server commands to clients, received by their Lua mods |
|
||||
|
||||
## Settings
|
||||
|
||||
`config().bind(Settings.class)` reads `config.toml` into a record. Keys are the component names
|
||||
in `snake_case` (`maxBalance` reads `max_balance`); defaults come from the jar's
|
||||
`META-INF/zomboidforge/config.toml`.
|
||||
|
||||
```java
|
||||
record Settings(
|
||||
@Key("max_hp_regen") int healthRegenPerHour, // keeps its key after a rename
|
||||
@Min(1) @Max(100) int maxPlayers, // bounds for numbers, also inside List, Map, Optional
|
||||
String greeting
|
||||
) {}
|
||||
```
|
||||
|
||||
A missing, mistyped, or out-of-bounds value stops the server, and the log lists every problem
|
||||
with its key (`'max_players' must be at most 100, found 250.`). `@Key` names are `snake_case`
|
||||
and differ within a record; `@Min`/`@Max` only fit numeric components and may be fractions
|
||||
(`@Max(0.5) double ratio`).
|
||||
|
||||
## Threads
|
||||
|
||||
Game objects belong to the server's main thread. Everything else should stay off it, because
|
||||
@@ -289,9 +308,14 @@ public class HelloCommand extends CommandBase
|
||||
public void onLoad() { this.commands().register(HelloCommand.class); }
|
||||
```
|
||||
|
||||
Or `@RegisterCommand` on the class (`dev.overlord.zomboidforge.api.annotations`), without the
|
||||
call: ZomboidForge registers the annotated classes of the mod's own jar (not of `lib/`) by name,
|
||||
before `onLoad()`.
|
||||
|
||||
- **Registration** happens in the entry point's constructor or `onLoad()`; later calls throw.
|
||||
`register` checks the class and throws `IllegalArgumentException` listing every problem,
|
||||
which stops the server like any other exception in `onLoad()`.
|
||||
which stops the server like any other exception in `onLoad()`; an annotated class that breaks
|
||||
the rules stops it the same way.
|
||||
- **The class** is public and not abstract, with one public constructor
|
||||
`(String, Role, String, UdpConnection)`.
|
||||
- **Names** (`@CommandName`, repeatable for aliases) consist of letters, digits, and `_` and
|
||||
@@ -400,7 +424,9 @@ this.storage().transaction(() -> { // all or nothin
|
||||
| `Instant` | ISO-8601 text |
|
||||
| `byte[]` | blob |
|
||||
|
||||
Table and column names are `snake_case`: `lastPaid` is stored as `last_paid`.
|
||||
Table and column names are `snake_case`: `lastPaid` is stored as `last_paid`. `@Key("paid_at")`
|
||||
on a component sets the column name instead, so a renamed component keeps its column and data.
|
||||
`@Min`/`@Max` are for settings; storage ignores them.
|
||||
|
||||
When the record changes between versions of the mod:
|
||||
|
||||
|
||||
Reference in new issue
Block a user