Class Player
- All Implemented Interfaces:
Audience
,Identified
,Pointered
,Sound.Emitter
,HoverEventSource<HoverEvent.ShowEntity>
,Localizable
,Shape
,CommandSender
,EventHandler<EntityEvent>
,EquipmentHandler
,PermissionHandler
,Snapshotable
,Taggable
,TagReadable
,TagWritable
,Tickable
,Schedulable
,NamedAndIdentified
,Viewable
You can easily create your own implementation of this and use it with ConnectionManager.setPlayerProvider(PlayerProvider)
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
Represents the main or off hand of the player.static enum
Represents where is located the main hand of the player (can be changed in Minecraft option).class
Nested classes/interfaces inherited from class net.minestom.server.entity.Entity
Entity.Pose
-
Field Summary
Modifier and TypeFieldDescriptionprotected Cooldown
static final boolean
protected PlayerInventory
protected final PlayerConnection
Fields inherited from class net.minestom.server.entity.LivingEntity
canPickupItem, expandedBoundingBox, invulnerable, isDead, itemPickupCooldown, lastDamage
Fields inherited from class net.minestom.server.entity.Entity
boundingBox, currentChunk, entityMeta, entityType, gravityTickCount, hasCollision, hasPhysics, instance, lastSyncedPosition, lastVelocityWasZero, metadata, onGround, position, previousPosition, removed, trackingUpdate, uuid, vehicle, velocity, viewEngine, viewers
-
Constructor Summary
ConstructorDescriptionPlayer
(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPacketToQueue
(@NotNull ClientPacket packet) All packets in the queue are executed in theupdate(long)
method It is used internally to add all received packet from the client.@NotNull HoverEvent
<HoverEvent.ShowEntity> asHoverEvent
(@NotNull UnaryOperator<HoverEvent.ShowEntity> op) @Nullable ItemUpdateStateEvent
callItemUpdateStateEvent
(boolean allowFood, @Nullable Player.Hand hand) Deprecated.@Nullable ItemUpdateStateEvent
callItemUpdateStateEvent
(@Nullable Player.Hand hand) Used to callItemUpdateStateEvent
with the proper item It does check which hand to get the item to update.void
void
void
Closes the current inventory if there is any.void
closeInventory
(boolean fromClient) boolean
boolean
Used internally to prevent an inventory click to be processed when the inventory listeners closed the inventory.boolean
Calls anItemDropEvent
with a specified item.void
facePosition
(@NotNull Player.FacePoint facePoint, @NotNull Point targetPosition) Rotates the player to facetargetPosition
.void
facePosition
(@NotNull Player.FacePoint facePoint, Entity entity, Player.FacePoint targetPoint) Rotates the player to faceentity
.float
Gets the player additional hearts.protected @NotNull PlayerInfoUpdatePacket
Gets the packet to add the player from the tab-list.@NotNull ItemStack
getBoots()
Gets the boots.@NotNull ItemStack
Gets the chestplate.@Nullable WorldPos
long
Gets the player default eating time.Gets the player dimension.@Nullable Component
Gets the player display name in the tab-list.@Nullable Player.Hand
Gets the hand which the player is eating from.float
getExp()
Gets the percentage displayed in the experience bar.double
Gets the entity eye height.float
float
Gets the player flying speed.int
getFood()
Gets the player food.float
Gets the playerGameMode
.byte
Gets the player held slot (0-8).@NotNull ItemStack
Gets the helmet.@NotNull PlayerInventory
@NotNull ItemStack
Gets theItemStack
in main hand.@NotNull ItemStack
Gets theItemStack
in off hand.long
Gets the last sent keep alive id.int
int
int
Used to get the player latency, computed by seeing how long it takes the client to answer theKeepAlivePacket
packet.@NotNull ItemStack
Gets the leggings.int
getLevel()
Gets the level of the player displayed in the experience bar.Gets the locale.@NotNull Component
getName()
Gets the player's name as a component.int
@Nullable Inventory
Gets the player open inventory.int
Gets the player permission level.@NotNull PlayerConnection
Gets the player connection.int
protected @NotNull PlayerInfoRemovePacket
Gets the packet to remove the player from the tab-list.@Nullable CompletableFuture
<Void> If there are resource packs in-flight, a future is returned which will be completed when all resource packs have been responded to by the client.@NotNull Pos
Used to retrieve the default spawn point.@NotNull Player.PlayerSettings
Gets the player settings.@Nullable PlayerSkin
getSkin()
Gets the player skin.@NotNull Map
<PlayerStatistic, Integer> This is the map used to send the statistic packet.@NotNull PlayerMeta
Gets the entity meta for the player.@NotNull String
Gets the player's username.@NotNull PlayerVehicleInformation
Gets the player vehicle information.boolean
Gets if the player has the reduced debug screen.void
hideBossBar
(@NotNull BossBar bar) @NotNull Identity
identity()
void
boolean
Gets if the player is allowed to fly.boolean
Gets if this player is in creative.boolean
isEating()
Gets if the player is eating.boolean
Gets if the player has the respawn screen enabled or disabled.boolean
isFlying()
Gets if the player is currently flying.boolean
isImmune
(@NotNull DamageType type) Is this entity immune to the given type of damage?boolean
boolean
The invulnerable field appear in thePlayerAbilitiesPacket
packet.boolean
boolean
isOnline()
Gets if the player is online or not.void
Kicks the player with a reason.void
Kicks the player with a reason.void
kill()
Kills the entity, trigger theEntityDeathEvent
event.void
Forces the player's client to look towards the specified pointvoid
Forces the player's client to look towards the specified entityvoid
onChunkBatchReceived
(float newTargetChunksPerTick) void
onResourcePackStatus
(@NotNull UUID id, @NotNull ResourcePackStatus status) void
boolean
openInventory
(@NotNull Inventory inventory) Opens the specified Inventory, close the previous inventory if existing.void
playEffect
(@NotNull Effects effect, int x, int y, int z, int data, boolean disableRelativeVolume) Plays a given effect at the given position for this player.protected void
Used to initialize the player connectionvoid
void
void
playSound
(@NotNull Sound sound, @NotNull Sound.Emitter emitter) void
@NotNull Pointers
pointers()
protected void
Sends to the player aPlayerAbilitiesPacket
with all the updated fields.protected void
Called after the player teleportation to refresh his position and send data to his new viewers.void
refreshAnswerKeepAlive
(boolean answerKeepAlive) void
Refreshes the command list for this player.void
refreshEating
(@Nullable Player.Hand eatingHand) void
refreshEating
(@Nullable Player.Hand eatingHand, long eatingTime) void
refreshFlying
(boolean flying) Updates the internal flying field.protected void
Sets the player food and health values to their maximum.void
refreshHeldSlot
(byte slot) Changes the held item for the player viewers Also cancel eating ifisEating()
was true.void
refreshKeepAlive
(long lastKeepAlive) Used to change internally the last sent last keep alive id.void
refreshLatency
(int latency) Changes the storage player latency and update its tab value.void
refreshOnGround
(boolean onGround) void
refreshReceivedTeleportId
(int receivedTeleportId) void
refreshVehicleSteer
(float sideways, float forward, boolean jump, boolean unmount) void
remove
(boolean permanent) void
removeResourcePacks
(@NotNull UUID id, @NotNull UUID @NotNull ... others) void
void
respawn()
Respawns the player by sending aRespawnPacket
to the player and teleporting him togetRespawnPoint()
.void
sendActionBar
(@NotNull Component message) void
Queues the given chunk to be sent to the player.protected void
sendChunkUpdates
(Chunk newChunk) protected void
sendDimension
(@NotNull DimensionType dimensionType, @NotNull String dimensionName) Changes the dimension of the player.void
sendMessage
(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) Deprecated.void
sendPacket
(@NotNull SendablePacket packet) Shortcut forPlayerConnection.sendPacket(SendablePacket)
.void
sendPackets
(@NotNull Collection<SendablePacket> packets) void
sendPackets
(@NotNull SendablePacket... packets) void
sendPacketToViewersAndSelf
(@NotNull SendablePacket packet) Sends a packet to all viewers and the viewable element if it is a player.void
sendPlayerListHeaderAndFooter
(@NotNull Component header, @NotNull Component footer) void
sendPluginMessage
(@NotNull String channel, byte @NotNull [] data) Sends a plugin message to the player.void
sendPluginMessage
(@NotNull String channel, @NotNull String message) Sends a plugin message to the player.void
sendResourcePacks
(@NotNull ResourcePackRequest request) <T> void
sendTitlePart
(@NotNull TitlePart<T> part, T value) void
setAdditionalHearts
(float additionalHearts) Changes the amount of additional hearts shown.void
setAllowFlying
(boolean allowFlying) Allows or forbid the player to fly.void
setBelowNameTag
(BelowNameTag belowNameTag) Changes the tag below the name.void
Changes the boots.void
setChestplate
(@NotNull ItemStack itemStack) Changes the chestplate.void
setDeathLocation
(@NotNull DimensionType type, @NotNull Pos position) void
setDefaultEatingTime
(long defaultEatingTime) Used to change the default eating time animation.void
setDisplayName
(@Nullable Component displayName) Changes the player display name in the tab-list.void
setEnableRespawnScreen
(boolean enableRespawnScreen) Enables or disable the respawn screen.void
setExp
(float exp) Used to change the percentage experience bar.void
setFieldViewModifier
(float fieldViewModifier) void
setFlying
(boolean flying) Sets the player flying.void
setFlyingSpeed
(float flyingSpeed) Updates the internal field and send aPlayerAbilitiesPacket
with the new flying speed.void
setFood
(int food) Sets and refresh client food bar.void
setFoodSaturation
(float foodSaturation) Sets and refresh client food saturation.boolean
setGameMode
(@NotNull GameMode gameMode) Changes the playerGameMode
void
setHealth
(float health) Changes the entity health, kill it ifhealth
is <= 0 and is not dead yet.void
setHeldItemSlot
(byte slot) Changes the current held slot for the player.void
Changes the helmet.setInstance
(@NotNull Instance instance) Changes the player instance without changing its position (defaulted togetRespawnPoint()
if the player is not in any instance).setInstance
(@NotNull Instance instance, @NotNull Pos spawnPosition) Changes the player instance and load surrounding chunks if needed.void
setInstantBreak
(boolean instantBreak) Changes the player ability "Creative Mode".void
setInvulnerable
(boolean invulnerable) This do update theinvulnerable
field in the packetPlayerAbilitiesPacket
and prevent the player from receiving damage.void
setItemInMainHand
(@NotNull ItemStack itemStack) Changes the main handItemStack
.void
setItemInOffHand
(@NotNull ItemStack itemStack) Changes the off handItemStack
.void
setLeggings
(@NotNull ItemStack itemStack) Changes the leggings.void
setLevel
(int level) Used to change the level of the player This cannot change the displayed percentage bar seesetExp(float)
void
Sets the player's locale.void
setPendingOptions
(@NotNull Instance pendingInstance, boolean hardcore) void
setPermissionLevel
(int permissionLevel) Changes the player permission level.void
setPortalCooldown
(int portalCooldown) void
setReducedDebugScreenInformation
(boolean reduced) Sets or remove the reduced debug screen.void
setRespawnPoint
(@NotNull Pos respawnPoint) Changes the default spawn point.void
setSkin
(@Nullable PlayerSkin skin) Changes the player skin.void
setSneaking
(boolean sneaking) Makes the entity sneak.void
setUsernameField
(@NotNull String username) Changes the internal player name, used for theAsyncPlayerPreLoginEvent
mostly unsafe outside of it.void
Changes the internal entity UUID, mostly unsafe.void
setView
(float yaw, float pitch) Forces the player's client to look towards the target yaw/pitchvoid
showBossBar
(@NotNull BossBar bar) protected void
showPlayer
(@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).void
Sets the camera atentity
eyes.void
Moves the player immediately to the configuration state.void
void
Resets the camera at the player.@NotNull CompletableFuture
<Void> Teleports the entity only if the chunk atposition
is loaded or ifInstance.hasEnabledAutoChunkLoad()
returns true.void
UNSAFE_changeDidCloseInventory
(boolean didCloseInventory) Used internally to reset the didCloseInventory field.Used when the player is created.void
update
(long time) Called each tick.void
updateOldViewer
(@NotNull Player player) Called when a viewer must be destroyed.protected void
@NotNull PlayerSnapshot
updateSnapshot
(@NotNull SnapshotUpdater updater) Updates the currently cached snapshot if required.Methods inherited from class net.minestom.server.entity.LivingEntity
canPickupItem, damage, damage, getArrowCount, getAttribute, getAttributeValue, getFireDamagePeriod, getHealth, getLastDamageSource, getLivingEntityMeta, getMaxHealth, getPropertiesPacket, getTargetBlockPosition, getTeam, heal, isDead, isFlyingWithElytra, onAttributeChanged, refreshActiveHand, refreshIsDead, setArrowCount, setBoundingBox, setCanPickupItem, setFireDamagePeriod, setFireDamagePeriod, setFireForDuration, setFireForDuration, setFireForDuration, setFlyingWithElytra, setTeam, swingMainHand, swingOffHand, takeKnockback, updateNewViewer
Methods inherited from class net.minestom.server.entity.Entity
addEffect, addPassenger, addViewer, autoViewEntities, clearEffects, despawn, editEntityMeta, eventNode, generateId, getAcquirable, getActiveEffects, getAerodynamics, getAliveTicks, getAllPermissions, getAttachEntityPacket, getBoundingBox, getChunk, getCustomName, getDistance, getDistance, getDistanceSquared, getDistanceSquared, getEffect, getEffectLevel, getEntity, getEntity, getEntityId, getEntityMeta, getEntityType, getGravityTickCount, getInstance, getLeashedEntities, getLeashHolder, getLineOfSight, getLineOfSightEntity, getMetadataPacket, getPassengers, getPassengersPacket, getPose, getPosition, getPreviousPosition, getSynchronizationTicks, getUuid, getVehicle, getVelocity, getVelocityForPacket, getVelocityPacket, getViewers, hasCollision, hasEffect, hasLineOfSight, hasLineOfSight, hasNoGravity, hasPassenger, hasPredictableViewers, hasVelocity, intersectBox, intersectBoxSwept, isActive, isAutoViewable, isCustomNameVisible, isGlowing, isInvisible, isOccluded, isOnFire, isRemoved, isSilent, isSneaking, isSprinting, movementTick, refreshCoordinate, refreshCurrentChunk, refreshPosition, refreshPosition, refreshPosition, relativeEnd, relativeStart, remove, removeEffect, removePassenger, removeViewer, scheduleNextTick, scheduler, scheduleRemove, scheduleRemove, setAerodynamics, setAutoViewable, setAutoViewEntities, setBoundingBox, setCustomName, setCustomNameVisible, setGlowing, setInstance, setInvisible, setLeashHolder, setNoGravity, setOnFire, setPose, setSilent, setSprinting, setSynchronizationTicks, setVelocity, spawn, switchEntityType, synchronizeNextTick, synchronizePosition, tagHandler, teleport, tick, triggerStatus, updateViewableRule, updateViewableRule, updateViewerRule, updateViewerRule
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.kyori.adventure.audience.Audience
deleteMessage, deleteMessage, filterAudience, forEachAudience, openBook, removeResourcePacks, removeResourcePacks, removeResourcePacks, sendActionBar, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListFooter, sendPlayerListHeader, sendPlayerListHeader, sendPlayerListHeaderAndFooter, sendResourcePacks, sendResourcePacks, showTitle, stopSound
Methods inherited from interface net.minestom.server.command.CommandSender
sendMessage, sendMessage
Methods inherited from interface net.minestom.server.inventory.EquipmentHandler
getEquipment, getEquipmentsPacket, getItemInHand, hasEquipment, setEquipment, setItemInHand, syncEquipment
Methods inherited from interface net.kyori.adventure.text.event.HoverEventSource
asHoverEvent
Methods inherited from interface net.minestom.server.utils.identity.NamedAndIdentified
getUuid
Methods inherited from interface net.minestom.server.permission.PermissionHandler
addPermission, getAllPermissions, getPermission, hasPermission, hasPermission, hasPermission, removePermission, removePermission
Methods inherited from interface net.kyori.adventure.pointer.Pointered
get, getOrDefault, getOrDefaultFrom
Methods inherited from interface net.minestom.server.collision.Shape
intersectEntity, isFaceFull
Methods inherited from interface net.minestom.server.tag.Taggable
getTag, hasTag, removeTag, setTag, tagHandler
Methods inherited from interface net.minestom.server.Viewable
getViewersAsAudience, getViewersAsAudiences, isViewer, sendPacketsToViewers, sendPacketsToViewers, sendPacketToViewers
-
Field Details
-
EXPERIMENT_PERFORM_POSE_UPDATES
public static final boolean EXPERIMENT_PERFORM_POSE_UPDATES -
playerConnection
-
inventory
-
experiencePickupCooldown
-
-
Constructor Details
-
Player
public Player(@NotNull @NotNull UUID uuid, @NotNull @NotNull String username, @NotNull @NotNull PlayerConnection playerConnection)
-
-
Method Details
-
setPendingOptions
@Internal public void setPendingOptions(@NotNull @NotNull Instance pendingInstance, boolean hardcore) -
UNSAFE_init
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.
-
startConfigurationPhase
public void startConfigurationPhase()Moves the player immediately to the configuration state. The player is automatically moved to configuration upon finishing login, this method can be used to move them back to configuration after entering the play state.This will result in them being removed from the current instance, player list, etc.
-
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 classLivingEntity
- Parameters:
time
- time of the update in milliseconds
-
kill
public void kill()Description copied from class:LivingEntity
Kills the entity, trigger theEntityDeathEvent
event.- Overrides:
kill
in classLivingEntity
-
respawn
public void respawn()Respawns the player by sending aRespawnPacket
to the player and teleporting him togetRespawnPoint()
. It also resets fire and health. -
refreshCommands
public void refreshCommands()Refreshes the command list for this player. This checks theCommandCondition
s again, and any changes will be visible to the player. -
isOnGround
public boolean isOnGround()- Overrides:
isOnGround
in classEntity
-
remove
public void remove(boolean permanent) -
updateOldViewer
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 classEntity
- Parameters:
player
- the player to send the packets to
-
sendPacketToViewersAndSelf
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 interfaceViewable
- 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 classEntity
- Parameters:
instance
- the new player instancespawnPosition
- the new position of the player- Returns:
- a future called once the player instance changed
-
setInstance
Changes the player instance without changing its position (defaulted togetRespawnPoint()
if the player is not in any instance).- Overrides:
setInstance
in classEntity
- 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:
-
onChunkBatchReceived
@Internal public void onChunkBatchReceived(float newTargetChunksPerTick) -
sendChunk
Queues the given chunk to be sent to the player.- Parameters:
chunk
- The chunk to send
-
updatePose
protected void updatePose()- Overrides:
updatePose
in classEntity
-
sendPluginMessage
Sends a plugin message to the player.- Parameters:
channel
- the message channeldata
- the message data
-
sendPluginMessage
Sends a plugin message to the player.Message encoded to UTF-8.
- Parameters:
channel
- the message channelmessage
- the message
-
sendMessage
@Deprecated public void sendMessage(@NotNull @NotNull Identity source, @NotNull @NotNull Component message, @NotNull @NotNull MessageType type) Deprecated.Deprecated, as the Adventure library has deprecated this method in the Audience class- Specified by:
sendMessage
in interfaceAudience
- Parameters:
source
- the identity of the source of the messagemessage
- a messagetype
- the type
-
playSound
-
playSound
-
playSound
-
playSound
-
stopSound
-
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 playx
- x position of the effecty
- y position of the effectz
- z position of the effectdata
- data for the effectdisableRelativeVolume
- disable volume scaling based on distance
-
sendTitlePart
- Specified by:
sendTitlePart
in interfaceAudience
-
sendActionBar
- Specified by:
sendActionBar
in interfaceAudience
-
resetTitle
public void resetTitle()- Specified by:
resetTitle
in interfaceAudience
-
clearTitle
public void clearTitle()- Specified by:
clearTitle
in interfaceAudience
-
showBossBar
- Specified by:
showBossBar
in interfaceAudience
-
hideBossBar
- Specified by:
hideBossBar
in interfaceAudience
-
openBook
-
isImmune
Description copied from class:LivingEntity
Is this entity immune to the given type of damage?- Overrides:
isImmune
in classLivingEntity
- 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 ifhealth
is <= 0 and is not dead yet.- Overrides:
setHealth
in classLivingEntity
- Parameters:
health
- the new entity health
-
getUnsafeEntityMeta
Gets the entity meta for the player.Note that this method will throw an exception if the player's entity type has been changed with
Entity.switchEntityType(EntityType)
. It is wise to checkEntity.getEntityType()
first. -
getAdditionalHearts
public float getAdditionalHearts()Gets the player additional hearts.Note that this function is uncallable if the player has their entity type switched with
Entity.switchEntityType(EntityType)
.- Returns:
- the player additional hearts
-
setAdditionalHearts
public void setAdditionalHearts(float additionalHearts) Changes the amount of additional hearts shown.Note that this function is uncallable if the player has their entity type switched with
Entity.switchEntityType(EntityType)
.- 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
- iffood
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
- iffoodSaturation
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
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 classEntity
- Returns:
- the entity eye height
-
getDisplayName
Gets the player display name in the tab-list.- Returns:
- the player display name, null means that
getUsername()
is displayed
-
setDisplayName
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
Gets the player skin.- Returns:
- the player skin object,
null means that the player has his
Entity.getUuid()
default skin
-
setSkin
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 hisEntity.getUuid()
default skin- See Also:
-
setDeathLocation
-
getDeathLocation
-
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
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 interfaceNamedAndIdentified
- Returns:
- the name
-
getUsername
Gets the player's username.- Returns:
- the player's username
-
setUsernameField
Changes the internal player name, used for theAsyncPlayerPreLoginEvent
mostly unsafe outside of it.- Parameters:
username
- the new player name
-
dropItem
Calls anItemDropEvent
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
-
sendResourcePacks
- Specified by:
sendResourcePacks
in interfaceAudience
-
removeResourcePacks
public void removeResourcePacks(@NotNull @NotNull UUID id, @NotNull @NotNull UUID @NotNull ... others) - Specified by:
removeResourcePacks
in interfaceAudience
-
clearResourcePacks
public void clearResourcePacks()- Specified by:
clearResourcePacks
in interfaceAudience
-
getResourcePackFuture
If there are resource packs in-flight, a future is returned which will be completed when all resource packs have been responded to by the client. Otherwise null is returned. -
onResourcePackStatus
@Internal public void onResourcePackStatus(@NotNull @NotNull UUID id, @NotNull @NotNull ResourcePackStatus status) -
facePosition
public void facePosition(@NotNull @NotNull Player.FacePoint facePoint, @NotNull @NotNull Point targetPosition) Rotates the player to facetargetPosition
.- Parameters:
facePoint
- the point from where the player should aimtargetPosition
- the target position to face
-
facePosition
public void facePosition(@NotNull @NotNull Player.FacePoint facePoint, Entity entity, Player.FacePoint targetPoint) Rotates the player to faceentity
.- Parameters:
facePoint
- the point from where the player should aimentity
- the entity to facetargetPoint
- the point to aim atentity
position
-
spectate
Sets the camera atentity
eyes.- Parameters:
entity
- the entity to spectate
-
stopSpectating
public void stopSpectating()Resets the camera at the player. -
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
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, seesetLevel(int)
.- Parameters:
exp
- a percentage between 0 and 1- Throws:
IllegalArgumentException
- ifexp
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 seesetExp(float)
- Parameters:
level
- the new level of the player
-
getPortalCooldown
public int getPortalCooldown() -
setPortalCooldown
public void setPortalCooldown(int portalCooldown) -
getPlayerConnection
Gets the player connection.Used to send packets and get stuff related to the connection.
- Returns:
- the player connection
-
sendPacket
Shortcut forPlayerConnection.sendPacket(SendablePacket)
.- Parameters:
packet
- the packet to send
-
sendPackets
-
sendPackets
-
isOnline
public boolean isOnline()Gets if the player is online or not.- Returns:
- true if the player is online, false otherwise
-
getSettings
Gets the player settings.- Returns:
- the player settings
-
getDimensionType
Gets the player dimension.- Returns:
- the player current dimension
-
getInventory
-
getLatency
public int getLatency()Used to get the player latency, computed by seeing how long it takes the client to answer theKeepAlivePacket
packet.- Returns:
- the player latency
-
getGameMode
Gets the playerGameMode
.- Returns:
- the player current gamemode
-
setGameMode
Changes the playerGameMode
- Parameters:
gameMode
- the new player GameMode- Returns:
- true if the gamemode was changed successfully, false otherwise (cancelled by event)
-
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, @NotNull @NotNull String dimensionName) Changes the dimension of the player. Mostly unsafe since it requires sending chunks after.- Parameters:
dimensionType
- the new player dimension
-
kick
Kicks the player with a reason.- Parameters:
component
- the reason
-
kick
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
- ifslot
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
-
setBelowNameTag
Changes the tag below the name.- Parameters:
belowNameTag
- The new below name tag
-
getOpenInventory
Gets the player open inventory.- Returns:
- the currently open inventory, null if there is not (player inventory is not detected)
-
openInventory
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) ifgetOpenInventory()
returns null. -
closeInventory
@Internal public void closeInventory(boolean fromClient) -
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
@Internal 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) -
setView
public void setView(float yaw, float pitch) Forces the player's client to look towards the target yaw/pitch -
lookAt
Forces the player's client to look towards the specified pointNote: the player's position is not updated on the server until the client receives this packet
-
lookAt
Forces the player's client to look towards the specified entityNote: the player's position is not updated on the server until the client receives this packet
-
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
- ifpermissionLevel
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 thePlayerAbilitiesPacket
packet.- Overrides:
isInvulnerable
in classLivingEntity
- Returns:
- true if the player is invulnerable, false otherwise
-
setInvulnerable
public void setInvulnerable(boolean invulnerable) This do update theinvulnerable
field in the packetPlayerAbilitiesPacket
and prevent the player from receiving damage.- Overrides:
setInvulnerable
in classLivingEntity
- 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 classEntity
- 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 aPlayerAbilitiesPacket
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
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
Gets the player vehicle information.- Returns:
- the player vehicle information
-
refreshAbilities
protected void refreshAbilities()Sends to the player aPlayerAbilitiesPacket
with all the updated fields. -
addPacketToQueue
All packets in the queue are executed in theupdate(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 ifisEating()
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
-
refreshEating
-
callItemUpdateStateEvent
@Deprecated @Nullable public @Nullable ItemUpdateStateEvent callItemUpdateStateEvent(boolean allowFood, @Nullable @Nullable Player.Hand hand) Deprecated.UsecallItemUpdateStateEvent(Hand)
insteadUsed to callItemUpdateStateEvent
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 callItemUpdateStateEvent
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 interfaceHoverEventSource<HoverEvent.ShowEntity>
- Overrides:
asHoverEvent
in classEntity
-
getAddPlayerToList
Gets the packet to add the player from the tab-list.- Returns:
- a
PlayerInfoUpdatePacket
to add the player
-
getRemovePlayerToList
Gets the packet to remove the player from the tab-list.- Returns:
- a
PlayerInfoRemovePacket
to remove the player
-
showPlayer
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
Description copied from interface:EquipmentHandler
Gets theItemStack
in main hand.- Specified by:
getItemInMainHand
in interfaceEquipmentHandler
- Overrides:
getItemInMainHand
in classLivingEntity
- Returns:
- the
ItemStack
in main hand
-
setItemInMainHand
Description copied from interface:EquipmentHandler
Changes the main handItemStack
.- Specified by:
setItemInMainHand
in interfaceEquipmentHandler
- Overrides:
setItemInMainHand
in classLivingEntity
- Parameters:
itemStack
- the main handItemStack
-
getItemInOffHand
Description copied from interface:EquipmentHandler
Gets theItemStack
in off hand.- Specified by:
getItemInOffHand
in interfaceEquipmentHandler
- Overrides:
getItemInOffHand
in classLivingEntity
- Returns:
- the item in off hand
-
setItemInOffHand
Description copied from interface:EquipmentHandler
Changes the off handItemStack
.- Specified by:
setItemInOffHand
in interfaceEquipmentHandler
- Overrides:
setItemInOffHand
in classLivingEntity
- Parameters:
itemStack
- the off handItemStack
-
getHelmet
Description copied from interface:EquipmentHandler
Gets the helmet.- Specified by:
getHelmet
in interfaceEquipmentHandler
- Overrides:
getHelmet
in classLivingEntity
- Returns:
- the helmet
-
setHelmet
Description copied from interface:EquipmentHandler
Changes the helmet.- Specified by:
setHelmet
in interfaceEquipmentHandler
- Overrides:
setHelmet
in classLivingEntity
- Parameters:
itemStack
- the helmet
-
getChestplate
Description copied from interface:EquipmentHandler
Gets the chestplate.- Specified by:
getChestplate
in interfaceEquipmentHandler
- Overrides:
getChestplate
in classLivingEntity
- Returns:
- the chestplate
-
setChestplate
Description copied from interface:EquipmentHandler
Changes the chestplate.- Specified by:
setChestplate
in interfaceEquipmentHandler
- Overrides:
setChestplate
in classLivingEntity
- Parameters:
itemStack
- the chestplate
-
getLeggings
Description copied from interface:EquipmentHandler
Gets the leggings.- Specified by:
getLeggings
in interfaceEquipmentHandler
- Overrides:
getLeggings
in classLivingEntity
- Returns:
- the leggings
-
setLeggings
Description copied from interface:EquipmentHandler
Changes the leggings.- Specified by:
setLeggings
in interfaceEquipmentHandler
- Overrides:
setLeggings
in classLivingEntity
- Parameters:
itemStack
- the leggings
-
getBoots
Description copied from interface:EquipmentHandler
Gets the boots.- Specified by:
getBoots
in interfaceEquipmentHandler
- Overrides:
getBoots
in classLivingEntity
- Returns:
- the boots
-
setBoots
Description copied from interface:EquipmentHandler
Changes the boots.- Specified by:
setBoots
in interfaceEquipmentHandler
- Overrides:
setBoots
in classLivingEntity
- Parameters:
itemStack
- the boots
-
getLocale
Description copied from interface:Localizable
Gets the locale.- Specified by:
getLocale
in interfaceLocalizable
- Returns:
- the locale, or
null
if they do not have a locale set
-
updateSnapshot
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 storeupdater
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 interfaceSnapshotable
- Overrides:
updateSnapshot
in classEntity
- Parameters:
updater
- the snapshot updater/context- Returns:
- the updated snapshot
-
setLocale
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 interfaceLocalizable
- Parameters:
locale
- the new locale
-
identity
- Specified by:
identity
in interfaceIdentified
-
pointers
-
setUuid
Description copied from class:Entity
Changes the internal entity UUID, mostly unsafe. -
sendChunkUpdates
-
teleport
@NotNull public @NotNull CompletableFuture<Void> teleport(@NotNull @NotNull Pos position, long @Nullable [] chunks, int flags) Description copied from class:Entity
Teleports the entity only if the chunk atposition
is loaded or ifInstance.hasEnabledAutoChunkLoad()
returns true.- Overrides:
teleport
in classEntity
- Parameters:
position
- the teleport positionchunks
- the chunk indexes to load before teleporting the entity, indexes are fromChunkUtils.getChunkIndex(int, int)
, can be null or empty to only load the chunk atposition
flags
- flags used to teleport the entity relatively rather than absolutely useRelativeFlags
to see available flags- See Also:
-
callItemUpdateStateEvent(Hand)
instead