Class PlaytimeTracker

java.lang.Object
com.storytimeproductions.stweaks.playtime.PlaytimeTracker

public class PlaytimeTracker extends Object
Manages and tracks the playtime of players on the server.

This class stores playtime data for each player, handles AFK status, and provides utility methods to query remaining required playtime. It also supports persistence via SQLite, allowing playtime data to survive server restarts and reset automatically if a new day begins.

  • Field Details

  • Constructor Details

    • PlaytimeTracker

      public PlaytimeTracker()
  • Method Details

    • init

      public static void init(org.bukkit.plugin.java.JavaPlugin pl)
      Initializes the PlaytimeTracker and starts periodic updates for all online players.
      Parameters:
      pl - The plugin instance.
    • getBaseMultiplier

      public static double getBaseMultiplier()
    • getWeekendMultiplier

      public static double getWeekendMultiplier()
    • getSocialMultiplier

      public static double getSocialMultiplier()
    • getSocialDistance

      public static double getSocialDistance()
    • computeGlobalSocialMultiplier

      public static double computeGlobalSocialMultiplier()
      Computes the social multiplier as the socialMultiplier times the weighted average of all party sizes, with more weight attributed to larger parties.
    • getTotalMultiplier

      public static double getTotalMultiplier()
      Computes the total multiplier for a player. Includes base, weekend, and social multipliers.
    • isWeekend

      public static boolean isWeekend()
      Checks if it is currently the weekend (Saturday or Sunday) in Eastern Time.
    • resetPlaytime

      public static void resetPlaytime(UUID playerUuid)
      Resets the recorded available seconds for a specific player.

      This method retrieves the PlaytimeData associated with the given player's UUID and, if available, resets their tracked available seconds back to zero. It has no effect if no playtime data is currently stored for the player.

      Parameters:
      playerUuid - The UUID of the player whose available seconds should be reset.
    • setAfk

      public static void setAfk(UUID uuid, boolean isAfk)
      Sets the AFK status for a specific player.

      This method updates the AFK status for a player, marking them as either AFK or not AFK. If the player does not have playtime data yet, a new entry will be created.

      Parameters:
      uuid - The unique identifier of the player.
      isAfk - The new AFK status for the player.
    • getData

      public static PlaytimeData getData(UUID uuid)
      Retrieves the playtime data for a specific player.
      Parameters:
      uuid - The unique identifier of the player.
      Returns:
      The playtime data for the player, or a new PlaytimeData if none exists.
    • getMinutes

      public static double getMinutes(UUID uuid)
      Retrieves the remaining time in minutes for a player.
      Parameters:
      uuid - The player's unique identifier.
      Returns:
      The remaining minutes, or 60 if the player has no tracked data.
    • getSeconds

      public static double getSeconds(UUID uuid)
      Retrieves the remaining time in seconds for a player.
      Parameters:
      uuid - The player's unique identifier.
      Returns:
      The remaining seconds, or 0 if no time is required.
    • getTimeLeft

      public static Duration getTimeLeft(UUID uuid)
      Gets the total remaining time for a player as a Duration.
      Parameters:
      uuid - The player's unique identifier.
      Returns:
      A Duration representing how much time is left.
    • setPlaytime

      public static void setPlaytime(UUID uuid, PlaytimeData data)
      Sets or replaces the current playtime data for a player.
      Parameters:
      uuid - The player's unique identifier.
      data - The playtime data to associate with the player.
    • getPlaytime

      public static double getPlaytime(UUID uuid)
      Gets the total available time in seconds for a player.
      Parameters:
      uuid - The player's unique identifier.
      Returns:
      Total available time in seconds, or 0 if not found.
    • loadFromDatabase

      public static void loadFromDatabase(Connection conn)
      Loads player playtime data from the SQLite database into memory.
      Parameters:
      conn - A valid database connection.
    • saveToDatabase

      public static void saveToDatabase(Connection conn)
      Saves the in-memory playtime data to the SQLite database.

      Uses upsert logic: if the player's UUID already exists, the record is updated; otherwise, a new row is inserted.

      Parameters:
      conn - A valid database connection.