Class Player
- All Implemented Interfaces:
Audience,Identified,Pointered,Sound.Emitter,HoverEventSource<HoverEvent.ShowEntity>,Shape,CommandSender,DataComponent.Holder,EventHandler<EntityEvent>,EquipmentHandler,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
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ClickPreprocessorprotected Cooldownprotected PlayerInventoryprotected final PlayerConnectionFields inherited from class net.minestom.server.entity.LivingEntity
canPickupItem, expandedBoundingBox, invulnerable, isDead, itemPickupCooldown, lastDamage, PROTECTED_MODIFIERSFields 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
ConstructorsConstructorDescriptionPlayer(@NotNull PlayerConnection playerConnection, @NotNull GameProfile gameProfile) -
Method Summary
Modifier and TypeMethodDescription@NotNull Acquirable<? extends Player> Obtains anAcquirable.voidaddPacketToQueue(@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) voidvoidvoidvoidCloses the current inventory if there is any.voidcloseInventory(boolean fromClient) booleanbooleanUsed internally to determine when sending the close inventory packet should be skipped.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 ClickPreprocessorlongGets the amount of ticks which have passed since the player started using an item.@Nullable WorldPosGets the player dimension.@Nullable ComponentGets the player display name in the tab-list.@NotNull ItemStackgetEquipment(@NotNull EquipmentSlot slot) Gets the equipment in a specific slot.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 PlayerInventory@Nullable PlayerHandGets the hand which the player is using an item from.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.intgetLevel()Gets the level of the player displayed in the experience bar.@NotNull ComponentgetName()Gets the player's name as a component.int@Nullable AbstractInventoryGets the player open inventory.intGets the player permission level.@NotNull PlayerConnectionGets the player connection.@NotNull PlayerMetaGets the entity meta for the player.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 ClientSettingsGets the player settings.@Nullable PlayerSkingetSkin()Gets the player skin.@NotNull Map<PlayerStatistic, Integer> This is the map used to send the statistic packet.@NotNull StringGets the player's username.booleanGets if the player has the reduced debug screen.voidhideBossBar(@NotNull BossBar bar) @NotNull Identityidentity()@NotNull PlayerInputsinputs()Gets the last reported set of player inputs.voidbooleanGets if the player is allowed to fly.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.booleanbooleanbooleanisOnline()Gets if the player is online or not.booleanGets if the player is using an item.voidKicks the player with a reason.voidKicks the player with a reason.voidkill()Kills the entity, trigger theEntityDeathEventevent.voidleaveBed()Sends aEntityAnimationPacketto clear remove the sleep darkness.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 WorldEvent worldEvent, int x, int y, int z, int data, boolean disableRelativeVolume) Plays a given worldEvent 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.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 item usage ifisUsingItem()was true.voidrefreshInput(boolean forward, boolean backward, boolean left, boolean right, boolean jump, boolean shift, boolean sprint) voidrefreshItemUse(@Nullable PlayerHand itemUseHand, long itemUseTimeTicks) 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) voidRefreshes the recipes and recipe book for this player, testing recipe predicates again.voidrefreshSettings(ClientSettings settings) Changes the player settings internally.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 RegistryKey<DimensionType> dimensionType, @NotNull String dimensionName) Changes the dimension of the player.voidsendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) voidsendNotification(@NotNull Notification notification) Send aNotificationto the player.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.voidsetDeathLocation(@NotNull String dimension, @NotNull Pos position) voidsetDeathLocation(@NotNull Pos position) voidsetDisplayName(@Nullable Component displayName) Changes the player display name in the tab-list.voidsetEnableRespawnScreen(boolean enableRespawnScreen) Enables or disable the respawn screen.voidsetEquipment(@NotNull EquipmentSlot slot, @NotNull ItemStack itemStack) 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.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.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.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> voidUNSAFE_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.voidupdate(long time) Called each tick.protected voidprotected 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, enterBed, getArrowCount, getAttribute, getAttributes, getAttributeValue, getFireTicks, getHealth, getLastDamageSource, getLivingEntityMeta, getPropertiesPacket, getTargetBlockPosition, getTeam, heal, isDead, isFlyingWithElytra, isImmune, isInvulnerable, onAttributeChanged, refreshActiveHand, refreshIsDead, setArrowCount, setBoundingBox, setCanPickupItem, setFireTicks, setFlyingWithElytra, setSprinting, setTeam, shouldSendAttributes, swingMainHand, swingMainHand, swingOffHand, swingOffHand, takeKnockback, updateEquipmentAttributes, updateNewViewerMethods inherited from class net.minestom.server.entity.Entity
addEffect, addPassenger, addViewer, autoViewEntities, clearEffects, despawn, editEntityMeta, eventNode, generateId, get, getAcquirable, getActiveEffects, getAerodynamics, getAliveTicks, 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, getSpawnPacket, 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, set, setAerodynamics, setAutoViewable, setAutoViewEntities, setBoundingBox, setCustomName, setCustomNameVisible, setGlowing, setInstance, setInvisible, setLeashHolder, setNoGravity, setPose, setPositionInternal, setSilent, setSynchronizationTicks, setVelocity, spawn, switchEntityType, synchronizeNextTick, synchronizePosition, tagHandler, teleport, teleport, teleport, teleport, teleport, tick, triggerStatus, updateOldViewer, 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, removeResourcePacks, sendActionBar, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendMessage, sendPlayerListFooter, sendPlayerListFooter, sendPlayerListHeader, sendPlayerListHeader, sendPlayerListHeaderAndFooter, sendResourcePacks, sendResourcePacks, showDialog, showTitle, stopSoundMethods inherited from interface net.minestom.server.command.CommandSender
sendMessage, sendMessageMethods inherited from interface net.minestom.server.component.DataComponent.Holder
get, hasMethods 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, 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.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
getAndSetTag, getAndUpdateTag, getTag, hasTag, removeTag, setTag, tagHandler, updateAndGetTag, updateTagMethods inherited from interface net.minestom.server.Viewable
getViewersAsAudience, getViewersAsAudiences, isViewer, sendPacketsToViewers, sendPacketsToViewers, sendPacketToViewers
-
Field Details
-
playerConnection
-
clickPreprocessor
-
inventory
-
experiencePickupCooldown
-
-
Constructor Details
-
Player
public Player(@NotNull @NotNull PlayerConnection playerConnection, @NotNull @NotNull GameProfile gameProfile)
-
-
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. -
refreshRecipes
public void refreshRecipes()Refreshes the recipes and recipe book for this player, testing recipe predicates again. -
isOnGround
public boolean isOnGround()- Overrides:
isOnGroundin classEntity
-
remove
public void remove(boolean permanent) -
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
-
sendMessage
public void sendMessage(@NotNull @NotNull Identity source, @NotNull @NotNull Component message, @NotNull @NotNull MessageType type) - Specified by:
sendMessagein 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 WorldEvent worldEvent, int x, int y, int z, int data, boolean disableRelativeVolume) Plays a given worldEvent at the given position for this player.- Parameters:
worldEvent- the worldEvent to playx- x position of the worldEventy- y position of the worldEventz- z position of the worldEventdata- data for the worldEventdisableRelativeVolume- 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
-
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
-
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- 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
-
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:EntityGets the entity eye height.- 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
-
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
-
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
-
refreshSettings
Changes the player settings internally.WARNING: the player will not be noticed by this change, probably unsafe.
-
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)
-
sendDimension
protected void sendDimension(@NotNull @NotNull RegistryKey<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
-
getClickPreprocessor
-
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- 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
-
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
-
inputs
Gets the last reported set of player inputs.This information comes from the client so should be considered as such.
-
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 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() -
refreshInput
public void refreshInput(boolean forward, boolean backward, boolean left, boolean right, boolean jump, boolean shift, boolean sprint) -
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
-
getEquipment
Description copied from interface:EquipmentHandlerGets the equipment in a specific slot.- Specified by:
getEquipmentin interfaceEquipmentHandler- Overrides:
getEquipmentin 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:
setEquipmentin interfaceEquipmentHandler- Overrides:
setEquipmentin classLivingEntity
-
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
-
getLocale
-
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.- Parameters:
locale- the new locale
-
identity
- Specified by:
identityin interfaceIdentified
-
pointers
-
updateCollisions
protected void updateCollisions()- Overrides:
updateCollisionsin classEntity
-
sendChunkUpdates
-
teleport
@NotNull public @NotNull CompletableFuture<Void> teleport(@NotNull @NotNull Pos position, long @Nullable [] chunks, int flags) -
sendNotification
Send aNotificationto the player.- Parameters:
notification- theNotificationto send
-
leaveBed
public void leaveBed()Sends aEntityAnimationPacketto clear remove the sleep darkness.- Overrides:
leaveBedin classLivingEntity
-
acquirable
Description copied from interface:AcquirableSourceObtains anAcquirable. To safely perform operations on this object, the user must callAcquirable.sync(Consumer)orAcquirable.lock()(followed by a subsequent unlock) on the Acquirable instance.- Specified by:
acquirablein interfaceAcquirableSource<Entity>- Overrides:
acquirablein classLivingEntity- Returns:
- an Acquirable which can be used to synchronize access to this object
-