Class SavedRunStateService

java.lang.Object
dev.deepcore.challenge.session.SavedRunStateService

public final class SavedRunStateService extends Object
Persists and restores a single saved speedrun state across server restarts.
  • Constructor Details

    • SavedRunStateService

      public SavedRunStateService(org.bukkit.plugin.java.JavaPlugin plugin, DeepCoreLogger log)
      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 path
      log - 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

      public void saveRun(SavedRunStateService.SavedRunSnapshot snapshot)
      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

      public static SavedRunStateService.PlayerSnapshot capturePlayer(org.bukkit.entity.Player player)
      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 restore
      snapshot - snapshot to apply