5fc3bda1c5
- player-load: load-on-join (PlayerReadyEvent → IO → modify). - async-moderation: IAsyncEvent → coroutine bridge for chat moderation. - periodic-leaderboard: pluginScope loop with parallel reads. - bounty-board: kitchen-sink demo exercising every v0.1 primitive.
1.2 KiB
1.2 KiB
player-load
Loads <plugin data dir>/players/<uuid>.json when a player joins, hydrates a
PlayerStats component on the world thread.
What it shows
eventRegistry.registerGlobal(PlayerReadyEvent::class.java) { … }— the right overload for events with a non-Voidkey type.playerScope(player).launch { … }— coroutine bound to the player. Cancels on disconnect, so a slow disk read doesn't outlive the session.withContext(AsyncDispatchers.HytaleIO) { … }— file I/O off the world thread.modify<PlayerStats>(player.handle()) { … }— thread-safe component mutation. The dispatcher switches happen automatically.
Build
./gradlew shadowJar
# → build/libs/player-load.jar
Run
- Drop the JAR in your dev server's
mods/. - Wire
PlayerStatsBinding.componentType()— replace theTODO()with whateverEntityStore.REGISTRY.register(PlayerStats::class.java, …)returns in your setup. - Seed
<server>/data/Mythlane.PlayerLoad/players/<your-uuid>.json:{"level":42,"clan":"red"} - Connect. The values land on the live
PlayerStatscomponent.
The JSON parser in the example is intentionally minimal — use
kotlinx.serialization in real plugins.