Class Player
- All Implemented Interfaces:
Audience
,Identified
,Pointered
,Sound.Emitter
,HoverEventSource<HoverEvent.ShowEntity>
,Localizable
,Shape
,CommandSender
,EventHandler<EntityEvent>
,EquipmentHandler
,PermissionHandler
,Snapshotable
,Taggable
,TagReadable
,TagWritable
,AcquirableSource<Entity>
,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
protected PlayerInventory
protected final PlayerConnection
Fields inherited from class net.minestom.server.entity.LivingEntity
canPickupItem, expandedBoundingBox, invulnerable, isDead, itemPickupCooldown, lastDamage, PROTECTED_MODIFIERS
Fields inherited from class net.minestom.server.entity.Entity
boundingBox, collidesWithEntities, currentChunk, entityMeta, entityType, gravityTickCount, hasPhysics, instance, lastSyncedPosition, lastVelocityWasZero, metadata, onGround, position, preventBlockPlacement, previousPosition, removed, trackingUpdate, vehicle, velocity, viewEngine, viewers
-
Constructor Summary
ConstructorDescriptionPlayer
(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) -
Method Summary
Modifier and TypeMethodDescription@NotNull Acquirable
<? extends Player> Obtains anAcquirable
.void
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) asPlayer()
Casts this object to aPlayer
.@NotNull ItemUpdateStateEvent
callItemUpdateStateEvent
(@NotNull Player.Hand hand) Used to callItemUpdateStateEvent
with the proper item It does check which hand to get the item to update.void
void
void
void
Closes the current inventory if there is any.void
closeInventory
(boolean fromClient) boolean
boolean
Used internally to determine when sending the close inventory packet should be skipped.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.long
Gets the amount of ticks which have passed since the player started using an item.@Nullable WorldPos
Gets the player dimension.@Nullable Component
Gets the player display name in the tab-list.@NotNull ItemStack
getEquipment
(@NotNull EquipmentSlot slot) Gets the equipment in a specific slot.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 PlayerInventory
@Nullable Player.Hand
Gets the hand which the player is using an item from.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.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.@NotNull PlayerMeta
Gets the entity meta for the player.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 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
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
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.boolean
isPlayer()
Gets if the sender is aPlayer
.boolean
Gets if the player is using an item.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
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 item usage ifisUsingItem()
was true.void
refreshItemUse
(@Nullable Player.Hand itemUseHand, long itemUseTimeTicks) 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
(DynamicRegistry.Key<DimensionType> dimensionType, @NotNull String dimensionName) Changes the dimension of the player.void
sendMessage
(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) 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
setDeathLocation
(@NotNull String dimension, @NotNull Pos position) void
setDeathLocation
(@NotNull Pos position) 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
setEquipment
(@NotNull EquipmentSlot slot, @NotNull ItemStack itemStack) 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.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
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
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> void
UNSAFE_changeDidCloseInventory
(boolean didCloseInventory) Used internally to reset the skipClosePacket field, which determines when sending the close inventory packet should be skipped.Used when the player is created.void
update
(long time) Called each tick.protected void
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, getAttributes, getAttributeValue, getFireTicks, getHealth, getLastDamageSource, getLivingEntityMeta, getPropertiesPacket, getTargetBlockPosition, getTeam, heal, isDead, isFlyingWithElytra, onAttributeChanged, refreshActiveHand, refreshIsDead, setArrowCount, setBoundingBox, setCanPickupItem, setFireTicks, setFlyingWithElytra, setSprinting, setTeam, swingMainHand, swingMainHand, swingOffHand, swingOffHand, takeKnockback, updateEquipmentAttributes, 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, getEntityId, getEntityMeta, getEntityType, getGravityTickCount, getInstance, getLeashedEntities, getLeashHolder, getLineOfSight, getLineOfSightEntity, getMetadataPacket, getPassengers, getPassengersPacket, getPose, getPosition, getPreviousPosition, getSynchronizationTicks, getUuid, getVehicle, getVelocity, getVelocityForPacket, getVelocityPacket, getViewers, hasEffect, hasEntityCollision, hasLineOfSight, hasLineOfSight, hasNoGravity, hasPassenger, hasPredictableViewers, hasVelocity, intersectBox, intersectBoxSwept, isActive, isAutoViewable, isCustomNameVisible, isGlowing, isInvisible, isOccluded, isOnFire, isRemoved, isSilent, isSneaking, isSprinting, movementTick, preventBlockPlacement, 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, setPose, setSilent, setSynchronizationTicks, setVelocity, spawn, switchEntityType, synchronizeNextTick, synchronizePosition, tagHandler, teleport, teleport, tick, triggerStatus, updateOldViewer, 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, 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
asConsole, isConsole, sendMessage, sendMessage
Methods inherited from interface net.minestom.server.inventory.EquipmentHandler
getBodyEquipment, getBoots, getChestplate, getEquipmentsPacket, getHelmet, getItemInHand, getItemInMainHand, getItemInOffHand, getLeggings, hasEquipment, setBodyEquipment, setBoots, setChestplate, setHelmet, setItemInHand, setItemInMainHand, setItemInOffHand, setLeggings, 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
getAndSetTag, getAndUpdateTag, getTag, hasTag, removeTag, setTag, tagHandler, updateAndGetTag, updateTag
Methods inherited from interface net.minestom.server.Viewable
getViewersAsAudience, getViewersAsAudiences, isViewer, sendPacketsToViewers, sendPacketsToViewers, sendPacketToViewers
-
Field Details
-
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) -
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
-
sendMessage
public void sendMessage(@NotNull @NotNull Identity source, @NotNull @NotNull Component message, @NotNull @NotNull MessageType type) - Specified by:
sendMessage
in interfaceAudience
-
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
-
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
-
getPlayerMeta
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
-
isUsingItem
public boolean isUsingItem()Gets if the player is using an item.- Returns:
- true if the player is using an item, false otherwise
-
getItemUseHand
Gets the hand which the player is using an item from.- Returns:
- the item use hand, null if none
-
getCurrentItemUseTime
public long getCurrentItemUseTime()Gets the amount of ticks which have passed since the player started using an item.- Returns:
- the amount of ticks which have passed, or zero if the player is not using an item
-
getEyeHeight
public double getEyeHeight()Description copied from class:Entity
Gets the entity eye height.- 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
-
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)
-
sendDimension
protected void sendDimension(@NotNull DynamicRegistry.Key<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 determine when sending the close inventory packet should be skipped. -
UNSAFE_changeDidCloseInventory
@Internal public void UNSAFE_changeDidCloseInventory(boolean didCloseInventory) Used internally to reset the skipClosePacket field, which determines when sending the close inventory packet should be skipped.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 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 item usage ifisUsingItem()
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
-
refreshItemUse
-
clearItemUse
public void clearItemUse() -
callItemUpdateStateEvent
@NotNull public @NotNull ItemUpdateStateEvent callItemUpdateStateEvent(@NotNull @NotNull Player.Hand hand) Used to callItemUpdateStateEvent
with the proper item It does check which hand to get the item to update.- Returns:
- the called
ItemUpdateStateEvent
,
-
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
-
getEquipment
Description copied from interface:EquipmentHandler
Gets the equipment in a specific slot.- Specified by:
getEquipment
in interfaceEquipmentHandler
- Overrides:
getEquipment
in classLivingEntity
- Parameters:
slot
- the equipment to get the item from- Returns:
- the equipment
ItemStack
-
setEquipment
public void setEquipment(@NotNull @NotNull EquipmentSlot slot, @NotNull @NotNull ItemStack itemStack) - Specified by:
setEquipment
in interfaceEquipmentHandler
- Overrides:
setEquipment
in classLivingEntity
-
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
-
isPlayer
public boolean isPlayer()Description copied from interface:CommandSender
Gets if the sender is aPlayer
.Consider using
instanceof
instead.- Specified by:
isPlayer
in interfaceCommandSender
- Returns:
- true if 'this' is a player, false otherwise
-
asPlayer
Description copied from interface:CommandSender
Casts this object to aPlayer
. No checks are performed,ClassCastException
can very much happen.- Specified by:
asPlayer
in interfaceCommandSender
- See Also:
-
updateCollisions
protected void updateCollisions()- Overrides:
updateCollisions
in classEntity
-
sendChunkUpdates
-
teleport
@NotNull public @NotNull CompletableFuture<Void> teleport(@NotNull @NotNull Pos position, long @Nullable [] chunks, int flags) -
acquirable
Description copied from interface:AcquirableSource
Obtains anAcquirable
. To safely perform operations on this object, the user must callAcquirable.sync(Consumer)
,Acquirable.async(Consumer)
, orAcquirable.lock()
(followed by a subsequent unlock) on the Acquirable instance.- Specified by:
acquirable
in interfaceAcquirableSource<Entity>
- Overrides:
acquirable
in classLivingEntity
- Returns:
- an Acquirable which can be used to synchronize access to this object
-