Package dev.deepcore.challenge.session
Class SavedRunStateService
java.lang.Object
dev.deepcore.challenge.session.SavedRunStateService
Persists and restores a single saved speedrun state across server restarts.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordSnapshot of a single player's position, inventory, health, and status state.static final recordSnapshot of the full run state serialized to disk on a save vote. -
Constructor Summary
ConstructorsConstructorDescriptionSavedRunStateService(org.bukkit.plugin.java.JavaPlugin plugin, DeepCoreLogger log) Creates a saved-run state service backed by a YAML file in the plugin data folder. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapplySnapshot(org.bukkit.entity.Player player, SavedRunStateService.PlayerSnapshot snapshot) Applies a saved snapshot to a player, teleporting them to their saved location and restoring their inventory, health, hunger, XP, game mode, and potion effects.capturePlayer(org.bukkit.entity.Player player) Captures the current in-game state of a player as a persistent snapshot.voidDeletes the saved run file from disk, clearing the restore slot.booleanReturns whether a saved run file currently exists on disk.Loads and deserializes the saved run from disk.voidsaveRun(SavedRunStateService.SavedRunSnapshot snapshot) Serializes the given snapshot to the saved-run YAML file, overwriting any previous save.
-
Constructor Details
-
SavedRunStateService
Creates a saved-run state service backed by a YAML file in the plugin data folder.- Parameters:
plugin- plugin instance used to resolve the data folder pathlog- logger for save and load diagnostics
-
-
Method Details
-
hasSavedRun
public boolean hasSavedRun()Returns whether a saved run file currently exists on disk.- Returns:
- true when a saved run is available for restore
-
saveRun
Serializes the given snapshot to the saved-run YAML file, overwriting any previous save.- Parameters:
snapshot- run snapshot to persist
-
loadSavedRun
Loads and deserializes the saved run from disk.- Returns:
- the saved snapshot, or empty if no save file exists
-
clearSavedRun
public void clearSavedRun()Deletes the saved run file from disk, clearing the restore slot. -
capturePlayer
Captures the current in-game state of a player as a persistent snapshot.- Parameters:
player- player whose state should be captured- Returns:
- snapshot of the player's current position, inventory, health, and status
-
applySnapshot
public static void applySnapshot(org.bukkit.entity.Player player, SavedRunStateService.PlayerSnapshot snapshot) Applies a saved snapshot to a player, teleporting them to their saved location and restoring their inventory, health, hunger, XP, game mode, and potion effects.- Parameters:
player- player to restoresnapshot- snapshot to apply
-