Player state manager
PlayerStateManager is a small in-memory key/value store keyed by player UUID. It also exposes a coarse PlayerState enum (ALIVE, DEAD, SPECTATING, LOBBY) for callers that want a shared label across mods. Values are not persistent — if a player disconnects or the server restarts, the entry is gone. For durable state, use GameStateSavedData or a vanilla SavedData subclass.
When to use it
Section titled “When to use it”- A small per-player counter or flag you only care about for the current session.
- A scratchpad between two phases of the same round.
- A quick “lives left” / “lock count” counter that doesn’t need to survive a crash.
package me.zlex.conduit.state;
public final class PlayerStateManager { public enum PlayerState { ALIVE, DEAD, SPECTATING, LOBBY }
public static void setState(UUID player, PlayerState state); public static PlayerState getState(UUID player); // defaults to LOBBY
public static void setModData(UUID player, String key, Object value); public static <T> T getModData(UUID player, String key, T defaultValue);
public static void clear(UUID player);}Keys are plain strings — namespace them by mod id ("my-mod.locks") to avoid collisions across mods.
Example
Section titled “Example”import me.zlex.conduit.state.PlayerStateManager;import net.minecraft.server.level.ServerPlayer;
public final class MyLocks {
private static final String KEY = "my-mod.locks";
public static int locksFor(ServerPlayer p) { return PlayerStateManager.getModData(p.getUUID(), KEY, 3); }
public static void consumeLock(ServerPlayer p) { int current = locksFor(p); PlayerStateManager.setModData(p.getUUID(), KEY, Math.max(0, current - 1)); }
public static void onDeath(ServerPlayer p) { PlayerStateManager.setState(p.getUUID(), PlayerStateManager.PlayerState.DEAD); }}- Values are typed as
Object; the generic getter casts back. Pick types you control. - Nothing persists. If you need durability, store in a vanilla
SavedDataand only mirror the hot value here. clear(UUID)wipes both state and mod data for that player — usually called on disconnect from your own handler if you want eager cleanup.