Class PlaytimeTracker
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic double
Computes the social multiplier as the socialMultiplier times the weighted average of all party sizes, with more weight attributed to larger parties.static double
static PlaytimeData
Retrieves the playtime data for a specific player.static double
getMinutes
(UUID uuid) Retrieves the remaining time in minutes for a player.static double
getPlaytime
(UUID uuid) Gets the total available time in seconds for a player.static double
getSeconds
(UUID uuid) Retrieves the remaining time in seconds for a player.static double
static double
static Duration
getTimeLeft
(UUID uuid) Gets the total remaining time for a player as aDuration
.static double
Computes the total multiplier for a player.static double
static void
init
(org.bukkit.plugin.java.JavaPlugin pl) Initializes the PlaytimeTracker and starts periodic updates for all online players.static boolean
Checks if it is currently the weekend (Saturday or Sunday) in Eastern Time.static void
loadFromDatabase
(Connection conn) Loads player playtime data from the SQLite database into memory.static void
resetPlaytime
(UUID playerUuid) Resets the recorded available seconds for a specific player.static void
saveToDatabase
(Connection conn) Saves the in-memory playtime data to the SQLite database.static void
Sets the AFK status for a specific player.static void
setPlaytime
(UUID uuid, PlaytimeData data) Sets or replaces the current playtime data for a player.
-
Field Details
-
playtimeMap
-
-
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
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
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
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
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
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
Gets the total remaining time for a player as aDuration
.- Parameters:
uuid
- The player's unique identifier.- Returns:
- A Duration representing how much time is left.
-
setPlaytime
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
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
Loads player playtime data from the SQLite database into memory.- Parameters:
conn
- A valid database connection.
-
saveToDatabase
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.
-