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 static final PointersSupplier<Player> protected final PlayerConnectionFields inherited from class LivingEntity
canPickupItem, expandedBoundingBox, invulnerable, isDead, itemPickupCooldown, lastDamage, PROTECTED_MODIFIERSFields inherited from class Entity
boundingBox, collidesWithEntities, currentChunk, ENTITY_POINTERS_SUPPLIER, entityMeta, entityType, gravityTickCount, hasPhysics, headRotation, instance, lastSyncedPosition, lastVelocityWasZero, metadata, onGround, position, preventBlockPlacement, previousPosition, removed, trackingUpdate, vehicle, velocity, viewEngine, viewers -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAcquirable<? extends Player> Obtains anAcquirable.voidaddPacketToQueue(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.voidvoidvoidvoidvoidCloses the current inventory if there is any.voidcloseInventory(boolean fromClient, byte windowId) booleanbooleanUsed internally to determine when sending the close inventory packet should be skipped.booleanCalls anItemDropEventwith a specified item.intGets the client's 'effective' view distance, which is the minimum of the client's view distance settings, and the local instance settings, plus onevoidfacePosition(Player.FacePoint facePoint, Point targetPosition) Rotates the player to facetargetPosition.voidfacePosition(Player.FacePoint facePoint, Entity entity, Player.FacePoint targetPoint) Rotates the player to faceentity.floatGets the player additional hearts.protected PlayerInfoUpdatePacketGets the packet to add the player from the tab-list.longGets the amount of ticks which have passed since the player started using an item.Gets the player dimension.Gets the player display name in the tab-list.getEquipment(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).Gets 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.getName()Gets the player's name as a component.intGets the player open inventory.intGets the player permission level.Gets the player connection.Gets the entity meta for the player.intprotected PlayerInfoRemovePacketGets the packet to remove the player from the tab-list.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.Used to retrieve the default spawn point.Gets the player settings.getSkin()Gets the player skin.This is the map used to send the statistic packet.Gets the player's username.booleanGets if the player has the reduced debug screen.voidhideBossBar(BossBar bar) inputs()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(UUID id, ResourcePackStatus status) voidbooleanopenInventory(Inventory inventory) Opens the specified Inventory, close the previous inventory if existing.voidplayEffect(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(Sound sound, Sound.Emitter emitter) voidpointers()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(UUID id, UUID... others) voidvoidrespawn()Respawns the player by sending aRespawnPacketto the player and teleporting him togetRespawnPoint().voidsendActionBar(Component message) voidQueues the given chunk to be sent to the player.protected voidsendChunkUpdates(Chunk newChunk) protected voidsendDimension(RegistryKey<DimensionType> dimensionType, String dimensionName) Changes the dimension of the player.voidsendMessage(Identity source, Component message, MessageType type) voidsendNotification(Notification notification) Send aNotificationto the player.voidsendPacket(SendablePacket packet) Shortcut forPlayerConnection.sendPacket(SendablePacket).voidsendPackets(Collection<SendablePacket> packets) voidsendPackets(SendablePacket... packets) voidSends a packet to all viewers and the viewable element if it is a player.voidsendPlayerListHeaderAndFooter(Component header, Component footer) voidsendPluginMessage(String channel, byte[] data) Sends a plugin message to the player.voidsendPluginMessage(String channel, String message) Sends a plugin message to the player.voidsendResourcePacks(ResourcePackRequest request) <T> voidsendTitlePart(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(String dimension, Pos position) voidsetDeathLocation(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(EquipmentSlot slot, 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(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(Instance instance) Changes the player instance without changing its position (defaulted togetRespawnPoint()if the player is not in any instance).setInstance(Instance instance, 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(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(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(BossBar bar) voidshowDialog(DialogLike dialog) protected voidshowPlayer(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 to the configuration state at the end of the current tick.voidvoidResets the camera at the player.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 voidupdateSnapshot(SnapshotUpdater updater) Updates the currently cached snapshot if required.Methods inherited from class 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 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, getHeadRotation, 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, identity, 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, setView, spawn, switchEntityType, synchronizeNextTick, synchronizePosition, tagHandler, teleport, teleport, teleport, teleport, teleport, tick, triggerStatus, updateOldViewer, updateViewableRule, updateViewableRule, updateViewerRule, updateViewerRuleMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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, stopSoundMethods inherited from interface CommandSender
sendMessage, sendMessageMethods inherited from interface DataComponent.Holder
get, hasMethods inherited from interface EquipmentHandler
getBodyEquipment, getBoots, getChestplate, getEquipmentsPacket, getHelmet, getItemInHand, getItemInMainHand, getItemInOffHand, getLeggings, hasEquipment, setBodyEquipment, setBoots, setChestplate, setHelmet, setItemInHand, setItemInMainHand, setItemInOffHand, setLeggings, syncEquipment, syncEquipmentMethods inherited from interface HoverEventSource
asHoverEventMethods inherited from interface Identified
identityMethods inherited from interface NamedAndIdentified
getUuidMethods inherited from interface Pointered
get, getOrDefault, getOrDefaultFromMethods inherited from interface Shape
intersectEntity, isFaceFullMethods inherited from interface Taggable
getAndSetTag, getAndUpdateTag, getTag, hasTag, removeTag, setTag, tagHandler, updateAndGetTag, updateTagMethods inherited from interface Viewable
getViewersAsAudience, getViewersAsAudiences, isViewer, sendPacketsToViewers, sendPacketsToViewers, sendPacketToViewers
-
Field Details
-
PLAYER_POINTERS_SUPPLIER
-
playerConnection
-
clickPreprocessor
-
inventory
-
experiencePickupCooldown
-
-
Constructor Details
-
Player
-
-
Method Details
-
setPendingOptions
-
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 to the configuration state at the end of the current tick.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. This may only be used as a delta and has no meaning in the real world
-
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
-
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
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
-
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
- Specified by:
sendMessagein interfaceAudience
-
sendPluginMessage
Sends a plugin message to the player.- Parameters:
channel- the message channeldata- the message data
-
sendPluginMessage
-
playSound
-
playSound
-
playSound
-
playSound
-
stopSound
-
playEffect
public void playEffect(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
-
showDialog
- Specified by:
showDialogin interfaceAudience
-
closeDialog
public void closeDialog()- Specified by:
closeDialogin interfaceAudience
-
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
-
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
-
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
- 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
-
facePosition
Rotates the player to facetargetPosition.- Parameters:
facePoint- the point from where the player should aimtargetPosition- the target position to face
-
facePosition
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
-
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
-
setGameMode
-
sendDimension
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
-
didCloseInventory
public boolean didCloseInventory()Used internally to determine when sending the close inventory packet should be skipped. -
UNSAFE_changeDidCloseInventory
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
-
lookAt
-
lookAt
-
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
-
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
- 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
- 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
-
pointers
-
updateCollisions
protected void updateCollisions()- Overrides:
updateCollisionsin classEntity
-
sendChunkUpdates
-
teleport
-
sendNotification
Send aNotificationto the player.- Parameters:
notification- theNotificationto send
-
leaveBed
public void leaveBed()Sends aEntityAnimationPacketto clear remove the sleep darkness.- Overrides:
leaveBedin classLivingEntity
-
effectiveViewDistance
public int effectiveViewDistance()Gets the client's 'effective' view distance, which is the minimum of the client's view distance settings, and the local instance settings, plus one- Returns:
- The effective chunk view distance range of the client
-
acquirable
Description copied from interface:AcquirableSourceObtains anAcquirable. To safely perform operations on this object, the user must callAcquirable.sync(Consumer),Acquirable.applySync(Function), 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
-