Class Player

All Implemented Interfaces:
Component<EntityStore>, MetricProvider, Cloneable

public class Player extends LivingEntity implements MetricProvider
  • Field Details

    • METRICS_REGISTRY

      @Nonnull public static final MetricsRegistry<Player> METRICS_REGISTRY
      The metrics affiliated with players
    • PLAYER_CONFIG_DATA

      @Nonnull public static final KeyedCodec<PlayerConfigData> PLAYER_CONFIG_DATA
      The keyed codec for PlayerConfigData instances
    • CODEC

      @Nonnull public static final BuilderCodec<Player> CODEC
      The codec used to parse Player instances
    • DEFAULT_VIEW_RADIUS_CHUNKS

      public static final int DEFAULT_VIEW_RADIUS_CHUNKS
      The default view radius, in chunks, for a player
      See Also:
    • RESPAWN_INVULNERABILITY_TIME_NANOS

      public static final long RESPAWN_INVULNERABILITY_TIME_NANOS
      The amount of time, in nanoseconds, in which a player is invulnerable after re-spawning
    • MAX_TELEPORT_INVULNERABILITY_MILLIS

      public static final long MAX_TELEPORT_INVULNERABILITY_MILLIS
      The maximum time, in milliseconds, in which a player is invulnerable after teleporting
      See Also:
    • executeTriggers

      public boolean executeTriggers
      Determines whether to execute block triggers for this player, upon collision with trigger blocks.
    • executeBlockDamage

      public boolean executeBlockDamage
      Determines whether to execute block damage for this player, upon collision with damaging blocks.
  • Constructor Details

    • Player

      public Player()
      Default Constructor for a Player instance
  • Method Details

    • getComponentType

      @Nonnull public static ComponentType<EntityStore, Player> getComponentType()
      Returns:
      the component type for Player components
    • copyFrom

      public void copyFrom(@Nonnull Player oldPlayerComponent)
      Called to copy the parameters and managers to this player from the old player instance.
      Parameters:
      oldPlayerComponent - The old Player component to copy from.
    • init

      public void init(@Nonnull UUID uuid, @Nonnull PlayerRef playerRef)
      Called to initialize this player instance with the given parameters
      Parameters:
      uuid - The unique ID of the player
      playerRef - The player ref associated with this player
    • setNetworkId

      public void setNetworkId(int id)
      Called to set the network ID for this player
      Parameters:
      id - The specific network ID to set
    • remove

      public boolean remove()
      Description copied from class: Entity
      Called to remove this entity from the world.
      Overrides:
      remove in class Entity
      Returns:
      true if the entity was removed, false if it was already removed.
    • moveTo

      public void moveTo(@Nonnull Ref<EntityStore> ref, double locX, double locY, double locZ, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Overrides:
      moveTo in class LivingEntity
      Parameters:
      ref - The entity reference of this entity.
      locX - The X coordinate to move to.
      locY - The Y coordinate to move to.
      locZ - The Z coordinate to move to.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
    • getPlayerConfigData

      @Nonnull public PlayerConfigData getPlayerConfigData()
      Returns:
      the player configuration data associated with this player
    • markNeedsSave

      public void markNeedsSave()
      Description copied from class: Entity
      Marks the chunk containing this entity as needing to be saved.
      Overrides:
      markNeedsSave in class Entity
    • applyMovementStates

      public static void applyMovementStates(@Nonnull Ref<EntityStore> ref, @Nonnull SavedMovementStates savedMovementStates, @Nonnull MovementStates movementStates, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
    • startClientReadyTimeout

      public void startClientReadyTimeout()
    • handleClientReady

      public void handleClientReady(boolean forced)
    • saveConfig

      @Nonnull public CompletableFuture<Void> saveConfig(@Nonnull World world, @Nonnull Holder<EntityStore> holder, boolean required)
    • getPlayerConnection

      @Deprecated(forRemoval=true) public PacketHandler getPlayerConnection()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use the PlayerRef to fetch this.
      This exists only to ease migration
      Returns:
      the affiliated PacketHandler instance.
    • getWorldMapTracker

      @Nonnull public WorldMapTracker getWorldMapTracker()
      Returns:
      the affiliated WorldMapTracker instance
    • getWindowManager

      @Nonnull public WindowManager getWindowManager()
      Returns:
      the affiliated WindowManager instance
    • getPageManager

      @Nonnull public PageManager getPageManager()
      Returns:
      the affiliated PageManager instance
    • getHudManager

      @Nonnull public HudManager getHudManager()
      Returns:
      the affiliated HudManager instance
    • getHotbarManager

      @Nonnull public HotbarManager getHotbarManager()
      Returns:
      the affiliated HotbarManager instance
    • isFirstSpawn

      public boolean isFirstSpawn()
      Returns:
      true if this is the first spawn of the player, false otherwise.
    • setFirstSpawn

      public void setFirstSpawn(boolean firstSpawn)
      Called to set whether this is the first spawn of the player.
      Parameters:
      firstSpawn - The value to set.
    • resetManagers

      public void resetManagers(@Nonnull Holder<EntityStore> holder)
      Called to reset all the managers affiliated with this player
      Parameters:
      holder - The holder instance of the player
    • notifyPickupItem

      public static void notifyPickupItem(@Nonnull Ref<EntityStore> ref, @Nonnull ItemStack itemStack, @Nullable org.joml.Vector3d position, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to notify the player of an item pick-up, playing expected audio and effects
      Parameters:
      ref - The entity reference of the player entity
      itemStack - The item stack that has been picked up
      position - The position, if applicable
      componentAccessor - The ComponentAccessor for component access
    • isOverrideBlockPlacementRestrictions

      public boolean isOverrideBlockPlacementRestrictions()
      Determines whether block placement restrictions are overridden for this player.
      Returns:
      true if block placement restrictions are overridden, false otherwise.
    • setOverrideBlockPlacementRestrictions

      public void setOverrideBlockPlacementRestrictions(@Nonnull Ref<EntityStore> ref, boolean overrideBlockPlacementRestrictions, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to set whether block placement restrictions are overridden for this player.
      Parameters:
      ref - The entity reference of the player entity.
      overrideBlockPlacementRestrictions - The value to set.
      componentAccessor - The ComponentAccessor for component access.
    • isNoClip

      public boolean isNoClip()
      Determines whether no-clip is enabled for this player.
      Returns:
      true if collision is disabled for this player, false otherwise.
    • setNoClip

      public void setNoClip(@Nonnull Ref<EntityStore> ref, boolean noClip, boolean notify, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Sets whether no-clip (collision disabled in every movement state) is enabled for this player.

      The value is per-session and is not persisted across reconnects.

      Parameters:
      ref - The entity reference of the player entity.
      noClip - The value to set.
      notify - Whether the client should surface a HUD message for this change.
      componentAccessor - The ComponentAccessor for component access.
    • isFlying

      public boolean isFlying(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Determines whether this player is currently flying.
      Parameters:
      ref - The entity reference of the player entity.
      componentAccessor - The ComponentAccessor for component access.
      Returns:
      true if the player is flying, false otherwise.
    • setFlying

      public void setFlying(@Nonnull Ref<EntityStore> ref, boolean flying, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Forces this player into (or out of) the flying state and pushes the change to the client.

      This controls the flying state (MovementStates.flying), not the fly capability. Enabling also grants the MovementSettings.Fly capability (and disabling restores the game-mode default), because the client leaves the flying state as soon as it is not allowed to fly; that capability handling is an internal detail of keeping the state applied.

      Parameters:
      ref - The entity reference of the player entity.
      flying - The value to set.
      componentAccessor - The ComponentAccessor for component access.
    • addLocationChange

      public static void addLocationChange(@Nonnull Ref<EntityStore> ref, double deltaX, double deltaY, double deltaZ, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
    • configTriggerBlockProcessing

      public void configTriggerBlockProcessing(boolean triggers, boolean blockDamage, @Nonnull CollisionResultComponent collisionResultComponent)
      Called to configure how trigger blocks are processed for this player.
      Parameters:
      triggers - Whether to execute trigger blocks.
      blockDamage - Whether to execute block damage.
      collisionResultComponent - The CollisionResultComponent component of the player entity.
    • resetVelocity

      public void resetVelocity(@Nonnull Velocity velocity)
    • processVelocitySample

      public void processVelocitySample(double dt, @Nonnull org.joml.Vector3d displacement, @Nonnull Velocity velocity)
      Updates velocity from the player's movement.
      Parameters:
      dt - The elapsed seconds since the previous sample.
      displacement - The movement since the previous sample, not an absolute position.
      velocity - The velocity component to update.
    • getRespawnPosition

      @Nonnull public static CompletableFuture<Transform> getRespawnPosition(@Nonnull Ref<EntityStore> ref, @Nonnull String worldName, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to return the respawn position for the given player
      Parameters:
      ref - The entity reference of the player entity
      worldName - The associated world name that we are fetching the respawn position in
      componentAccessor - The ComponentAccessor instance for component access
      Returns:
      the respawn position as a Transform instance
    • hasSpawnProtection

      public boolean hasSpawnProtection()
    • isWaitingForClientReady

      public boolean isWaitingForClientReady()
      Returns:
      true if we are waiting for the client to be ready, false otherwise
    • isHiddenFromLivingEntity

      public boolean isHiddenFromLivingEntity(@Nonnull Ref<EntityStore> ref, @Nonnull Ref<EntityStore> targetRef, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Description copied from class: Entity
      Determines whether this entity is hidden from the given target entity
      Overrides:
      isHiddenFromLivingEntity in class Entity
      Parameters:
      ref - The entity reference of this entity
      targetRef - The entity reference of the target entity
      componentAccessor - The ComponentAccessor for component access
      Returns:
      true if they are hidden from the target entity, false otherwise
    • setClientViewRadius

      public void setClientViewRadius(int clientViewRadius)
      Called to set the current client view radius of this player
      Parameters:
      clientViewRadius - The client view radius to set
    • getClientViewRadius

      public int getClientViewRadius()
      Returns:
      the current client view radius of the player
    • getViewRadius

      public int getViewRadius()
      Returns:
      the client view radius in chunks, clamped to [0, server max].
    • toMetricResults

      @Nonnull public MetricResults toMetricResults()
      Specified by:
      toMetricResults in interface MetricProvider
    • setLastSpawnTimeNanos

      public void setLastSpawnTimeNanos(long lastSpawnTimeNanos)
      Called to set the last spawn time of this player
      Parameters:
      lastSpawnTimeNanos - The given last spawn time to set
    • getSinceLastSpawnNanos

      public long getSinceLastSpawnNanos()
      Returns:
      the time since the last spawn of this player, in nanoseconds.
    • getPlayerRef

      @Deprecated(forRemoval=true) public PlayerRef getPlayerRef()
      Deprecated, for removal: This API element is subject to removal in a future version.
      This field only exists to simplify migrating this class away from it. Any new uses should fetch the PlayerRef component manually.
      Returns:
      the affiliated PlayerRef instance.
    • getMountEntityId

      public int getMountEntityId()
      Returns:
      the entity ID of the mount entity.
    • setMountEntityId

      public void setMountEntityId(int mountEntityId)
      Called to set the entity ID of the mount entity.
      Parameters:
      mountEntityId - The ID of the mount entity to set.
    • getGameMode

      public GameMode getGameMode()
      Returns:
      the current game mode of the player.
    • setGameMode

      public static void setGameMode(@Nonnull Ref<EntityStore> playerRef, @Nonnull GameMode gameMode, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Sets the current game-mode of the given entity.
      Parameters:
      playerRef - The entity reference of the player entity we are setting the game-mode for.
      gameMode - The GameMode that we are switching to.
      componentAccessor - The ComponentAccessor for component access.
    • initGameMode

      public static void initGameMode(@Nonnull Ref<EntityStore> playerRef, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called during the initialization stage of the players creation to initialize their game-mode and permissions.
      Parameters:
      playerRef - The entity reference of the player entity.
      componentAccessor - The ComponentAccessor for component access.
    • giveItem

      @Nonnull public static ItemStackTransaction giveItem(@Nonnull ItemStack stack, @Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Entity
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Entity
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class LivingEntity