Class RenewSchedule

java.lang.Object
com.ordwen.odailyquests.tools.RenewSchedule

public final class RenewSchedule extends Object
Utility class responsible for computing quest renewal schedules.

It centralizes all time-based calculations related to renewals (next execution, elapsed intervals, offline catch-up logic), ensuring consistent behavior across the plugin.

The schedule is defined by:

  • a daily anchor time (LocalTime)
  • a renewal interval (Duration)
  • a time zone (ZoneId)
  • a timestamp mode (raw int, handled elsewhere)

This class is stateless and cannot be instantiated.

  • Method Details

    • settings

      public static RenewSchedule.Settings settings()
      Builds a RenewSchedule.Settings instance from the current plugin configuration.
      Returns:
      the configured renewal schedule settings
    • isValid

      public static boolean isValid(RenewSchedule.Settings s)
      Validates that the given settings are usable for scheduling calculations.
      Parameters:
      s - the schedule settings to validate
      Returns:
      true if the settings are valid, false otherwise
    • nextExecutionAtOrAfter

      public static ZonedDateTime nextExecutionAtOrAfter(ZonedDateTime now, RenewSchedule.Settings s)
      Computes the next scheduled execution time greater than or equal to now.

      The calculation uses an anchor defined as "today at renewTime", then applies k * interval to reach the first execution ≥ now.

      This method is the single source of truth for renewal timing and is used by both timer tasks and remaining-time displays.

      Parameters:
      now - the current date-time
      s - the schedule settings
      Returns:
      the next scheduled execution time
    • shouldRenewSince

      public static boolean shouldRenewSince(ZonedDateTime lastRenew, ZonedDateTime now, RenewSchedule.Settings s)
      Determines whether at least one scheduled execution occurred after lastRenew and before or at now.

      This method is intended for offline catch-up logic (e.g. when a player reconnects after being offline).

      Parameters:
      lastRenew - the last recorded renewal time
      now - the current date-time
      s - the schedule settings
      Returns:
      true if a renewal should occur, false otherwise
    • millisUntilNext

      public static long millisUntilNext(ZonedDateTime now, RenewSchedule.Settings s)
      Returns the number of milliseconds remaining until the next scheduled execution.
      Parameters:
      now - the current date-time
      s - the schedule settings
      Returns:
      the remaining time in milliseconds (never negative)