Package dev.itsharshxd.zentrix.api.game
Interface GameService
public interface GameService
Service for game management and query operations.
This service provides read-only access to game state and information. Use the events system to react to game state changes.
Example Usage
GameService gameService = ZentrixProvider.get().getGameService();
// Get all active games
Collection<ZentrixGame> games = gameService.getActiveGames();
// Check if player is in a game
if (gameService.isInGame(player)) {
ZentrixGame game = gameService.getPlayerGame(player).orElseThrow();
// Do something with the game
}
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionintGets the total number of active games.@NotNull Collection<ZentrixGame> Gets all currently active games.@NotNull Collection<String> Gets all available arena names.@NotNull Optional<ZentrixGame> Gets a game by its unique identifier.@NotNull Collection<ZentrixGame> Gets all games in a specific state.@NotNull Collection<ZentrixGame> getGamesForArena(@NotNull String arenaName) Gets all games running on a specific arena.@NotNull Optional<ZentrixGame> getPlayerGame(@NotNull UUID playerId) Gets the game a player is currently in by UUID.@NotNull Optional<ZentrixGame> getPlayerGame(@NotNull org.bukkit.entity.Player player) Gets the game a player is currently in.intGets the total number of players across all active games.booleanChecks if a player is currently in any game by UUID.booleanisInGame(@NotNull org.bukkit.entity.Player player) Checks if a player is currently in any game.booleanChecks if a player is actively playing (alive) in a game by UUID.booleanisPlaying(@NotNull org.bukkit.entity.Player player) Checks if a player is actively playing (alive) in a game.booleanisSpectating(@NotNull UUID playerId) Checks if a player is spectating a game by UUID.booleanisSpectating(@NotNull org.bukkit.entity.Player player) Checks if a player is spectating a game.
-
Method Details
-
getActiveGames
Gets all currently active games.Active games include games in any state: WAITING, STARTING, PLAYING, ENDING, or RESTARTING.
- Returns:
- An unmodifiable collection of all active games (never null, may be empty)
-
getGame
Gets a game by its unique identifier.- Parameters:
gameId- The game's unique ID- Returns:
- Optional containing the game, or empty if not found
-
getPlayerGame
@NotNull @NotNull Optional<ZentrixGame> getPlayerGame(@NotNull @NotNull org.bukkit.entity.Player player) Gets the game a player is currently in.This includes both active players and spectators.
- Parameters:
player- The player to check- Returns:
- Optional containing the game, or empty if player is not in any game
-
getPlayerGame
Gets the game a player is currently in by UUID.This includes both active players and spectators.
- Parameters:
playerId- The player's UUID- Returns:
- Optional containing the game, or empty if player is not in any game
-
isInGame
boolean isInGame(@NotNull @NotNull org.bukkit.entity.Player player) Checks if a player is currently in any game.This returns true for both active players and spectators.
- Parameters:
player- The player to check- Returns:
trueif the player is in a game (playing or spectating)
-
isInGame
Checks if a player is currently in any game by UUID.- Parameters:
playerId- The player's UUID- Returns:
trueif the player is in a game (playing or spectating)
-
isSpectating
boolean isSpectating(@NotNull @NotNull org.bukkit.entity.Player player) Checks if a player is spectating a game.Spectators are players who have been eliminated but are still watching the game, or players who joined as spectators.
- Parameters:
player- The player to check- Returns:
trueif the player is spectating a game
-
isSpectating
Checks if a player is spectating a game by UUID.- Parameters:
playerId- The player's UUID- Returns:
trueif the player is spectating a game
-
isPlaying
boolean isPlaying(@NotNull @NotNull org.bukkit.entity.Player player) Checks if a player is actively playing (alive) in a game.This returns
trueonly for alive players, not spectators.- Parameters:
player- The player to check- Returns:
trueif the player is alive in a game
-
isPlaying
Checks if a player is actively playing (alive) in a game by UUID.- Parameters:
playerId- The player's UUID- Returns:
trueif the player is alive in a game
-
getActiveGameCount
int getActiveGameCount()Gets the total number of active games.- Returns:
- The count of active games
-
getGamesForArena
Gets all games running on a specific arena.Multiple game instances can run on the same arena template.
- Parameters:
arenaName- The arena name- Returns:
- Collection of games for that arena (never null, may be empty)
-
getGamesByState
Gets all games in a specific state.- Parameters:
state- The game state to filter by- Returns:
- Collection of games in that state (never null, may be empty)
-
getTotalPlayerCount
int getTotalPlayerCount()Gets the total number of players across all active games.This includes only alive players, not spectators.
- Returns:
- Total player count across all games
-
getAvailableArenas
Gets all available arena names.- Returns:
- Collection of arena names (never null, may be empty)
-