Interface PlayerService
public interface PlayerService
Provides player queries for Zentrix games.
Use it to inspect player state, statistics, and team membership.
Example
PlayerService playerService = ZentrixProvider.get().getPlayerService();
// Get the player's game representation
Optional<ZentrixPlayer> zentrixPlayer = playerService.getPlayer(player);
zentrixPlayer.ifPresent(zp -> {
int kills = zp.getGameKills();
boolean alive = zp.isAlive();
});
- Since:
- 1.0.0
-
Method Summary
Modifier and TypeMethodDescriptionbooleanareInSameGame(@NotNull UUID playerId1, @NotNull UUID playerId2) Checks if two players are in the same game by UUID.booleanareInSameGame(@NotNull org.bukkit.entity.Player player1, @NotNull org.bukkit.entity.Player player2) Checks if two players are in the same game.default booleanclearSpectatorCameraTarget(@NotNull org.bukkit.entity.Player spectator) Returns a spectator from another player's point of view to free flight, as sneaking would.@NotNull Collection<ZentrixPlayer> Gets all players currently in any game (alive only).@NotNull Collection<ZentrixPlayer> Gets all spectators currently watching any game.intgetGameKills(@NotNull UUID playerId) Gets the number of kills a player has in their current game by UUID.intgetGameKills(@NotNull org.bukkit.entity.Player player) Gets the number of kills a player has in their current game.default @NotNull ParticipantStategetParticipantState(@NotNull UUID playerId) Where a player stands, online or not.@NotNull Optional<ZentrixPlayer> getPlayer(@NotNull ZentrixGame game, @NotNull UUID playerId) Gets a player within a specific game.@NotNull Optional<ZentrixPlayer> Gets a player's Zentrix representation by UUID if they are in a game.@NotNull Optional<ZentrixPlayer> getPlayer(@NotNull org.bukkit.entity.Player player) Gets a player's Zentrix representation if they are in a game.@NotNull Collection<ZentrixPlayer> getPlayersInGame(@NotNull ZentrixGame game) Gets all players in a specific game.default @NotNull Optional<org.bukkit.entity.Player> getSpectatorCameraTarget(@NotNull org.bukkit.entity.Player spectator) The living player whose point of view a spectator currently has, if any.@NotNull Collection<ZentrixPlayer> getSpectatorsInGame(@NotNull ZentrixGame game) Gets all spectators in a specific game.booleanChecks if a player is currently alive in any game by UUID.booleanisAlive(@NotNull org.bukkit.entity.Player player) Checks if a player is currently alive in any game.booleanisSpectating(@NotNull UUID playerId) Checks if a player is spectating any game by UUID.booleanisSpectating(@NotNull org.bukkit.entity.Player player) Checks if a player is spectating any game.default booleansetSpectatorCameraTarget(@NotNull org.bukkit.entity.Player spectator, @NotNull org.bukkit.entity.Player target) Puts a spectator into a living player's point of view, as clicking that player would.
-
Method Details
-
getPlayer
@NotNull @NotNull Optional<ZentrixPlayer> getPlayer(@NotNull @NotNull org.bukkit.entity.Player player) Gets a player's Zentrix representation if they are in a game.- Parameters:
player- The Bukkit player- Returns:
- Optional containing the ZentrixPlayer, or empty if not in a game
-
getPlayer
Gets a player's Zentrix representation by UUID if they are in a game.- Parameters:
playerId- The player's UUID- Returns:
- Optional containing the ZentrixPlayer, or empty if not in a game
-
getPlayer
@NotNull @NotNull Optional<ZentrixPlayer> getPlayer(@NotNull @NotNull ZentrixGame game, @NotNull @NotNull UUID playerId) Gets a player within a specific game.- Parameters:
game- The game to search inplayerId- The player's UUID- Returns:
- Optional containing the ZentrixPlayer, or empty if not found
-
getAllPlayers
Gets all players currently in any game (alive only).- Returns:
- An unmodifiable collection of all players in games (never null)
-
getAllSpectators
Gets all spectators currently watching any game.- Returns:
- An unmodifiable collection of all spectators (never null)
-
isAlive
boolean isAlive(@NotNull @NotNull org.bukkit.entity.Player player) Checks if a player is currently alive in any game.- Parameters:
player- The player to check- Returns:
trueif the player is alive in a game
-
isAlive
Checks if a player is currently alive in any game by UUID.- Parameters:
playerId- The player's UUID- Returns:
trueif the player is alive in a game
-
isSpectating
boolean isSpectating(@NotNull @NotNull org.bukkit.entity.Player player) Checks if a player is spectating any game.- Parameters:
player- The player to check- Returns:
trueif the player is spectating a game
-
isSpectating
Checks if a player is spectating any game by UUID.- Parameters:
playerId- The player's UUID- Returns:
trueif the player is spectating a game
-
getGameKills
int getGameKills(@NotNull @NotNull org.bukkit.entity.Player player) Gets the number of kills a player has in their current game.Returns 0 if the player is not in a game.
- Parameters:
player- The player- Returns:
- The kill count, or 0 if not in a game
-
getGameKills
Gets the number of kills a player has in their current game by UUID.- Parameters:
playerId- The player's UUID- Returns:
- The kill count, or 0 if not in a game
-
getPlayersInGame
Gets all players in a specific game.- Parameters:
game- The game- Returns:
- An unmodifiable collection of players (never null)
-
getSpectatorsInGame
Gets all spectators in a specific game.- Parameters:
game- The game- Returns:
- An unmodifiable collection of spectators (never null)
-
areInSameGame
boolean areInSameGame(@NotNull @NotNull org.bukkit.entity.Player player1, @NotNull @NotNull org.bukkit.entity.Player player2) Checks if two players are in the same game.- Parameters:
player1- First playerplayer2- Second player- Returns:
trueif both players are in the same game
-
areInSameGame
Checks if two players are in the same game by UUID.- Parameters:
playerId1- First player's UUIDplayerId2- Second player's UUID- Returns:
trueif both players are in the same game
-
getParticipantState
Where a player stands, online or not.Unlike
getPlayer(UUID), this also answers for a player who left a running match and can still return to it (ParticipantState.DISCONNECTED_RETURNABLE), and tells an eliminated participant apart from a spectator who never played.- Parameters:
playerId- The player's UUID- Returns:
- The player's state;
ParticipantState.NOT_PARTICIPATINGoutside any match - Since:
- 1.8.0
-
getSpectatorCameraTarget
@NotNull default @NotNull Optional<org.bukkit.entity.Player> getSpectatorCameraTarget(@NotNull @NotNull org.bukkit.entity.Player spectator) The living player whose point of view a spectator currently has, if any.- Parameters:
spectator- The spectator- Returns:
- The viewed player; empty in free flight or for a player who is not spectating
- Since:
- 1.8.0
-
setSpectatorCameraTarget
default boolean setSpectatorCameraTarget(@NotNull @NotNull org.bukkit.entity.Player spectator, @NotNull @NotNull org.bukkit.entity.Player target) Puts a spectator into a living player's point of view, as clicking that player would.Only living players of the match the spectator watches can be viewed. A
SpectatorCameraEventlistener may still refuse. Main thread only.- Parameters:
spectator- The spectatortarget- The living player to view- Returns:
truewhen the spectator now views the target- Throws:
IllegalStateException- off the main thread- Since:
- 1.8.0
-
clearSpectatorCameraTarget
default boolean clearSpectatorCameraTarget(@NotNull @NotNull org.bukkit.entity.Player spectator) Returns a spectator from another player's point of view to free flight, as sneaking would. Main thread only.- Parameters:
spectator- The spectator- Returns:
truewhen they had been viewing a player- Throws:
IllegalStateException- off the main thread- Since:
- 1.8.0
-