Skip to content

Feature: Add player and server data container systems with JSON persistence#11

Merged
Trilleo merged 1 commit into
masterfrom
copilot/add-player-data-container-solution
Apr 21, 2026
Merged

Feature: Add player and server data container systems with JSON persistence#11
Trilleo merged 1 commit into
masterfrom
copilot/add-player-data-container-solution

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 21, 2026

Adds per-player and server-wide JSON-backed data containers with automatic load/save lifecycle hooks, following the existing registration patterns.

New: data package

  • PlayerData — open class with typed getString/getInt/getDouble/getBoolean getters and set/remove/has mutators over a JsonObject. Extend to expose strongly-typed Kotlin properties.
  • PlayerDataManager — singleton; registers an internal Listener that loads playerdata/<uuid>.json on PlayerJoinEvent and flushes on PlayerQuitEvent. saveAll() is called from onDisable as a safety net. Supports a custom factory via setFactory { uuid -> MyPlayerData(uuid) }.
  • ServerData / ServerDataManager — same API, single instance; loaded on init, persisted via save() from onDisable. Stored at serverdata.json.

Both managers log WARNING on corrupt/missing files and SEVERE on write failures.

Usage

// Basic — no subclassing required
val data = PlayerDataManager.get(player)
data.set("kills", data.getInt("kills") + 1)

// Typed subclass
class MyPlayerData(uuid: UUID) : PlayerData(uuid) {
    var kills: Int
        get() = getInt("kills")
        set(value) = set("kills", value)
}

PlayerDataManager.setFactory { uuid -> MyPlayerData(uuid) }  // before init
val typed = PlayerDataManager.get(player) as MyPlayerData
typed.kills++

Main.kt

  • onEnable: calls ServerDataManager.init(this) then PlayerDataManager.init(this).
  • onDisable: calls PlayerDataManager.saveAll() and ServerDataManager.save().

Docs

DEVELOPER_GUIDE.md updated with full Player Data and Server Data sections covering API reference, subclass pattern, and example listener/command.

@Trilleo Trilleo marked this pull request as ready for review April 21, 2026 15:30
@Trilleo Trilleo merged commit 742cf22 into master Apr 21, 2026
@Trilleo Trilleo deleted the copilot/add-player-data-container-solution branch April 22, 2026 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants