Class PlayerProfileManager
java.lang.Object
net.joseplay.allianceutils.api.playerProfile.data.PlayerProfileManager
Manages
PlayerProfile lifecycle, including caching, synchronization,
persistence, and cross-server updates.
Core design principles:
- Profiles are never exposed directly (only immutable snapshots)
- All mutations must go through
modify(UUID, Consumer) - Thread-safety is enforced via per-profile locks
- Persistence is asynchronous and batched
Caching:
- Backed by Caffeine
LoadingCache - Entries expire after inactivity
- Maximum size is bounded
Concurrency model:
- Each profile has its own
ReentrantReadWriteLock - Reads use snapshots (no shared mutable state)
- Writes are exclusive and rate-limited
Data integrity:
- Changes are detected via JSON diff
- Only modified profiles are persisted
- Dirty flag ensures retry on failure
Warning:
- Snapshots are deep-copied via JSON (performance cost)
- No strong consistency across servers (eventual consistency)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyRemoteUpdate(@NotNull UUID uuid, @NotNull String json) Applies a remote update received from another server.@NotNull PlayerProfileDeprecated.Retorna apenas SNAPSHOT (somente leitura)@NotNull PlayerProfilegetSnapshot(@NotNull UUID uuid) Returns an immutable snapshot of the player's profile.voidloadOnJoin(UUID uuid) Preloads a profile into cache (typically on player join).voidmodify(@NotNull UUID uuid, @NotNull Consumer<PlayerProfile> modifier) Applies a mutation to the player's profile in a thread-safe manner.voidForces immediate persistence of a profile if present in cache.voidshutdown()Flushes all dirty profiles and shuts down the persistence executor.voidunloadOnQuit(UUID uuid) Saves and removes a profile from active usage (typically on player quit).
-
Constructor Details
-
PlayerProfileManager
public PlayerProfileManager()
-
-
Method Details
-
getPlayer
Deprecated.Retorna apenas SNAPSHOT (somente leitura) -
getSnapshot
Returns an immutable snapshot of the player's profile.The returned object is a deep copy and must not be used for mutations.
- Parameters:
uuid- player UUID- Returns:
- immutable snapshot
-
modify
Applies a mutation to the player's profile in a thread-safe manner.Execution flow:
- Global rate limit check
- Acquire write lock
- Apply mutation
- Detect changes via JSON comparison
- Mark as dirty if changed
- Dispatch async update to other servers
- Schedule async persistence
Failure cases:
- Rate limit exceeded → modification is ignored
- Lock not acquired → modification is skipped
- Parameters:
uuid- player UUIDmodifier- mutation logic
-
shutdown
public void shutdown()Flushes all dirty profiles and shuts down the persistence executor.Warning: Failure here may result in data loss.
-
applyRemoteUpdate
Applies a remote update received from another server.This overwrites the local profile state.
- Parameters:
uuid- player UUIDjson- serialized profile
-
saveNow
Forces immediate persistence of a profile if present in cache.This operation is synchronous and blocks the current thread.
- Parameters:
uuid- player UUID
-
loadOnJoin
Preloads a profile into cache (typically on player join).- Parameters:
uuid- player UUID
-
unloadOnQuit
Saves and removes a profile from active usage (typically on player quit).- Parameters:
uuid- player UUID
-