Class PlayerSettingsCache
preloadSettings(java.util.UUID, java.lang.String)), read by the dialog-open paths, updated in place on change, and evicted
on quit (evictSettings(java.util.UUID)) — so it is bounded by the online-player count. Writes go straight
to the DB (write-through), so the cache holds no dirty state and needs no shutdown flush. See the
leak-free invariant documented on preloadSettings(java.util.UUID, java.lang.String).
preloadSettings(java.util.UUID, java.lang.String) is also where a player's name is recorded, because the settings row it
already loads carries the last known username — so the check is free and the write only
happens on a first-ever join or a rename. That is what makes PlayerNameIndex complete without
ever reading the playerdata folder: every player who joins is in the players table
from then on, and admin tab-completion needs no other source. ChestOpener's open prelude does
the same check against its own already-loaded row, covering players who were online before this
plugin loaded.
-
Constructor Summary
ConstructorsConstructorDescriptionPlayerSettingsCache(EnderChestStorage storage, DbExecutor db, org.slf4j.Logger logger, PlayerNameIndex nameIndex, Telemetry telemetry) -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Drops every cached entry on shutdown.voidevictSettings(UUID owner) Evicts a player's cached settings on quit.voidRecords a name in the in-memoryPlayerNameIndexonly, with no DB write — called on join, where the name is already in hand, so an admin can tab-complete the player immediately instead of waiting onpreloadSettings(java.util.UUID, java.lang.String)'s round trip (or losing the name entirely if the startup index load failed).loadSettingsAsync(UUID owner) Returns the player's settings, served from the cache when present (the common case for an online player).markSeenAsync(UUID owner, String username) Records that the player is here now: their in-game name (offline/ee viewresolution) andlast_online, which decides how long they keep showing up in admin name suggestions.voidpreloadSettings(UUID owner, String currentName) Loads a player's settings into the cache on join.setAppliedDefaultSizeAsync(UUID owner, int size) Persists the base-chest size baseline the default-size reconcile just applied, with a single targeted upsert (no preceding read), leaving edit-mode untouched.setEditModeAsync(UUID owner, boolean editMode) Persists the player's edit-mode preference with a single targeted upsert (no preceding read), leaving every other setting untouched.
-
Constructor Details
-
PlayerSettingsCache
public PlayerSettingsCache(EnderChestStorage storage, DbExecutor db, org.slf4j.Logger logger, PlayerNameIndex nameIndex, Telemetry telemetry)
-
-
Method Details
-
preloadSettings
Loads a player's settings into the cache on join. This is the cache's only inserter, which keeps the leak-free invariant simple: every entry added here is removed byevictSettings(java.util.UUID)on quit. The post-load online re-check covers the join-then-immediate-quit race — if the player already left while the load was in flight (soevictSettingsran before this put), the entry is dropped right after it is added, so nothing is ever orphaned.currentNameis the joining player's name, compared against theusernameon the row that was just loaded. Recording it here rather than only on a chest open is what keepsPlayerNameIndex— and therefore admin tab-completion — complete from the database alone, with noplayerdatascan anywhere in the plugin. -
indexName
Records a name in the in-memoryPlayerNameIndexonly, with no DB write — called on join, where the name is already in hand, so an admin can tab-complete the player immediately instead of waiting onpreloadSettings(java.util.UUID, java.lang.String)'s round trip (or losing the name entirely if the startup index load failed).nowas the last-seen time is exactly right: they just joined. -
evictSettings
Evicts a player's cached settings on quit. Paired withpreloadSettings(java.util.UUID, java.lang.String)so the cache stays bounded by online players. -
loadSettingsAsync
Returns the player's settings, served from the cache when present (the common case for an online player). A miss — preload still in flight, or the player was already online before the plugin loaded — falls back to a one-off DB read that is deliberately not cached, sopreloadSettings(java.util.UUID, java.lang.String)remains the sole inserter and the leak-free invariant holds. -
setEditModeAsync
Persists the player's edit-mode preference with a single targeted upsert (no preceding read), leaving every other setting untouched. Write-through: the cached copy is updated in place first (if present) so the next dialog open reflects the change without a DB read, then the DB is written. UsescomputeIfPresentso it never inserts — preserving the leak-free invariant. -
setAppliedDefaultSizeAsync
Persists the base-chest size baseline the default-size reconcile just applied, with a single targeted upsert (no preceding read), leaving edit-mode untouched. Write-through: the cached copy is updated in place first (if present) so the next reconcile sees the new baseline without a DB read (and so its fast path holds), then the DB is written. UsescomputeIfPresentso it never inserts — preserving the leak-free invariant. -
markSeenAsync
Records that the player is here now: their in-game name (offline/ee viewresolution) andlast_online, which decides how long they keep showing up in admin name suggestions. Called on join and quit, and byChestOpener's open prelude when the name it loaded is stale.Unconditional, unlike the old name-only write, because
last_onlinechanges every time by definition — and it costs no extra statement:CachedStorageonly mutates the resident row and marks it dirty, so this rides the next batched flush together with the player's chests.Write-through: the cached copy is updated in place first (if present), then the storage layer. Uses
computeIfPresentso it never inserts — preserving the leak-free invariant. -
clear
public void clear()Drops every cached entry on shutdown. The write-through cache holds no dirty state (every change was persisted immediately), so there is nothing to flush — just release the references.
-