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
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enumRepresents the main or off hand of the player.static enumRepresents where is located the main hand of the player (can be changed in Minecraft option).classNested classes/interfaces inherited from class net.minestom.server.entity.Entity
Entity.Pose -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Cooldownstatic final booleanprotected PlayerInventoryprotected final PlayerConnectionFields inherited from class net.minestom.server.entity.LivingEntity
canPickupItem, expandedBoundingBox, invulnerable, isDead, itemPickupCooldown, lastDamageFields 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
ConstructorsConstructorDescriptionPlayer(@NotNull UUID uuid, @NotNull String username, @NotNull PlayerConnection playerConnection) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPacketToQueue(@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 ItemUpdateStateEventcallItemUpdateStateEvent(boolean allowFood, @Nullable Player.Hand hand) Deprecated.@Nullable ItemUpdateStateEventcallItemUpdateStateEvent(@Nullable Player.Hand hand) Used to callItemUpdateStateEventwith the proper item It does check which hand to get the item to update.voidvoidvoidCloses the current inventory if there is any.voidcloseInventory(boolean fromClient) booleanbooleanUsed internally to prevent an inventory click to be processed when the inventory listeners closed the inventory.booleanCalls anItemDropEventwith a specified item.voidfacePosition(@NotNull Player.FacePoint facePoint, @NotNull Point targetPosition) Rotates the player to facetargetPosition.voidfacePosition(@NotNull Player.FacePoint facePoint, Entity entity, Player.FacePoint targetPoint) Rotates the player to faceentity.floatGets the player additional hearts.protected @NotNull PlayerInfoUpdatePacketGets the packet to add the player from the tab-list.@NotNull ItemStackgetBoots()Gets the boots.@NotNull ItemStackGets the chestplate.@Nullable WorldPoslongGets the player default eating time.Gets the player dimension.@Nullable ComponentGets the player display name in the tab-list.@Nullable Player.HandGets the hand which the player is eating from.floatgetExp()Gets the percentage displayed in the experience bar.doubleGets the entity eye height.floatfloatGets the player flying speed.intgetFood()Gets the player food.floatGets the playerGameMode.byteGets the player held slot (0-8).@NotNull ItemStackGets the helmet.@NotNull PlayerInventory@NotNull ItemStackGets theItemStackin main hand.@NotNull ItemStackGets theItemStackin off hand.longGets the last sent keep alive id.intintintUsed to get the player latency, computed by seeing how long it takes the client to answer theKeepAlivePacketpacket.@NotNull ItemStackGets the leggings.intgetLevel()Gets the level of the player displayed in the experience bar.Gets the locale.@NotNull ComponentgetName()Gets the player's name as a component.int@Nullable InventoryGets the player open inventory.intGets the player permission level.@NotNull PlayerConnectionGets the player connection.intprotected @NotNull PlayerInfoRemovePacketGets 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 PosUsed to retrieve the default spawn point.@NotNull Player.PlayerSettingsGets the player settings.@Nullable PlayerSkingetSkin()Gets the player skin.@NotNull Map<PlayerStatistic, Integer> This is the map used to send the statistic packet.@NotNull PlayerMetaGets the entity meta for the player.@NotNull StringGets the player's username.@NotNull PlayerVehicleInformationGets the player vehicle information.booleanGets if the player has the reduced debug screen.voidhideBossBar(@NotNull BossBar bar) @NotNull Identityidentity()voidbooleanGets if the player is allowed to fly.booleanGets if this player is in creative.booleanisEating()Gets if the player is eating.booleanGets if the player has the respawn screen enabled or disabled.booleanisFlying()Gets if the player is currently flying.booleanisImmune(@NotNull DamageType type) Is this entity immune to the given type of damage?booleanbooleanThe invulnerable field appear in thePlayerAbilitiesPacketpacket.booleanbooleanisOnline()Gets if the player is online or not.voidKicks the player with a reason.voidKicks the player with a reason.voidkill()Kills the entity, trigger theEntityDeathEventevent.voidForces the player's client to look towards the specified pointvoidForces the player's client to look towards the specified entityvoidonChunkBatchReceived(float newTargetChunksPerTick) voidonResourcePackStatus(@NotNull UUID id, @NotNull ResourcePackStatus status) voidbooleanopenInventory(@NotNull Inventory inventory) Opens the specified Inventory, close the previous inventory if existing.voidplayEffect(@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 voidUsed to initialize the player connectionvoidvoidvoidplaySound(@NotNull Sound sound, @NotNull Sound.Emitter emitter) void@NotNull Pointerspointers()protected voidSends to the player aPlayerAbilitiesPacketwith all the updated fields.protected voidCalled after the player teleportation to refresh his position and send data to his new viewers.voidrefreshAnswerKeepAlive(boolean answerKeepAlive) voidRefreshes the command list for this player.voidrefreshEating(@Nullable Player.Hand eatingHand) voidrefreshEating(@Nullable Player.Hand eatingHand, long eatingTime) voidrefreshFlying(boolean flying) Updates the internal flying field.protected voidSets the player food and health values to their maximum.voidrefreshHeldSlot(byte slot) Changes the held item for the player viewers Also cancel eating ifisEating()was true.voidrefreshKeepAlive(long lastKeepAlive) Used to change internally the last sent last keep alive id.voidrefreshLatency(int latency) Changes the storage player latency and update its tab value.voidrefreshOnGround(boolean onGround) voidrefreshReceivedTeleportId(int receivedTeleportId) voidrefreshVehicleSteer(float sideways, float forward, boolean jump, boolean unmount) voidremove(boolean permanent) voidremoveResourcePacks(@NotNull UUID id, @NotNull UUID @NotNull ... others) voidvoidrespawn()Respawns the player by sending aRespawnPacketto the player and teleporting him togetRespawnPoint().voidsendActionBar(@NotNull Component message) voidQueues the given chunk to be sent to the player.protected voidsendChunkUpdates(Chunk newChunk) protected voidsendDimension(@NotNull DimensionType dimensionType, @NotNull String dimensionName) Changes the dimension of the player.voidsendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) Deprecated.voidsendPacket(@NotNull SendablePacket packet) Shortcut forPlayerConnection.sendPacket(SendablePacket).voidsendPackets(@NotNull Collection<SendablePacket> packets) voidsendPackets(@NotNull SendablePacket... packets) voidsendPacketToViewersAndSelf(@NotNull SendablePacket packet) Sends a packet to all viewers and the viewable element if it is a player.voidsendPlayerListHeaderAndFooter(@NotNull Component header, @NotNull Component footer) voidsendPluginMessage(@NotNull String channel, byte @NotNull [] data) Sends a plugin message to the player.voidsendPluginMessage(@NotNull String channel, @NotNull String message) Sends a plugin message to the player.voidsendResourcePacks(@NotNull ResourcePackRequest request) <T> voidsendTitlePart(@NotNull TitlePart<T> part, T value) voidsetAdditionalHearts(float additionalHearts) Changes the amount of additional hearts shown.voidsetAllowFlying(boolean allowFlying) Allows or forbid the player to fly.voidsetBelowNameTag(BelowNameTag belowNameTag) Changes the tag below the name.voidChanges the boots.voidsetChestplate(@NotNull ItemStack itemStack) Changes the chestplate.voidsetDeathLocation(@NotNull DimensionType type, @NotNull Pos position) voidsetDefaultEatingTime(long defaultEatingTime) Used to change the default eating time animation.voidsetDisplayName(@Nullable Component displayName) Changes the player display name in the tab-list.voidsetEnableRespawnScreen(boolean enableRespawnScreen) Enables or disable the respawn screen.voidsetExp(float exp) Used to change the percentage experience bar.voidsetFieldViewModifier(float fieldViewModifier) voidsetFlying(boolean flying) Sets the player flying.voidsetFlyingSpeed(float flyingSpeed) Updates the internal field and send aPlayerAbilitiesPacketwith the new flying speed.voidsetFood(int food) Sets and refresh client food bar.voidsetFoodSaturation(float foodSaturation) Sets and refresh client food saturation.booleansetGameMode(@NotNull GameMode gameMode) Changes the playerGameModevoidsetHealth(float health) Changes the entity health, kill it ifhealthis <= 0 and is not dead yet.voidsetHeldItemSlot(byte slot) Changes the current held slot for the player.voidChanges 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.voidsetInstantBreak(boolean instantBreak) Changes the player ability "Creative Mode".voidsetInvulnerable(boolean invulnerable) This do update theinvulnerablefield in the packetPlayerAbilitiesPacketand prevent the player from receiving damage.voidsetItemInMainHand(@NotNull ItemStack itemStack) Changes the main handItemStack.voidsetItemInOffHand(@NotNull ItemStack itemStack) Changes the off handItemStack.voidsetLeggings(@NotNull ItemStack itemStack) Changes the leggings.voidsetLevel(int level) Used to change the level of the player This cannot change the displayed percentage bar seesetExp(float)voidSets the player's locale.voidsetPendingOptions(@NotNull Instance pendingInstance, boolean hardcore) voidsetPermissionLevel(int permissionLevel) Changes the player permission level.voidsetPortalCooldown(int portalCooldown) voidsetReducedDebugScreenInformation(boolean reduced) Sets or remove the reduced debug screen.voidsetRespawnPoint(@NotNull Pos respawnPoint) Changes the default spawn point.voidsetSkin(@Nullable PlayerSkin skin) Changes the player skin.voidsetSneaking(boolean sneaking) Makes the entity sneak.voidsetUsernameField(@NotNull String username) Changes the internal player name, used for theAsyncPlayerPreLoginEventmostly unsafe outside of it.voidChanges the internal entity UUID, mostly unsafe.voidsetView(float yaw, float pitch) Forces the player's client to look towards the target yaw/pitchvoidshowBossBar(@NotNull BossBar bar) protected voidshowPlayer(@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).voidSets the camera atentityeyes.voidMoves the player immediately to the configuration state.voidvoidResets the camera at the player.@NotNull CompletableFuture<Void> Teleports the entity only if the chunk atpositionis loaded or ifInstance.hasEnabledAutoChunkLoad()returns true.voidUNSAFE_changeDidCloseInventory(boolean didCloseInventory) Used internally to reset the didCloseInventory field.Used when the player is created.voidupdate(long time) Called each tick.voidupdateOldViewer(@NotNull Player player) Called when a viewer must be destroyed.protected void@NotNull PlayerSnapshotupdateSnapshot(@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, updateNewViewerMethods 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, updateViewerRuleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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, stopSoundMethods inherited from interface net.minestom.server.command.CommandSender
sendMessage, sendMessageMethods inherited from interface net.minestom.server.inventory.EquipmentHandler
getEquipment, getEquipmentsPacket, getItemInHand, hasEquipment, setEquipment, setItemInHand, syncEquipmentMethods inherited from interface net.kyori.adventure.text.event.HoverEventSource
asHoverEventMethods inherited from interface net.minestom.server.utils.identity.NamedAndIdentified
getUuidMethods inherited from interface net.minestom.server.permission.PermissionHandler
addPermission, getAllPermissions, getPermission, hasPermission, hasPermission, hasPermission, removePermission, removePermissionMethods inherited from interface net.kyori.adventure.pointer.Pointered
get, getOrDefault, getOrDefaultFromMethods inherited from interface net.minestom.server.collision.Shape
intersectEntity, isFaceFullMethods inherited from interface net.minestom.server.tag.Taggable
getTag, hasTag, removeTag, setTag, tagHandlerMethods 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:EntityCalled each tick.- Overrides:
updatein classLivingEntity- Parameters:
time- time of the update in milliseconds
-
kill
public void kill()Description copied from class:LivingEntityKills the entity, trigger theEntityDeathEventevent.- Overrides:
killin classLivingEntity
-
respawn
public void respawn()Respawns the player by sending aRespawnPacketto 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 theCommandConditions again, and any changes will be visible to the player. -
isOnGround
public boolean isOnGround()- Overrides:
isOnGroundin classEntity
-
remove
public void remove(boolean permanent) -
updateOldViewer
Description copied from class:EntityCalled when a viewer must be destroyed. Method can be subject to deadlocking if the target's viewers are also accessed.- Overrides:
updateOldViewerin classEntity- Parameters:
player- the player to send the packets to
-
sendPacketToViewersAndSelf
Description copied from interface:ViewableSends 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:
sendPacketToViewersAndSelfin 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:
setInstancein 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:
setInstancein classEntity- Parameters:
instance- the new player instance- Returns:
- a
CompletableFuturecalled 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:
updatePosein 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:
sendMessagein 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:
sendTitlePartin interfaceAudience
-
sendActionBar
- Specified by:
sendActionBarin interfaceAudience
-
resetTitle
public void resetTitle()- Specified by:
resetTitlein interfaceAudience
-
clearTitle
public void clearTitle()- Specified by:
clearTitlein interfaceAudience
-
showBossBar
- Specified by:
showBossBarin interfaceAudience
-
hideBossBar
- Specified by:
hideBossBarin interfaceAudience
-
openBook
-
isImmune
Description copied from class:LivingEntityIs this entity immune to the given type of damage?- Overrides:
isImmunein 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:LivingEntityChanges the entity health, kill it ifhealthis <= 0 and is not dead yet.- Overrides:
setHealthin 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- iffoodis 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- iffoodSaturationis 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:EntityGets the entity eye height.Default to
BoundingBox.height()x0.85- Overrides:
getEyeHeightin 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:
getNamein interfaceNamedAndIdentified- Returns:
- the name
-
getUsername
Gets the player's username.- Returns:
- the player's username
-
setUsernameField
Changes the internal player name, used for theAsyncPlayerPreLoginEventmostly unsafe outside of it.- Parameters:
username- the new player name
-
dropItem
Calls anItemDropEventwith a specified item.Returns false if
itemis air.- Parameters:
item- the item to drop- Returns:
- true if player can drop the item (event not cancelled), false otherwise
-
sendResourcePacks
- Specified by:
sendResourcePacksin interfaceAudience
-
removeResourcePacks
public void removeResourcePacks(@NotNull @NotNull UUID id, @NotNull @NotNull UUID @NotNull ... others) - Specified by:
removeResourcePacksin interfaceAudience
-
clearResourcePacks
public void clearResourcePacks()- Specified by:
clearResourcePacksin 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 atentityposition
-
spectate
Sets the camera atentityeyes.- 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- ifexpis 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 theKeepAlivePacketpacket.- 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- ifslotis 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- ifpermissionLevelis 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 thePlayerAbilitiesPacketpacket.- Overrides:
isInvulnerablein classLivingEntity- Returns:
- true if the player is invulnerable, false otherwise
-
setInvulnerable
public void setInvulnerable(boolean invulnerable) This do update theinvulnerablefield in the packetPlayerAbilitiesPacketand prevent the player from receiving damage.- Overrides:
setInvulnerablein classLivingEntity- Parameters:
invulnerable- should the player be invulnerable
-
setSneaking
public void setSneaking(boolean sneaking) Description copied from class:EntityMakes the entity sneak.WARNING: this will not work for the client itself.
- Overrides:
setSneakingin 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 aPlayerAbilitiesPacketwith 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 aPlayerAbilitiesPacketwith 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 callItemUpdateStateEventwith 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 callItemUpdateStateEventwith 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:
asHoverEventin interfaceHoverEventSource<HoverEvent.ShowEntity>- Overrides:
asHoverEventin classEntity
-
getAddPlayerToList
Gets the packet to add the player from the tab-list.- Returns:
- a
PlayerInfoUpdatePacketto add the player
-
getRemovePlayerToList
Gets the packet to remove the player from the tab-list.- Returns:
- a
PlayerInfoRemovePacketto 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:EquipmentHandlerGets theItemStackin main hand.- Specified by:
getItemInMainHandin interfaceEquipmentHandler- Overrides:
getItemInMainHandin classLivingEntity- Returns:
- the
ItemStackin main hand
-
setItemInMainHand
Description copied from interface:EquipmentHandlerChanges the main handItemStack.- Specified by:
setItemInMainHandin interfaceEquipmentHandler- Overrides:
setItemInMainHandin classLivingEntity- Parameters:
itemStack- the main handItemStack
-
getItemInOffHand
Description copied from interface:EquipmentHandlerGets theItemStackin off hand.- Specified by:
getItemInOffHandin interfaceEquipmentHandler- Overrides:
getItemInOffHandin classLivingEntity- Returns:
- the item in off hand
-
setItemInOffHand
Description copied from interface:EquipmentHandlerChanges the off handItemStack.- Specified by:
setItemInOffHandin interfaceEquipmentHandler- Overrides:
setItemInOffHandin classLivingEntity- Parameters:
itemStack- the off handItemStack
-
getHelmet
Description copied from interface:EquipmentHandlerGets the helmet.- Specified by:
getHelmetin interfaceEquipmentHandler- Overrides:
getHelmetin classLivingEntity- Returns:
- the helmet
-
setHelmet
Description copied from interface:EquipmentHandlerChanges the helmet.- Specified by:
setHelmetin interfaceEquipmentHandler- Overrides:
setHelmetin classLivingEntity- Parameters:
itemStack- the helmet
-
getChestplate
Description copied from interface:EquipmentHandlerGets the chestplate.- Specified by:
getChestplatein interfaceEquipmentHandler- Overrides:
getChestplatein classLivingEntity- Returns:
- the chestplate
-
setChestplate
Description copied from interface:EquipmentHandlerChanges the chestplate.- Specified by:
setChestplatein interfaceEquipmentHandler- Overrides:
setChestplatein classLivingEntity- Parameters:
itemStack- the chestplate
-
getLeggings
Description copied from interface:EquipmentHandlerGets the leggings.- Specified by:
getLeggingsin interfaceEquipmentHandler- Overrides:
getLeggingsin classLivingEntity- Returns:
- the leggings
-
setLeggings
Description copied from interface:EquipmentHandlerChanges the leggings.- Specified by:
setLeggingsin interfaceEquipmentHandler- Overrides:
setLeggingsin classLivingEntity- Parameters:
itemStack- the leggings
-
getBoots
Description copied from interface:EquipmentHandlerGets the boots.- Specified by:
getBootsin interfaceEquipmentHandler- Overrides:
getBootsin classLivingEntity- Returns:
- the boots
-
setBoots
Description copied from interface:EquipmentHandlerChanges the boots.- Specified by:
setBootsin interfaceEquipmentHandler- Overrides:
setBootsin classLivingEntity- Parameters:
itemStack- the boots
-
getLocale
Description copied from interface:LocalizableGets the locale.- Specified by:
getLocalein interfaceLocalizable- Returns:
- the locale, or
nullif they do not have a locale set
-
updateSnapshot
Description copied from interface:SnapshotableUpdates 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 storeupdateranywhere 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:
updateSnapshotin interfaceSnapshotable- Overrides:
updateSnapshotin 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:
setLocalein interfaceLocalizable- Parameters:
locale- the new locale
-
identity
- Specified by:
identityin interfaceIdentified
-
pointers
-
setUuid
Description copied from class:EntityChanges 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:EntityTeleports the entity only if the chunk atpositionis loaded or ifInstance.hasEnabledAutoChunkLoad()returns true.- Overrides:
teleportin 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 atpositionflags- flags used to teleport the entity relatively rather than absolutely useRelativeFlagsto see available flags- See Also:
-
callItemUpdateStateEvent(Hand)instead