Class Player

All Implemented Interfaces:
Audience, Identified, Pointered, Sound.Emitter, HoverEventSource<HoverEvent.ShowEntity>, Localizable, CommandSender, EventHandler<EntityEvent>, EquipmentHandler, PermissionHandler, Snapshotable, Taggable, TagReadable, TagWritable, Tickable, Schedulable, NamedAndIdentified, Viewable
Direct Known Subclasses:
FakePlayer

Those are the major actors of the server, they are not necessary backed by a PlayerSocketConnection as shown by FakePlayer.

You can easily create your own implementation of this and use it with ConnectionManager.setPlayerProvider(PlayerProvider).

  • Field Details

  • Constructor Details

    • Player

      public Player(@NotNull @NotNull UUID uuid, @NotNull @NotNull String username, @NotNull @NotNull PlayerConnection playerConnection)
  • Method Details

    • UNSAFE_init

      public CompletableFuture<Void> UNSAFE_init(@NotNull @NotNull Instance spawnInstance)
      Used when the player is created. Init the player and spawn him.

      WARNING: executed in the main update thread UNSAFE: Only meant to be used when a socket player connects through the server.

      Parameters:
      spawnInstance - the player spawn instance (defined in PlayerLoginEvent)
    • playerConnectionInit

      protected void playerConnectionInit()
      Used to initialize the player connection
    • update

      public void update(long time)
      Description copied from class: Entity
      Called each tick.
      Overrides:
      update in class LivingEntity
      Parameters:
      time - time of the update in milliseconds
    • kill

      public void kill()
      Description copied from class: LivingEntity
      Kills the entity, trigger the EntityDeathEvent event.
      Overrides:
      kill in class LivingEntity
    • respawn

      public void respawn()
      Respawns the player by sending a RespawnPacket to the player and teleporting him to getRespawnPoint(). It also resets fire and health.
    • refreshCommands

      public void refreshCommands()
      Refreshes the command list for this player. This checks the CommandConditions again, and any changes will be visible to the player.
    • isOnGround

      public boolean isOnGround()
      Overrides:
      isOnGround in class Entity
    • remove

      public void remove()
      Description copied from class: Entity
      Removes the entity from the server immediately.

      WARNING: this does not trigger EntityDeathEvent.

      Overrides:
      remove in class Entity
    • updateOldViewer

      public void updateOldViewer(@NotNull @NotNull Player player)
      Description copied from class: Entity
      Called when a viewer must be destroyed. Method can be subject to deadlocking if the target's viewers are also accessed.
      Overrides:
      updateOldViewer in class Entity
      Parameters:
      player - the player to send the packets to
    • sendPacketToViewersAndSelf

      public void sendPacketToViewersAndSelf(@NotNull @NotNull SendablePacket packet)
      Description copied from interface: Viewable
      Sends a packet to all viewers and the viewable element if it is a player.

      If 'this' isn't a player, then only Viewable.sendPacketToViewers(SendablePacket) is called.

      Specified by:
      sendPacketToViewersAndSelf in interface Viewable
      Parameters:
      packet - the packet to send
    • setInstance

      public CompletableFuture<Void> setInstance(@NotNull @NotNull Instance instance, @NotNull @NotNull Pos spawnPosition)
      Changes the player instance and load surrounding chunks if needed.

      Be aware that because chunk operations are expensive, it is possible for this method to be non-blocking when retrieving chunks is required.

      Overrides:
      setInstance in class Entity
      Parameters:
      instance - the new player instance
      spawnPosition - the new position of the player
      Returns:
      a future called once the player instance changed
    • setInstance

      public CompletableFuture<Void> setInstance(@NotNull @NotNull Instance instance)
      Changes the player instance without changing its position (defaulted to getRespawnPoint() if the player is not in any instance).
      Overrides:
      setInstance in class Entity
      Parameters:
      instance - the new player instance
      Returns:
      a CompletableFuture called once the entity's instance has been set, this is due to chunks needing to load for players
      See Also:
    • sendPluginMessage

      public void sendPluginMessage(@NotNull @NotNull String channel, byte @NotNull [] data)
      Sends a plugin message to the player.
      Parameters:
      channel - the message channel
      data - the message data
    • sendPluginMessage

      public void sendPluginMessage(@NotNull @NotNull String channel, @NotNull @NotNull String message)
      Sends a plugin message to the player.

      Message encoded to UTF-8.

      Parameters:
      channel - the message channel
      message - the message
    • sendMessage

      public void sendMessage(@NotNull @NotNull Identity source, @NotNull @NotNull Component message, @NotNull @NotNull MessageType type)
      Specified by:
      sendMessage in interface Audience
    • playSound

      public void playSound(@NotNull @NotNull Sound sound)
      Specified by:
      playSound in interface Audience
    • playSound

      public void playSound(@NotNull @NotNull Sound sound, double x, double y, double z)
      Specified by:
      playSound in interface Audience
    • playSound

      public void playSound(@NotNull @NotNull Sound sound, @NotNull Sound.Emitter emitter)
      Specified by:
      playSound in interface Audience
    • stopSound

      public void stopSound(@NotNull @NotNull SoundStop stop)
      Specified by:
      stopSound in interface Audience
    • playEffect

      public void playEffect(@NotNull @NotNull Effects effect, int x, int y, int z, int data, boolean disableRelativeVolume)
      Plays a given effect at the given position for this player.
      Parameters:
      effect - the effect to play
      x - x position of the effect
      y - y position of the effect
      z - z position of the effect
      data - data for the effect
      disableRelativeVolume - disable volume scaling based on distance
    • sendPlayerListHeaderAndFooter

      public void sendPlayerListHeaderAndFooter(@NotNull @NotNull Component header, @NotNull @NotNull Component footer)
      Specified by:
      sendPlayerListHeaderAndFooter in interface Audience
    • sendTitlePart

      public <T> void sendTitlePart(@NotNull @NotNull TitlePart<T> part, @NotNull T value)
      Specified by:
      sendTitlePart in interface Audience
    • sendActionBar

      public void sendActionBar(@NotNull @NotNull Component message)
      Specified by:
      sendActionBar in interface Audience
    • resetTitle

      public void resetTitle()
      Specified by:
      resetTitle in interface Audience
    • clearTitle

      public void clearTitle()
      Specified by:
      clearTitle in interface Audience
    • showBossBar

      public void showBossBar(@NotNull @NotNull BossBar bar)
      Specified by:
      showBossBar in interface Audience
    • hideBossBar

      public void hideBossBar(@NotNull @NotNull BossBar bar)
      Specified by:
      hideBossBar in interface Audience
    • openBook

      public void openBook(@NotNull @NotNull Book book)
      Specified by:
      openBook in interface Audience
    • isImmune

      public boolean isImmune(@NotNull @NotNull DamageType type)
      Description copied from class: LivingEntity
      Is this entity immune to the given type of damage?
      Overrides:
      isImmune in class LivingEntity
      Parameters:
      type - the type of damage
      Returns:
      true if this entity is immune to the given type of damage
    • setHealth

      public void setHealth(float health)
      Description copied from class: LivingEntity
      Changes the entity health, kill it if health is <= 0 and is not dead yet.
      Overrides:
      setHealth in class LivingEntity
      Parameters:
      health - the new entity health
    • getEntityMeta

      @NotNull public @NotNull PlayerMeta getEntityMeta()
      Description copied from class: Entity
      Gets metadata of this entity. You may want to cast it to specific implementation.
      Overrides:
      getEntityMeta in class Entity
      Returns:
      metadata of this entity.
    • getAdditionalHearts

      public float getAdditionalHearts()
      Gets the player additional hearts.
      Returns:
      the player additional hearts
    • setAdditionalHearts

      public void setAdditionalHearts(float additionalHearts)
      Changes the amount of additional hearts shown.
      Parameters:
      additionalHearts - the count of additional hearts
    • getFood

      public int getFood()
      Gets the player food.
      Returns:
      the player food
    • setFood

      public void setFood(int food)
      Sets and refresh client food bar.
      Parameters:
      food - the new food value
      Throws:
      IllegalArgumentException - if food is not between 0 and 20
    • getFoodSaturation

      public float getFoodSaturation()
    • setFoodSaturation

      public void setFoodSaturation(float foodSaturation)
      Sets and refresh client food saturation.
      Parameters:
      foodSaturation - the food saturation
      Throws:
      IllegalArgumentException - if foodSaturation is not between 0 and 20
    • isEating

      public boolean isEating()
      Gets if the player is eating.
      Returns:
      true if the player is eating, false otherwise
    • getEatingHand

      @Nullable public @Nullable Player.Hand getEatingHand()
      Gets the hand which the player is eating from.
      Returns:
      the eating hand, null if none
    • getDefaultEatingTime

      public long getDefaultEatingTime()
      Gets the player default eating time.
      Returns:
      the player default eating time
    • setDefaultEatingTime

      public void setDefaultEatingTime(long defaultEatingTime)
      Used to change the default eating time animation.
      Parameters:
      defaultEatingTime - the default eating time in milliseconds
    • getEyeHeight

      public double getEyeHeight()
      Description copied from class: Entity
      Gets the entity eye height.

      Default to BoundingBox.height()x0.85

      Overrides:
      getEyeHeight in class Entity
      Returns:
      the entity eye height
    • getDisplayName

      @Nullable public @Nullable Component getDisplayName()
      Gets the player display name in the tab-list.
      Returns:
      the player display name, null means that getUsername() is displayed
    • setDisplayName

      public void setDisplayName(@Nullable @Nullable Component displayName)
      Changes the player display name in the tab-list.

      Sets to null to show the player username.

      Parameters:
      displayName - the display name, null to display the username
    • getSkin

      @Nullable public @Nullable PlayerSkin getSkin()
      Gets the player skin.
      Returns:
      the player skin object, null means that the player has his Entity.getUuid() default skin
    • setSkin

      public void setSkin(@Nullable @Nullable PlayerSkin skin)
      Changes the player skin.

      This does remove the player for all viewers to spawn it again with the correct new skin.

      Parameters:
      skin - the player skin, null to reset it to his Entity.getUuid() default skin
      See Also:
    • isEnableRespawnScreen

      public boolean isEnableRespawnScreen()
      Gets if the player has the respawn screen enabled or disabled.
      Returns:
      true if the player has the respawn screen, false if he didn't
    • setEnableRespawnScreen

      public void setEnableRespawnScreen(boolean enableRespawnScreen)
      Enables or disable the respawn screen.
      Parameters:
      enableRespawnScreen - true to enable the respawn screen, false to disable it
    • getName

      @NotNull public @NotNull Component getName()
      Gets the player's name as a component. This will either return the display name (if set) or a component holding the username.
      Specified by:
      getName in interface NamedAndIdentified
      Returns:
      the name
    • getUsername

      @NotNull public @NotNull String getUsername()
      Gets the player's username.
      Returns:
      the player's username
    • setUsernameField

      public void setUsernameField(@NotNull @NotNull String username)
      Changes the internal player name, used for the AsyncPlayerPreLoginEvent mostly unsafe outside of it.
      Parameters:
      username - the new player name
    • dropItem

      public boolean dropItem(@NotNull @NotNull ItemStack item)
      Calls an ItemDropEvent with a specified item.

      Returns false if item is air.

      Parameters:
      item - the item to drop
      Returns:
      true if player can drop the item (event not cancelled), false otherwise
    • setResourcePack

      public void setResourcePack(@NotNull @NotNull ResourcePack resourcePack)
      Sets the player resource pack.
      Parameters:
      resourcePack - the resource pack
    • facePosition

      public void facePosition(@NotNull @NotNull Player.FacePoint facePoint, @NotNull @NotNull Point targetPosition)
      Rotates the player to face targetPosition.
      Parameters:
      facePoint - the point from where the player should aim
      targetPosition - the target position to face
    • facePosition

      public void facePosition(@NotNull @NotNull Player.FacePoint facePoint, Entity entity, Player.FacePoint targetPoint)
      Rotates the player to face entity.
      Parameters:
      facePoint - the point from where the player should aim
      entity - the entity to face
      targetPoint - the point to aim at entity position
    • spectate

      public void spectate(@NotNull @NotNull Entity entity)
      Sets the camera at entity eyes.
      Parameters:
      entity - the entity to spectate
    • stopSpectating

      public void stopSpectating()
      Resets the camera at the player.
    • getRespawnPoint

      @NotNull public @NotNull Pos getRespawnPoint()
      Used to retrieve the default spawn point.

      Can be altered by the PlayerRespawnEvent.setRespawnPosition(Pos).

      Returns:
      a copy of the default respawn point
    • setRespawnPoint

      public void setRespawnPoint(@NotNull @NotNull Pos respawnPoint)
      Changes the default spawn point.
      Parameters:
      respawnPoint - the player respawn point
    • refreshAfterTeleport

      protected void refreshAfterTeleport()
      Called after the player teleportation to refresh his position and send data to his new viewers.
    • refreshHealth

      protected void refreshHealth()
      Sets the player food and health values to their maximum.
    • getExp

      public float getExp()
      Gets the percentage displayed in the experience bar.
      Returns:
      the exp percentage 0-1
    • setExp

      public void setExp(float exp)
      Used to change the percentage experience bar. This cannot change the displayed level, see setLevel(int).
      Parameters:
      exp - a percentage between 0 and 1
      Throws:
      IllegalArgumentException - if exp is not between 0 and 1
    • getLevel

      public int getLevel()
      Gets the level of the player displayed in the experience bar.
      Returns:
      the player level
    • setLevel

      public void setLevel(int level)
      Used to change the level of the player This cannot change the displayed percentage bar see setExp(float)
      Parameters:
      level - the new level of the player
    • getPlayerConnection

      @NotNull public @NotNull PlayerConnection getPlayerConnection()
      Gets the player connection.

      Used to send packets and get stuff related to the connection.

      Returns:
      the player connection
    • sendPacket

      @Experimental public void sendPacket(@NotNull @NotNull SendablePacket packet)
      Parameters:
      packet - the packet to send
    • sendPackets

      @Experimental public void sendPackets(@NotNull @NotNull SendablePacket... packets)
    • sendPackets

      @Experimental public void sendPackets(@NotNull @NotNull Collection<SendablePacket> packets)
    • isOnline

      public boolean isOnline()
      Gets if the player is online or not.
      Returns:
      true if the player is online, false otherwise
    • getSettings

      @NotNull public @NotNull Player.PlayerSettings getSettings()
      Gets the player settings.
      Returns:
      the player settings
    • getDimensionType

      public DimensionType getDimensionType()
      Gets the player dimension.
      Returns:
      the player current dimension
    • getInventory

      @NotNull public @NotNull PlayerInventory getInventory()
    • getLatency

      public int getLatency()
      Used to get the player latency, computed by seeing how long it takes the client to answer the KeepAlivePacket packet.
      Returns:
      the player latency
    • getGameMode

      public GameMode getGameMode()
      Gets the player GameMode.
      Returns:
      the player current gamemode
    • setGameMode

      public void setGameMode(@NotNull @NotNull GameMode gameMode)
      Changes the player GameMode
      Parameters:
      gameMode - the new player GameMode
    • isCreative

      public boolean isCreative()
      Gets if this player is in creative. Used for code readability.
      Returns:
      true if the player is in creative mode
    • sendDimension

      protected void sendDimension(@NotNull @NotNull DimensionType dimensionType)
      Changes the dimension of the player. Mostly unsafe since it requires sending chunks after.
      Parameters:
      dimensionType - the new player dimension
    • kick

      public void kick(@NotNull @NotNull Component component)
      Kicks the player with a reason.
      Parameters:
      component - the reason
    • kick

      public void kick(@NotNull @NotNull String message)
      Kicks the player with a reason.
      Parameters:
      message - the kick reason
    • setHeldItemSlot

      public void setHeldItemSlot(byte slot)
      Changes the current held slot for the player.
      Parameters:
      slot - the slot that the player has to held
      Throws:
      IllegalArgumentException - if slot is not between 0 and 8
    • getHeldSlot

      public byte getHeldSlot()
      Gets the player held slot (0-8).
      Returns:
      the current held slot for the player
    • setTeam

      public void setTeam(Team team)
      Description copied from class: LivingEntity
      Changes the Team for the entity.
      Overrides:
      setTeam in class LivingEntity
      Parameters:
      team - The new team
    • setBelowNameTag

      public void setBelowNameTag(BelowNameTag belowNameTag)
      Changes the tag below the name.
      Parameters:
      belowNameTag - The new below name tag
    • getOpenInventory

      @Nullable public @Nullable Inventory getOpenInventory()
      Gets the player open inventory.
      Returns:
      the currently open inventory, null if there is not (player inventory is not detected)
    • openInventory

      public boolean openInventory(@NotNull @NotNull Inventory inventory)
      Opens the specified Inventory, close the previous inventory if existing.
      Parameters:
      inventory - the inventory to open
      Returns:
      true if the inventory has been opened/sent to the player, false otherwise (cancelled by event)
    • closeInventory

      public void closeInventory()
      Closes the current inventory if there is any. It closes the player inventory (when opened) if getOpenInventory() returns null.
    • didCloseInventory

      public boolean didCloseInventory()
      Used internally to prevent an inventory click to be processed when the inventory listeners closed the inventory.

      Should only be used within an inventory listener (event or condition).

      Returns:
      true if the inventory has been closed, false otherwise
    • UNSAFE_changeDidCloseInventory

      public void UNSAFE_changeDidCloseInventory(boolean didCloseInventory)
      Used internally to reset the didCloseInventory field.

      Shouldn't be used externally without proper understanding of its consequence.

      Parameters:
      didCloseInventory - the new didCloseInventory field
    • getNextTeleportId

      public int getNextTeleportId()
    • getLastSentTeleportId

      public int getLastSentTeleportId()
    • getLastReceivedTeleportId

      public int getLastReceivedTeleportId()
    • refreshReceivedTeleportId

      public void refreshReceivedTeleportId(int receivedTeleportId)
    • synchronizePosition

      @Internal protected void synchronizePosition(boolean includeSelf)
      Description copied from class: Entity
      Used to synchronize entity position with viewers by sending an EntityTeleportPacket to viewers, in case of a player this is overridden in order to send an additional PlayerPositionAndLookPacket to itself.
      Overrides:
      synchronizePosition in class Entity
      Parameters:
      includeSelf - if true and this is a Player an additional PlayerPositionAndLookPacket will be sent to the player itself
      See Also:
    • getPermissionLevel

      public int getPermissionLevel()
      Gets the player permission level.
      Returns:
      the player permission level
    • setPermissionLevel

      public void setPermissionLevel(int permissionLevel)
      Changes the player permission level.
      Parameters:
      permissionLevel - the new player permission level
      Throws:
      IllegalArgumentException - if permissionLevel is not between 0 and 4
    • setReducedDebugScreenInformation

      public void setReducedDebugScreenInformation(boolean reduced)
      Sets or remove the reduced debug screen.
      Parameters:
      reduced - should the player has the reduced debug screen
    • hasReducedDebugScreenInformation

      public boolean hasReducedDebugScreenInformation()
      Gets if the player has the reduced debug screen.
      Returns:
      true if the player has the reduced debug screen, false otherwise
    • isInvulnerable

      public boolean isInvulnerable()
      The invulnerable field appear in the PlayerAbilitiesPacket packet.
      Overrides:
      isInvulnerable in class LivingEntity
      Returns:
      true if the player is invulnerable, false otherwise
    • setInvulnerable

      public void setInvulnerable(boolean invulnerable)
      This do update the invulnerable field in the packet PlayerAbilitiesPacket and prevent the player from receiving damage.
      Overrides:
      setInvulnerable in class LivingEntity
      Parameters:
      invulnerable - should the player be invulnerable
    • setSneaking

      public void setSneaking(boolean sneaking)
      Description copied from class: Entity
      Makes the entity sneak.

      WARNING: this will not work for the client itself.

      Overrides:
      setSneaking in class Entity
      Parameters:
      sneaking - true to make the entity sneak
    • isFlying

      public boolean isFlying()
      Gets if the player is currently flying.
      Returns:
      true if the player if flying, false otherwise
    • setFlying

      public void setFlying(boolean flying)
      Sets the player flying.
      Parameters:
      flying - should the player fly
    • refreshFlying

      public void refreshFlying(boolean flying)
      Updates the internal flying field.

      Mostly unsafe since there is nothing to backup the value, used internally for creative players.

      Parameters:
      flying - the new flying field
      See Also:
    • isAllowFlying

      public boolean isAllowFlying()
      Gets if the player is allowed to fly.
      Returns:
      true if the player if allowed to fly, false otherwise
    • setAllowFlying

      public void setAllowFlying(boolean allowFlying)
      Allows or forbid the player to fly.
      Parameters:
      allowFlying - should the player be allowed to fly
    • isInstantBreak

      public boolean isInstantBreak()
    • setInstantBreak

      public void setInstantBreak(boolean instantBreak)
      Changes the player ability "Creative Mode".
      Parameters:
      instantBreak - true to allow instant break
      See Also:
    • getFlyingSpeed

      public float getFlyingSpeed()
      Gets the player flying speed.
      Returns:
      the flying speed of the player
    • setFlyingSpeed

      public void setFlyingSpeed(float flyingSpeed)
      Updates the internal field and send a PlayerAbilitiesPacket with the new flying speed.
      Parameters:
      flyingSpeed - the new flying speed of the player
    • getFieldViewModifier

      public float getFieldViewModifier()
    • setFieldViewModifier

      public void setFieldViewModifier(float fieldViewModifier)
    • getStatisticValueMap

      @NotNull public @NotNull Map<PlayerStatistic,Integer> getStatisticValueMap()
      This is the map used to send the statistic packet. It is possible to add/remove/change statistic value directly into it.
      Returns:
      the modifiable statistic map
    • getVehicleInformation

      @NotNull public @NotNull PlayerVehicleInformation getVehicleInformation()
      Gets the player vehicle information.
      Returns:
      the player vehicle information
    • refreshAbilities

      protected void refreshAbilities()
      Sends to the player a PlayerAbilitiesPacket with all the updated fields.
    • addPacketToQueue

      public void addPacketToQueue(@NotNull @NotNull ClientPacket packet)
      All packets in the queue are executed in the update(long) method It is used internally to add all received packet from the client. Could be used to "simulate" a received packet, but to use at your own risk.
      Parameters:
      packet - the packet to add in the queue
    • interpretPacketQueue

      @Internal @Experimental public void interpretPacketQueue()
    • refreshLatency

      public void refreshLatency(int latency)
      Changes the storage player latency and update its tab value.
      Parameters:
      latency - the new player latency
    • refreshOnGround

      public void refreshOnGround(boolean onGround)
    • refreshKeepAlive

      public void refreshKeepAlive(long lastKeepAlive)
      Used to change internally the last sent last keep alive id.

      Warning: could lead to have the player kicked because of a wrong keep alive packet.

      Parameters:
      lastKeepAlive - the new lastKeepAlive id
    • didAnswerKeepAlive

      public boolean didAnswerKeepAlive()
    • refreshAnswerKeepAlive

      public void refreshAnswerKeepAlive(boolean answerKeepAlive)
    • refreshHeldSlot

      public void refreshHeldSlot(byte slot)
      Changes the held item for the player viewers Also cancel eating if isEating() was true.

      Warning: the player will not be noticed by this chance, only his viewers, see instead: setHeldItemSlot(byte).

      Parameters:
      slot - the new held slot
    • refreshEating

      public void refreshEating(@Nullable @Nullable Player.Hand eatingHand, long eatingTime)
    • refreshEating

      public void refreshEating(@Nullable @Nullable Player.Hand eatingHand)
    • callItemUpdateStateEvent

      @Deprecated @Nullable public @Nullable ItemUpdateStateEvent callItemUpdateStateEvent(boolean allowFood, @Nullable @Nullable Player.Hand hand)
      Deprecated.
      Used to call ItemUpdateStateEvent with the proper item It does check which hand to get the item to update.
      Parameters:
      allowFood - true if food should be updated, false otherwise
      Returns:
      the called ItemUpdateStateEvent, null if there is no item to update the state
    • callItemUpdateStateEvent

      @Nullable public @Nullable ItemUpdateStateEvent callItemUpdateStateEvent(@Nullable @Nullable Player.Hand hand)
      Used to call ItemUpdateStateEvent with the proper item It does check which hand to get the item to update. Allows food.
      Returns:
      the called ItemUpdateStateEvent, null if there is no item to update the state
    • refreshVehicleSteer

      public void refreshVehicleSteer(float sideways, float forward, boolean jump, boolean unmount)
    • getLastKeepAlive

      public long getLastKeepAlive()
      Gets the last sent keep alive id.
      Returns:
      the last keep alive id sent to the player
    • asHoverEvent

      @NotNull public @NotNull HoverEvent<HoverEvent.ShowEntity> asHoverEvent(@NotNull @NotNull UnaryOperator<HoverEvent.ShowEntity> op)
      Specified by:
      asHoverEvent in interface HoverEventSource<HoverEvent.ShowEntity>
      Overrides:
      asHoverEvent in class Entity
    • getAddPlayerToList

      @NotNull protected @NotNull PlayerInfoPacket getAddPlayerToList()
      Gets the packet to add the player from the tab-list.
      Returns:
      a PlayerInfoPacket to add the player
    • getRemovePlayerToList

      @NotNull protected @NotNull PlayerInfoPacket getRemovePlayerToList()
      Gets the packet to remove the player from the tab-list.
      Returns:
      a PlayerInfoPacket to remove the player
    • showPlayer

      protected void showPlayer(@NotNull @NotNull PlayerConnection connection)
      Sends all the related packet to have the player sent to another with related data (create player, spawn position, velocity, metadata, equipments, passengers, team).

      WARNING: this alone does not sync the player, please use Entity.addViewer(Player).

      Parameters:
      connection - the connection to show the player to
    • getItemInMainHand

      @NotNull public @NotNull ItemStack getItemInMainHand()
      Description copied from interface: EquipmentHandler
      Gets the ItemStack in main hand.
      Specified by:
      getItemInMainHand in interface EquipmentHandler
      Overrides:
      getItemInMainHand in class LivingEntity
      Returns:
      the ItemStack in main hand
    • setItemInMainHand

      public void setItemInMainHand(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the main hand ItemStack.
      Specified by:
      setItemInMainHand in interface EquipmentHandler
      Overrides:
      setItemInMainHand in class LivingEntity
      Parameters:
      itemStack - the main hand ItemStack
    • getItemInOffHand

      @NotNull public @NotNull ItemStack getItemInOffHand()
      Description copied from interface: EquipmentHandler
      Gets the ItemStack in off hand.
      Specified by:
      getItemInOffHand in interface EquipmentHandler
      Overrides:
      getItemInOffHand in class LivingEntity
      Returns:
      the item in off hand
    • setItemInOffHand

      public void setItemInOffHand(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the off hand ItemStack.
      Specified by:
      setItemInOffHand in interface EquipmentHandler
      Overrides:
      setItemInOffHand in class LivingEntity
      Parameters:
      itemStack - the off hand ItemStack
    • getHelmet

      @NotNull public @NotNull ItemStack getHelmet()
      Description copied from interface: EquipmentHandler
      Gets the helmet.
      Specified by:
      getHelmet in interface EquipmentHandler
      Overrides:
      getHelmet in class LivingEntity
      Returns:
      the helmet
    • setHelmet

      public void setHelmet(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the helmet.
      Specified by:
      setHelmet in interface EquipmentHandler
      Overrides:
      setHelmet in class LivingEntity
      Parameters:
      itemStack - the helmet
    • getChestplate

      @NotNull public @NotNull ItemStack getChestplate()
      Description copied from interface: EquipmentHandler
      Gets the chestplate.
      Specified by:
      getChestplate in interface EquipmentHandler
      Overrides:
      getChestplate in class LivingEntity
      Returns:
      the chestplate
    • setChestplate

      public void setChestplate(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the chestplate.
      Specified by:
      setChestplate in interface EquipmentHandler
      Overrides:
      setChestplate in class LivingEntity
      Parameters:
      itemStack - the chestplate
    • getLeggings

      @NotNull public @NotNull ItemStack getLeggings()
      Description copied from interface: EquipmentHandler
      Gets the leggings.
      Specified by:
      getLeggings in interface EquipmentHandler
      Overrides:
      getLeggings in class LivingEntity
      Returns:
      the leggings
    • setLeggings

      public void setLeggings(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the leggings.
      Specified by:
      setLeggings in interface EquipmentHandler
      Overrides:
      setLeggings in class LivingEntity
      Parameters:
      itemStack - the leggings
    • getBoots

      @NotNull public @NotNull ItemStack getBoots()
      Description copied from interface: EquipmentHandler
      Gets the boots.
      Specified by:
      getBoots in interface EquipmentHandler
      Overrides:
      getBoots in class LivingEntity
      Returns:
      the boots
    • setBoots

      public void setBoots(@NotNull @NotNull ItemStack itemStack)
      Description copied from interface: EquipmentHandler
      Changes the boots.
      Specified by:
      setBoots in interface EquipmentHandler
      Overrides:
      setBoots in class LivingEntity
      Parameters:
      itemStack - the boots
    • getLocale

      public Locale getLocale()
      Description copied from interface: Localizable
      Gets the locale.
      Specified by:
      getLocale in interface Localizable
      Returns:
      the locale, or null if they do not have a locale set
    • updateSnapshot

      @NotNull public @NotNull PlayerSnapshot updateSnapshot(@NotNull @NotNull SnapshotUpdater updater)
      Description copied from interface: Snapshotable
      Updates the currently cached snapshot if required. The updater can be used to retrieve references to other snapshots while avoiding circular dependency. Be careful to do not store updater anywhere as its data will change when building requested references.

      This method is not thread-safe, and targeted at internal use since its execution rely on safe-points (e.g. end of ticks)

      Specified by:
      updateSnapshot in interface Snapshotable
      Overrides:
      updateSnapshot in class Entity
      Parameters:
      updater - the snapshot updater/context
      Returns:
      the updated snapshot
    • setLocale

      public void setLocale(@Nullable @Nullable Locale locale)
      Sets the player's locale. This will only set the locale of the player as it is stored in the server. This will also be reset if the settings are refreshed.
      Specified by:
      setLocale in interface Localizable
      Parameters:
      locale - the new locale
    • identity

      @NotNull public @NotNull Identity identity()
      Specified by:
      identity in interface Identified
    • pointers

      @NotNull public @NotNull Pointers pointers()
      Specified by:
      pointers in interface Pointered
    • setUuid

      public void setUuid(@NotNull @NotNull UUID uuid)
      Description copied from class: Entity
      Changes the internal entity UUID, mostly unsafe.
      Overrides:
      setUuid in class Entity
      Parameters:
      uuid - the new entity uuid
    • isPlayer

      public boolean isPlayer()
      Description copied from interface: CommandSender
      Gets if the sender is a Player.

      Consider using instanceof instead.

      Specified by:
      isPlayer in interface CommandSender
      Returns:
      true if 'this' is a player, false otherwise
    • asPlayer

      public Player asPlayer()
      Description copied from interface: CommandSender
      Casts this object to a Player. No checks are performed, ClassCastException can very much happen.
      Specified by:
      asPlayer in interface CommandSender
      See Also:
    • sendChunkUpdates

      protected void sendChunkUpdates(Chunk newChunk)
    • teleport

      @NotNull public @NotNull CompletableFuture<Void> teleport(@NotNull @NotNull Pos position, long @Nullable [] chunks)
      Description copied from class: Entity
      Teleports the entity only if the chunk at position is loaded or if Instance.hasEnabledAutoChunkLoad() returns true.
      Overrides:
      teleport in class Entity
      Parameters:
      position - the teleport position
      chunks - the chunk indexes to load before teleporting the entity, indexes are from ChunkUtils.getChunkIndex(int, int), can be null or empty to only load the chunk at position