Class RunProgressService

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

public final class RunProgressService extends Object
Tracks run milestone progress and computes split durations for record storage.
  • Constructor Details

    • RunProgressService

      public RunProgressService()
  • Method Details

    • restore

      public void restore(boolean reachedNether, long netherMs, boolean reachedBlazeObjective, long blazeObjectiveMs, boolean reachedEnd, long endMs)
      Restores run milestone state from a persistent snapshot.
      Parameters:
      reachedNether - whether the Nether was reached before save
      netherMs - timestamp when Nether was reached, or 0
      reachedBlazeObjective - whether the blaze objective was met before save
      blazeObjectiveMs - timestamp when blaze objective was met, or 0
      reachedEnd - whether the End was reached before save
      endMs - timestamp when End was reached, or 0
    • reset

      public void reset()
      Resets all tracked run milestones.
    • hasReachedNether

      public boolean hasReachedNether()
      Returns whether any participant has reached the Nether.
      Returns:
      true when the Nether milestone has been recorded
    • hasReachedEnd

      public boolean hasReachedEnd()
      Returns whether any participant has reached the End.
      Returns:
      true when the End milestone has been recorded
    • hasReachedBlazeObjective

      public boolean hasReachedBlazeObjective()
      Returns whether the blaze objective milestone has been reached.
      Returns:
      true when the blaze objective milestone has been recorded
    • isDragonKilled

      public boolean isDragonKilled()
      Returns whether the dragon kill milestone has been reached.
      Returns:
      true when the dragon kill milestone has been recorded
    • getNetherReachedMillis

      public long getNetherReachedMillis()
      Returns the timestamp when the Nether milestone was first reached.
      Returns:
      epoch milliseconds when Nether was reached, or 0 if not reached
    • getBlazeObjectiveReachedMillis

      public long getBlazeObjectiveReachedMillis()
      Returns the timestamp when the blaze objective milestone was first reached.
      Returns:
      epoch milliseconds when blaze objective was reached, or 0 if not reached
    • getEndReachedMillis

      public long getEndReachedMillis()
      Returns the timestamp when the End milestone was first reached.
      Returns:
      epoch milliseconds when End was reached, or 0 if not reached
    • resolveElapsedReferenceTime

      public long resolveElapsedReferenceTime(long currentTimeMillis)
      Resolves the timestamp to use for elapsed-time rendering.
      Parameters:
      currentTimeMillis - current wall-clock timestamp in milliseconds
      Returns:
      timestamp to use for elapsed-time calculations
    • markNetherReached

      public boolean markNetherReached(long timestampMillis)
      Marks the Nether milestone if it has not already been recorded.
      Parameters:
      timestampMillis - timestamp in milliseconds when the milestone was reached
      Returns:
      true when the milestone was newly recorded
    • markEndReached

      public boolean markEndReached(long timestampMillis)
      Marks the End milestone if it has not already been recorded.
      Parameters:
      timestampMillis - timestamp in milliseconds when the milestone was reached
      Returns:
      true when the milestone was newly recorded
    • markDragonKilled

      public void markDragonKilled(long timestampMillis)
      Marks the dragon kill milestone timestamp.
      Parameters:
      timestampMillis - timestamp in milliseconds when the dragon was killed
    • maybeMarkBlazeObjectiveReached

      public OptionalLong maybeMarkBlazeObjectiveReached(boolean runningPhase, int teamBlazeRodCount, long timestampMillis)
      Marks the blaze-rod milestone once the threshold is met during a run.
      Parameters:
      runningPhase - whether the challenge is currently in the running phase
      teamBlazeRodCount - total blaze rods currently held across participants
      timestampMillis - timestamp in milliseconds for this progress sample
      Returns:
      split duration from Nether entry to blaze objective completion when newly reached
    • currentObjectiveText

      public String currentObjectiveText(int teamBlazeRodCount)
      Builds the current objective label for run HUD/status output.
      Parameters:
      teamBlazeRodCount - total blaze rods currently held across participants
      Returns:
      objective text representing the next run milestone
    • snapshotForDisplay

      public RunProgressService.RunProgressSnapshot snapshotForDisplay(int teamBlazeRodCount)
      Captures a lightweight immutable progress snapshot for UI rendering.
      Parameters:
      teamBlazeRodCount - total blaze rods currently held across participants
      Returns:
      immutable progress snapshot for action-bar and sidebar rendering
    • countTeamBlazeRods

      public int countTeamBlazeRods(List<org.bukkit.entity.Player> participants)
      Counts total blaze rods across the given participant inventories.
      Parameters:
      participants - participants whose inventories should be counted
      Returns:
      total blaze rod count across all participant inventories
    • updateMilestonesFromParticipants

      public void updateMilestonesFromParticipants(List<org.bukkit.entity.Player> participants, long timestampMillis)
      Updates Nether/End milestones by inspecting participant world locations.
      Parameters:
      participants - participants whose world locations should be inspected
      timestampMillis - timestamp in milliseconds for newly reached milestones
    • calculateSectionDurations

      public RunProgressService.SectionDurations calculateSectionDurations(long runStartMillis, long dragonDeathTime, long fallbackDurationMillis)
      Calculates each run split duration, falling back to overall duration when a milestone was not reached.
      Parameters:
      runStartMillis - run start timestamp in milliseconds
      dragonDeathTime - dragon death timestamp in milliseconds
      fallbackDurationMillis - fallback duration used when a milestone is missing
      Returns:
      calculated run section durations for persistence and display