Interface ProfileService
public interface ProfileService
Service for accessing player profile statistics.
This service provides access to persistent player statistics such as wins, kills, deaths, and other lifetime achievements.
Example Usage
ProfileService profileService = ZentrixProvider.get().getProfileService();
// Get player stats asynchronously
profileService.getStats(player.getUniqueId()).thenAccept(stats -> {
int wins = stats.getWins();
int kills = stats.getKills();
double kd = stats.getKDRatio();
player.sendMessage("Wins: " + wins + ", K/D: " + kd);
});
// Or get cached stats synchronously
PlayerStats cached = profileService.getCachedStats(player.getUniqueId());
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescription@NotNull StringformatSurvivalTime(double seconds) Formats a survival time in seconds to a human-readable format.@NotNull PlayerStatsgetCachedStats(@NotNull UUID playerId) Gets a player's cached statistics for immediate access.@NotNull PlayerStatsgetCachedStats(@NotNull org.bukkit.entity.Player player) Gets a player's cached statistics for immediate access.intGets the total number of deaths for a player (cached).doublegetKDRatio(@NotNull UUID playerId) Gets the K/D ratio for a player (cached).intGets the total number of kills for a player (cached).intgetMatchesPlayed(@NotNull UUID playerId) Gets the total matches played for a player (cached).@NotNull CompletableFuture<PlayerStats> Gets a player's statistics asynchronously.@NotNull CompletableFuture<PlayerStats> getStats(@NotNull org.bukkit.entity.Player player) Gets a player's statistics asynchronously.doublegetWinRate(@NotNull UUID playerId) Gets the win rate percentage for a player (cached).intGets the total number of wins for a player (cached).booleanChecks if a player's stats are currently cached.@NotNull CompletableFuture<PlayerStats> Preloads a player's statistics into the cache.@NotNull CompletableFuture<PlayerStats> loadStats(@NotNull org.bukkit.entity.Player player) Preloads a player's statistics into the cache.
-
Method Details
-
getStats
Gets a player's statistics asynchronously.This method fetches stats from storage if not cached. For synchronous access, use
getCachedStats(UUID).- Parameters:
playerId- The player's UUID- Returns:
- CompletableFuture containing the player's stats
-
getStats
@NotNull @NotNull CompletableFuture<PlayerStats> getStats(@NotNull @NotNull org.bukkit.entity.Player player) Gets a player's statistics asynchronously.- Parameters:
player- The player- Returns:
- CompletableFuture containing the player's stats
-
getCachedStats
Gets a player's cached statistics for immediate access.Returns the cached stats if available, or empty stats if not yet loaded. Use this for scoreboards and GUIs where async operations are not desirable.
- Parameters:
playerId- The player's UUID- Returns:
- The cached stats (may be empty if not loaded)
-
getCachedStats
Gets a player's cached statistics for immediate access.- Parameters:
player- The player- Returns:
- The cached stats (may be empty if not loaded)
-
loadStats
Preloads a player's statistics into the cache.Call this when a player joins the server to ensure their stats are available for quick access.
- Parameters:
playerId- The player's UUID- Returns:
- CompletableFuture that completes when loading is done
-
loadStats
@NotNull @NotNull CompletableFuture<PlayerStats> loadStats(@NotNull @NotNull org.bukkit.entity.Player player) Preloads a player's statistics into the cache.- Parameters:
player- The player- Returns:
- CompletableFuture that completes when loading is done
-
isCached
Checks if a player's stats are currently cached.- Parameters:
playerId- The player's UUID- Returns:
trueif stats are in the cache
-
formatSurvivalTime
Formats a survival time in seconds to a human-readable format.Examples:
- 45 seconds → "45s"
- 150 seconds → "2m 30s"
- 3700 seconds → "1h 1m"
- Parameters:
seconds- The time in seconds- Returns:
- Formatted time string (never null)
-
getWins
Gets the total number of wins for a player (cached).Convenience method for quick access to win count.
- Parameters:
playerId- The player's UUID- Returns:
- The win count, or 0 if not cached
-
getKills
Gets the total number of kills for a player (cached).- Parameters:
playerId- The player's UUID- Returns:
- The kill count, or 0 if not cached
-
getDeaths
Gets the total number of deaths for a player (cached).- Parameters:
playerId- The player's UUID- Returns:
- The death count, or 0 if not cached
-
getMatchesPlayed
Gets the total matches played for a player (cached).- Parameters:
playerId- The player's UUID- Returns:
- The match count, or 0 if not cached
-
getKDRatio
Gets the K/D ratio for a player (cached).- Parameters:
playerId- The player's UUID- Returns:
- The K/D ratio, or 0 if not cached
-
getWinRate
Gets the win rate percentage for a player (cached).- Parameters:
playerId- The player's UUID- Returns:
- The win rate (0-100), or 0 if not cached
-