PlayerData

class PlayerData(val uuid: UUID, username: String, level: Int, xp: Long, gold: Int, gems: Int)

Data class representing all persistent player information in the MMO system.

This class serves as the central data structure for storing and managing all player-related information that needs to persist across server restarts. It implements a dirty tracking system to optimize database operations by only saving data when changes have been made.

The class manages several categories of player data:

  • Core Stats: Level, XP, gold, gems

  • Identity: UUID and username

  • Inventory: Main inventory and armor contents

  • Flags: Persistent key-value pairs for plugin communication

  • Preferences: Plugin-specific settings and data storage

Dirty Tracking System: The class automatically tracks when data has been modified through the isDirty flag. All property setters update this flag when values change, allowing the persistence system to perform efficient saves by only writing modified data to the database.

Thread Safety: This class is NOT thread-safe. Access should be synchronized externally or limited to single-threaded contexts (typically the main server thread).

Parameters

uuid

The unique identifier for this player (immutable)

username

The player's current display name (mutable)

level

The player's current character level

xp

The player's total experience points

gold

The player's current gold currency amount

gems

The player's current gem currency amount

Constructors

Link copied to clipboard
constructor(uuid: UUID, username: String, level: Int, xp: Long, gold: Int, gems: Int)

Properties

Link copied to clipboard
var armorContents: Array<ItemStack?>

Array containing the player's equipped armor contents.

Link copied to clipboard
var gems: Int

The player's current gem currency amount.

Link copied to clipboard
var gold: Int

The player's current gold currency amount.

Link copied to clipboard
var inventoryContents: Array<ItemStack?>

Array containing the player's main inventory contents.

Link copied to clipboard

Flag indicating whether this PlayerData instance has been modified.

Link copied to clipboard
var level: Int

The player's current character level.

Link copied to clipboard

Map containing persistent player flags for inter-plugin communication.

Link copied to clipboard

Nested map containing plugin-specific player preferences and data.

Link copied to clipboard

The player's current username/display name.

Link copied to clipboard
val uuid: UUID
Link copied to clipboard
var xp: Long

The player's total accumulated experience points.

Functions

Link copied to clipboard
fun addGems(amount: Int)

Adds gems currency to the player's balance.

Link copied to clipboard
fun addGold(amount: Int)

Adds gold currency to the player's balance.

Link copied to clipboard
fun addXp(amount: Long)

Adds experience points to the player's total XP.

Link copied to clipboard

Retrieves a player flag value by key.

Link copied to clipboard
fun getPluginPlayerPref(pluginKey: String, prefKey: String): Any?

Retrieves a plugin-specific preference without type checking.

fun <T> getPluginPlayerPref(pluginKey: String, prefKey: String, type: Class<T>, defaultValue: T?): T?

Retrieves a plugin-specific preference with type safety and default value support.

Link copied to clipboard
fun markDirty()

Manually marks this PlayerData instance as dirty.

Link copied to clipboard

Removes a player flag from the persistent storage.

Link copied to clipboard
fun removePluginPlayerPref(pluginKey: String, prefKey: String)

Removes a plugin-specific preference.

Link copied to clipboard
fun setClean()

Marks this PlayerData instance as clean (not modified).

Link copied to clipboard
fun setPlayerFlag(key: String, value: String)

Sets a player flag to a specific value.

Link copied to clipboard
fun setPluginPlayerPref(pluginKey: String, prefKey: String, value: Any)

Sets a plugin-specific preference value.