Interface GamePlayer<P>

Type Parameters:
P - the player type (platform-specific)

public interface GamePlayer<P>
Represents a player participating in a game session.

GamePlayer wraps a platform-specific player object and provides game-specific state management, including player status (alive/spectator/eliminated) and custom data storage for game modules.

  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears all custom data for this player.
    void
    eliminate(String reason)
    Eliminates this player from the game with a reason.
    <T> T
    getData(String key, Class<T> type)
    Retrieves custom game-specific data for this player.
    Gets the underlying platform-specific player object.
    Gets the current state of this player in the game.
    boolean
    Checks if custom data exists for a given key.
    boolean
    Checks if the player is alive and actively playing.
    boolean
    Checks if the player has been eliminated from the game.
    boolean
    Checks if the player is spectating the game.
    void
    Converts this player into a spectator.
    void
    setData(String key, Object value)
    Stores custom game-specific data for this player.
    void
    Sets the player's state.
  • Method Details

    • getPlayer

      P getPlayer()
      Gets the underlying platform-specific player object.
      Returns:
      the platform player
    • getState

      PlayerState getState()
      Gets the current state of this player in the game.
      Returns:
      the player's state (PLAYING, SPECTATOR, or ELIMINATED)
    • isAlive

      boolean isAlive()
      Checks if the player is alive and actively playing.
      Returns:
      true if the player is in PLAYING state
    • isSpectator

      boolean isSpectator()
      Checks if the player is spectating the game.
      Returns:
      true if the player is in SPECTATOR state
    • isEliminated

      boolean isEliminated()
      Checks if the player has been eliminated from the game.
      Returns:
      true if the player is in ELIMINATED state
    • setState

      void setState(PlayerState state)
      Sets the player's state.
      Parameters:
      state - the new player state
    • eliminate

      void eliminate(String reason)
      Eliminates this player from the game with a reason.

      This sets the player state to ELIMINATED and fires a PlayerEliminateEvent.

      Parameters:
      reason - the reason for elimination (for events/logging)
    • makeSpectator

      void makeSpectator()
      Converts this player into a spectator.

      This sets the player state to SPECTATOR.

    • setData

      void setData(String key, Object value)
      Stores custom game-specific data for this player.

      Game modules can use this to store temporary player data that persists for the duration of the game session.

      Parameters:
      key - the data key
      value - the data value to store
    • getData

      <T> T getData(String key, Class<T> type)
      Retrieves custom game-specific data for this player.
      Type Parameters:
      T - the expected type
      Parameters:
      key - the data key
      type - the class of the expected type
      Returns:
      the stored value, or null if not found
    • hasData

      boolean hasData(String key)
      Checks if custom data exists for a given key.
      Parameters:
      key - the data key to check
      Returns:
      true if data exists for this key, false otherwise
    • clearData

      void clearData()
      Clears all custom data for this player.