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 Type
    Method
    Description
    boolean
    areInSameGame(@NotNull UUID playerId1, @NotNull UUID playerId2)
    Checks if two players are in the same game by UUID.
    boolean
    areInSameGame(@NotNull org.bukkit.entity.Player player1, @NotNull org.bukkit.entity.Player player2)
    Checks if two players are in the same game.
    default boolean
    clearSpectatorCameraTarget(@NotNull org.bukkit.entity.Player spectator)
    Returns a spectator from another player's point of view to free flight, as sneaking would.
    Gets all players currently in any game (alive only).
    Gets all spectators currently watching any game.
    int
    getGameKills(@NotNull UUID playerId)
    Gets the number of kills a player has in their current game by UUID.
    int
    getGameKills(@NotNull org.bukkit.entity.Player player)
    Gets the number of kills a player has in their current game.
    default @NotNull ParticipantState
    getParticipantState(@NotNull UUID playerId)
    Where a player stands, online or not.
    getPlayer(@NotNull ZentrixGame game, @NotNull UUID playerId)
    Gets a player within a specific game.
    getPlayer(@NotNull UUID playerId)
    Gets a player's Zentrix representation by UUID if they are in a game.
    getPlayer(@NotNull org.bukkit.entity.Player player)
    Gets a player's Zentrix representation if they are in a 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.
    Gets all spectators in a specific game.
    boolean
    isAlive(@NotNull UUID playerId)
    Checks if a player is currently alive in any game by UUID.
    boolean
    isAlive(@NotNull org.bukkit.entity.Player player)
    Checks if a player is currently alive in any game.
    boolean
    isSpectating(@NotNull UUID playerId)
    Checks if a player is spectating any game by UUID.
    boolean
    isSpectating(@NotNull org.bukkit.entity.Player player)
    Checks if a player is spectating any game.
    default boolean
    setSpectatorCameraTarget(@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

      @NotNull @NotNull Optional<ZentrixPlayer> getPlayer(@NotNull @NotNull UUID playerId)
      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 in
      playerId - The player's UUID
      Returns:
      Optional containing the ZentrixPlayer, or empty if not found
    • getAllPlayers

      @NotNull @NotNull Collection<ZentrixPlayer> getAllPlayers()
      Gets all players currently in any game (alive only).
      Returns:
      An unmodifiable collection of all players in games (never null)
    • getAllSpectators

      @NotNull @NotNull Collection<ZentrixPlayer> 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:
      true if the player is alive in a game
    • isAlive

      boolean isAlive(@NotNull @NotNull UUID playerId)
      Checks if a player is currently alive in any game by UUID.
      Parameters:
      playerId - The player's UUID
      Returns:
      true if 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:
      true if the player is spectating a game
    • isSpectating

      boolean isSpectating(@NotNull @NotNull UUID playerId)
      Checks if a player is spectating any game by UUID.
      Parameters:
      playerId - The player's UUID
      Returns:
      true if 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

      int getGameKills(@NotNull @NotNull UUID playerId)
      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

      @NotNull @NotNull Collection<ZentrixPlayer> getPlayersInGame(@NotNull @NotNull ZentrixGame game)
      Gets all players in a specific game.
      Parameters:
      game - The game
      Returns:
      An unmodifiable collection of players (never null)
    • getSpectatorsInGame

      @NotNull @NotNull Collection<ZentrixPlayer> getSpectatorsInGame(@NotNull @NotNull ZentrixGame game)
      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 player
      player2 - Second player
      Returns:
      true if both players are in the same game
    • areInSameGame

      boolean areInSameGame(@NotNull @NotNull UUID playerId1, @NotNull @NotNull UUID playerId2)
      Checks if two players are in the same game by UUID.
      Parameters:
      playerId1 - First player's UUID
      playerId2 - Second player's UUID
      Returns:
      true if both players are in the same game
    • getParticipantState

      @NotNull default @NotNull ParticipantState getParticipantState(@NotNull @NotNull UUID playerId)
      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_PARTICIPATING outside 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 SpectatorCameraEvent listener may still refuse. Main thread only.

      Parameters:
      spectator - The spectator
      target - The living player to view
      Returns:
      true when 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:
      true when they had been viewing a player
      Throws:
      IllegalStateException - off the main thread
      Since:
      1.8.0