21 lines
700 B
Java
21 lines
700 B
Java
package games.dmg.spigottyrant;
|
|
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
public record PersistentState(GameState game, Map<UUID, PlayerState> players) {
|
|
public PersistentState {
|
|
game = game == null ? GameState.empty() : game;
|
|
players = players == null ? Map.of() : Map.copyOf(players);
|
|
for (Map.Entry<UUID, PlayerState> entry : players.entrySet()) {
|
|
if (!entry.getKey().equals(entry.getValue().playerId())) {
|
|
throw new IllegalArgumentException("player map key must match player state ID");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static PersistentState empty() {
|
|
return new PersistentState(GameState.empty(), Map.of());
|
|
}
|
|
}
|