Class PlaytimeService
java.lang.Object
net.flectone.pulse.service.PlaytimeService
Service for managing player playtime tracking and statistics.
Handles initialization, session updates, and retrieval of playtime data.
Playtime tracking can be enabled or disabled via configuration.
- Since:
- 1.10.1
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionPlaytimeService(FileFacade fileFacade, PlaytimeRepository playtimeRepository, FPlayerService fPlayerService, PlatformPlayerAdapter platformPlayerAdapter) -
Method Summary
Modifier and TypeMethodDescriptiongetAllPlayTimes(int limit, int offset) Gets a paginated list of all playtime records from the database.@Nullable PlayTimegetPlayTime(FPlayer fPlayer) Gets the playtime statistics for a specific player.intGets the total count of all playtime records in the database.voidInitializes playtime tracking by migrating legacy data from platform adapters.voidinvalidate(@NonNull UUID uuid) Invalidates cached playtime data for a specific player.voidsaveAfkSession(FPlayer fPlayer, boolean afk) Saves a player's AFK session status change and invalidates cache.voidupdateJoinSession(@NonNull FPlayer fPlayer) Updates a player's join session when they connect to the server.voidupdateLastSession(@NonNull FPlayer fPlayer) Updates a player's last seen timestamp when they disconnect from the server.
-
Constructor Details
-
PlaytimeService
@Inject public PlaytimeService(FileFacade fileFacade, PlaytimeRepository playtimeRepository, FPlayerService fPlayerService, PlatformPlayerAdapter platformPlayerAdapter)
-
-
Method Details
-
initialize
public void initialize()Initializes playtime tracking by migrating legacy data from platform adapters. Only runs if playtime tracking is enabled and no existing records are found. This serves as a migration for versions prior to 1.9.0 where playtime data was not stored in the database. -
invalidate
Invalidates cached playtime data for a specific player. Only executes if playtime tracking is enabled.- Parameters:
uuid- the UUID of the player whose playtime cache should be invalidated
-
saveAfkSession
Saves a player's AFK session status change and invalidates cache. Only executes if playtime tracking is enabled.- Parameters:
fPlayer- the player whose AFK status is being updatedafk- true if the player is going AFK, false if returning from AFK
-
updateJoinSession
Updates a player's join session when they connect to the server. Saves the session and invalidates cached playtime data. Only executes if playtime tracking is enabled.- Parameters:
fPlayer- the player whose join session is being updated
-
updateLastSession
Updates a player's last seen timestamp when they disconnect from the server. Saves the quit session and invalidates cached playtime data. Only executes if playtime tracking is enabled.- Parameters:
fPlayer- the player whose last seen time is being updated
-
getPlayTime
Gets the playtime statistics for a specific player. Returns null if playtime tracking is disabled.- Parameters:
fPlayer- the player to get playtime statistics for- Returns:
- the player's playtime statistics, or null if tracking is disabled or not found
-
getPlayTimesCount
public int getPlayTimesCount()Gets the total count of all playtime records in the database. Returns -1 if playtime tracking is disabled.- Returns:
- the total number of playtime records, or -1 if tracking is disabled
-
getAllPlayTimes
Gets a paginated list of all playtime records from the database. Returns an empty list if playtime tracking is disabled.- Parameters:
limit- the maximum number of records to retrieveoffset- the number of records to skip before returning results- Returns:
- list of playtime records within the specified range, or empty list if tracking is disabled
-