API reference / @jsprismarine/prismarine / network/PlayerSession / PlayerSession
Class: PlayerSession
Defined in: prismarine/src/network/PlayerSession.ts:336
Constructors
Constructor
new PlayerSession(
server,connection,player,players,world):PlayerSession
Defined in: prismarine/src/network/PlayerSession.ts:531
Parameters
server
The server the session belongs to.
connection
ClientConnection
The connection it speaks through.
player
SessionPlayerRef
The id and identity of the player it speaks for.
players
SessionPlayers<StorePlayer>
Where the player is filed by that id.
world
The world the login puts the player in, until its record names another.
Returns
PlayerSession
Properties
identity
readonlyidentity:PlayerIdentity
Defined in: prismarine/src/network/PlayerSession.ts:344
Who logged in on this session.
runtimeId
readonlyruntimeId:bigint
Defined in: prismarine/src/network/PlayerSession.ts:341
The player's entity id, as the wire carries it.
Accessors
attributes
Get Signature
get attributes():
Attributes
Defined in: prismarine/src/network/PlayerSession.ts:3327
The client's attribute table: food, experience and the rest, and a copy of the health.
Returns
Attributes
gamemode
Get Signature
get gamemode():
Gametype
Defined in: prismarine/src/network/PlayerSession.ts:3322
The game mode.
Returns
pitch
Get Signature
get pitch():
number
Defined in: prismarine/src/network/PlayerSession.ts:3317
Returns
number
sender
Get Signature
get sender():
ChunkSender
Defined in: prismarine/src/network/PlayerSession.ts:740
The queue the scheduler drains - see ChunkRecipient.
Returns
ChunkSender
yaw
Get Signature
get yaw():
number
Defined in: prismarine/src/network/PlayerSession.ts:3313
Returns
number
Methods
abandonRespawnPoint()
abandonRespawnPoint(
level?):void
Defined in: prismarine/src/network/PlayerSession.ts:3656
Gives up the chunk tickets attemptRespawnPoint took, for a caller that stops asking before it has the answer, such as a trip out of the End that was dropped. A respawn request of the same player that still waits takes its ticket again at its next attempt.
Parameters
level?
Pick<Level, "getRespawnSearch"> = ...
The level whose search took the tickets, the player's own by default. A player who moved to another level since asks a different search, so a caller that knows where the search ran names it.
Returns
void
addFood()
addFood(
food,saturation?):void
Defined in: prismarine/src/network/PlayerSession.ts:3377
Feeds the player, as eating does.
Parameters
food
number
saturation?
number = 0
Returns
void
addToPlayerList()
addToPlayerList():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2983
Adds the client to the player list of every player inside the server and also to the player itself.
Returns
Promise<void>
announceSettings()
announceSettings():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1275
Sends this session's player's game mode, adventure settings and abilities where each belongs.
The two halves have different audiences, and sending both to everyone was a bug. UpdateAdventureSettingsPacket carries no target actor - it describes the client receiving it and nothing else - so pushing one player's settings to every session made a single spectator set worldImmutable on everybody else's client. It goes to this client alone. UpdateAbilitiesPacket does carry targetActorUniqueId, so it is genuinely about this player and belongs with everyone who can see them.
Returns
Promise<void>
attemptRespawnPoint()
attemptRespawnPoint():
RespawnDestination|undefined
Defined in: prismarine/src/network/PlayerSession.ts:3643
requestRespawnPoint for a caller that asks again at each input step until it has the answer, such as a trip out of the End. Each attempt that lacks a chunk holds a ticket for it in the player's name.
Returns
RespawnDestination | undefined
The destination, or undefined while the search waits for what it lacks.
beginLoadingScreen()
beginLoadingScreen():
number
Defined in: prismarine/src/network/PlayerSession.ts:2366
Hands out the Loading Screen Id for a ChangeDimensionPacket about to be sent, and remembers it until PlayerSession.endLoadingScreen hears the client close that screen.
Returns
number
A uint32 no other open screen on this session uses.
changeWorld()
changeWorld(
arrival,options?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2415
Moves the player to another world and walks the client through the dimension change.
Server side first: the record is saved to the world being left, stamped with that world's dimension, the player leaves its roster, the old world's entities come off the client, the chunk bookkeeping is cleared, the position moves, and the player joins the new roster. Then the wire sequence Dragonfly, Geyser and Nukkit agree on: one ChangeDimension with the target's Bedrock id, StopSound for everything playing, NetworkChunkPublisherUpdate at the arrival, the server-sent PlayerAction ChangeDimensionAck, the arrival chunks, and PlayStatus PlayerSpawn. The change stays pending, and the client's PlayerAuthInput is dropped, until the client closes the screen with the id this handed out: see PlayerSession.completeDimensionChange.
A client sent ChangeDimension to the dimension it is already in never closes the screen, so a move between two worlds of the same Bedrock id detours through another dimension first.
A second arrival while a change is pending is held until the client closes the first screen, then carried out; only the latest is kept. A caller whose arrival goes stale while it waits, such as a portal, instead passes whenPending: 'drop': the player is still ticked on the loading screen, and one who arrived inside the exit portal would otherwise be sent back once the 10 tick cooldown ran out, before the client ever closed the first screen. Custom dimension ids are sent after the level announces them in DimensionData.
Every write is made and every packet queued before this returns, so the input step that runs it waits for nothing. The record's save is handed to work outside the tick.
Parameters
arrival
The world, feet position and rotation the player lands at.
options?
What to do with this arrival when a change is already pending, and what follows the change: then runs once the change is carried out, so a held change takes it along and a dropped one drops it.
then?
() => void
whenPending?
"queue" | "drop"
Returns
Promise<void>
Settles once the transport has framed the packets.
clearChunks()
clearChunks():
void
Defined in: prismarine/src/network/PlayerSession.ts:1469
Clear the currently loaded and loading chunks.
Returns
void
Remarks
Usually used for changing dimension, world, etc.
Everything in flight goes with them. The two sets are only the bookkeeping; the queue of coordinates still to send and the chunks already produced but not yet dispatched are the actual work, and they belong to the world being left. Left in place, a dimension change sent the old world's terrain into the new one, and resolved the leftover coordinates against a world where they mean somewhere else entirely.
closeWindow()
closeWindow(
windowId):boolean
Defined in: prismarine/src/network/PlayerSession.ts:1867
Forgets a window the client reports closed.
The docs have the server delete its container manager when the client's ContainerClose arrives, before answering it. Only a window this session opened can be closed here; any other id is left alone and reported through the return value so the handler can log it.
Parameters
windowId
number
the Container Id the client sent.
Returns
boolean
whether a window with that id was open.
completeCredits()
completeCredits():
boolean
Defined in: prismarine/src/network/PlayerSession.ts:2639
Finishes held credits: the full dimension change sequence to the held arrival, sent as a respawn, which is how Java's PlayerList.respawn(player, true, ...) answers the credits. Called by ShowCreditsHandler when the client reports the credits finished.
The change is a message: it runs at the next input step through DimensionTravel.move, so the handler that reports the finish waits for nothing.
Returns
boolean
Whether credits were pending. A finish with none pending changes nothing.
completeDimensionChange()
completeDimensionChange(
loadingScreenId):boolean
Defined in: prismarine/src/network/PlayerSession.ts:2708
Finishes a pending world change once the client reports its loading screen closed.
Teleports the client to the exact arrival position, re-sends the attributes and the inventory, which a dimension change is not known to keep, tells the client where its spawn point is from the new dimension, and raises the changed dimension advancement hook, in that order. A change held while this one was pending is filed last, as a message the next input step carries out. Called by ServerboundLoadingScreenHandler in its unit, and by the tick for a client that never closed the screen. Every packet is queued before this returns.
Parameters
loadingScreenId
number
The id the client's EndLoadingScreen carried.
Returns
boolean
Whether a change was pending under that id. Any other id changes nothing.
completeSpawn()
completeSpawn():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2202
Finishes bringing this session's player into the game: position, gamemode, inventory, settings, and the attributes, metadata and status effects the spawning client threw away.
Returns
Promise<void>
Remarks
Named apart from StorePlayerActor.spawnTo on purpose. This used to be called sendSpawn, overriding the entity method of that name with a different signature and an unrelated meaning - one is "put me into the world", the other is "show me to somebody". Adding a player to a world therefore ran this by accident.
considerEntity()
considerEntity(
entity):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1051
Shows one entity to this client, if it is close enough and not already shown.
The single-entity path, for something that has just entered the world rather than a whole pass over everything in it.
Parameters
entity
ShownEntity
The entity to consider.
Returns
Promise<void>
deliver()
deliver(
x,z):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:753
Produces one chunk and queues it for the next batch. Called only by the scheduler.
The scheduler takes a coordinate off the queue before calling this, so a failure here has to put the bookkeeping back: loadingChunks is what stops needNewChunks from asking for the same chunk twice, and leaving the hash in it after nothing was sent means that chunk is never requested again - a permanent hole in the player's world for as long as they stay in range of it.
Parameters
x
number
z
number
Returns
Promise<void>
despawnAllTrackedEntities()
despawnAllTrackedEntities():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1097
Hides every tracked entity from this client and forgets them all.
For a world change. A dimension change does not make the client drop what it holds, so the mobs of the world being left stayed on screen in the new one. Not routed through PlayerSession.reconcileTrackedEntities: that returns early while another pass runs, and a world change cannot be skipped.
Returns
Promise<void>
dropEntity()
dropEntity(
entity):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1084
Hides one entity from this client if it is showing, and forgets it either way.
Unconditional forgetting matters: a stale id left behind would make the tracker believe the client still has an entity it does not, and block it from ever being sent again.
Parameters
entity
Pick<ShownActor, "getRuntimeId">
The entity that is going away.
Returns
Promise<void>
endLoadingScreen()
endLoadingScreen(
id):boolean
Defined in: prismarine/src/network/PlayerSession.ts:2378
Records that the client closed a loading screen.
Parameters
id
number
The Loading Screen Id from the client's ServerboundLoadingScreenPacket.
Returns
boolean
Whether the id belonged to a screen this session had opened and not yet closed.
flush()
flush():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1107
Sends what has been produced but not yet dispatched.
Called by the scheduler at the end of its pass, so a partial batch does not sit until the next tick.
Returns
Promise<void>
flushQueuedMoves()
flushQueuedMoves():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3156
Sends this tick's movement as one batch.
Called once per world tick, after every entity has had its update.
Returns
Promise<void>
Resolves once the batch has been framed.
getActor()
getActor():
StorePlayerActor|undefined
Defined in: prismarine/src/network/PlayerSession.ts:3247
The player's actor while its entity is in the store of its world: what entity code is handed in the player's place, such as a blow's attacker, the portal touch and the entity events. Undefined from the login to the spawn and between two worlds, when nothing can reach the player.
Returns
StorePlayerActor | undefined
getBox()
getBox():
EntityBox
Defined in: prismarine/src/network/PlayerSession.ts:3270
The box the player's body takes up, from the type's collision box.
Returns
EntityBox
getClientCacheEnabled()
getClientCacheEnabled():
boolean
Defined in: prismarine/src/network/PlayerSession.ts:785
Whether this session will use cached blobs in request-mode subchunk responses.
Returns
boolean
getConnection()
getConnection():
ClientConnection
Defined in: prismarine/src/network/PlayerSession.ts:3190
Returns
ClientConnection
getEquipment()
getEquipment():
ViewableEquipment
Defined in: prismarine/src/network/PlayerSession.ts:3337
What the player wears and holds.
Returns
ViewableEquipment
getExperience()
getExperience():
ExperienceHolder
Defined in: prismarine/src/network/PlayerSession.ts:3387
The experience, written through logged setters.
Returns
ExperienceHolder
getFallDistance()
getFallDistance():
number
Defined in: prismarine/src/network/PlayerSession.ts:3382
How far the player has fallen since it was last supported.
Returns
number
getFeetY()
getFeetY():
number
Defined in: prismarine/src/network/PlayerSession.ts:3309
The bottom of the player's body.
Returns
number
getFood()
getFood():
number
Defined in: prismarine/src/network/PlayerSession.ts:3367
Food, out of 20.
Returns
number
getFormattedUsername()
getFormattedUsername():
string
Defined in: prismarine/src/network/PlayerSession.ts:3412
The name as a chat line attributes it.
Returns
string
getInventory()
getInventory():
HumanInventory
Defined in: prismarine/src/network/PlayerSession.ts:3332
What the player carries.
Returns
HumanInventory
getJoinSpawn()
getJoinSpawn():
PlayerSpawn|null
Defined in: prismarine/src/network/PlayerSession.ts:2143
Where the player was placed on joining, or null when they came back to a saved position.
Returns
PlayerSpawn | null
getName()
getName():
string
Defined in: prismarine/src/network/PlayerSession.ts:3407
The name the player logged in with.
Returns
string
getOpenBlockContainer()
getOpenBlockContainer():
OpenBlockContainer|undefined
Defined in: prismarine/src/network/PlayerSession.ts:1818
The block container this session has open, or undefined for none.
Returns
OpenBlockContainer | undefined
getPermissions()
getPermissions():
string[]
Defined in: prismarine/src/network/PlayerSession.ts:3425
The permissions the player holds, read from the permission manager on every call so a revoked operator status or grant applies at once.
Returns
string[]
getPlayer()
getPlayer():
StorePlayer
Defined in: prismarine/src/network/PlayerSession.ts:3203
The player this session speaks for, found by its entity id.
The one way from a session to its player's state, the store player the server's directory files by that id. Code that needs only the id, the name or the key reads PlayerSession.runtimeId or PlayerSession.identity instead.
Returns
StorePlayer
The player.
Throws
Once PlayerSession.disable has forgotten the player.
getPosition()
getPosition():
Vector3
Defined in: prismarine/src/network/PlayerSession.ts:3304
Where the player's eyes are, as its client reports them.
Returns
getRuntimeId()
getRuntimeId():
bigint
Defined in: prismarine/src/network/PlayerSession.ts:3289
The player's entity id.
Returns
bigint
getSaturation()
getSaturation():
number
Defined in: prismarine/src/network/PlayerSession.ts:3372
The hidden buffer spent before food.
Returns
number
getServer()
getServer():
Server
Defined in: prismarine/src/network/PlayerSession.ts:3275
The server this session belongs to.
Returns
getSpawnPoint()
getSpawnPoint():
StoredSpawnPoint|undefined
Defined in: prismarine/src/network/PlayerSession.ts:3397
The player's own spawn point, or undefined for the world spawn.
Returns
StoredSpawnPoint | undefined
getStatusEffects()
getStatusEffects(): readonly
StatusEffect[]
Defined in: prismarine/src/network/PlayerSession.ts:3342
The status effects on the player.
Returns
readonly StatusEffect[]
getType()
getType():
string
Defined in: prismarine/src/network/PlayerSession.ts:3294
The type of the player's entity, minecraft:player.
Returns
string
getViewDistance()
getViewDistance():
number
Defined in: prismarine/src/network/PlayerSession.ts:2136
The chunk radius this client sees, as it asked for it, in chunks.
Returns
number
The radius, or zero until the client's first RequestChunkRadius.
getViewPosition()
getViewPosition():
Vector3
Defined in: prismarine/src/network/PlayerSession.ts:2128
Where this client sees the world from: its player's eyes, the point chunk streaming, entity tracking and a world's broadcasts measure from.
Returns
The position.
getWorld()
getWorld():
World
Defined in: prismarine/src/network/PlayerSession.ts:2119
The world this session's player is in, which is the world its chunks are streamed from.
During a dimension change it is the destination from the moment the player moves, while the client may still be on its loading screen.
Returns
The world.
getXUID()
getXUID():
string|null
Defined in: prismarine/src/network/PlayerSession.ts:3299
The XUID the login carried, or null when it carried none.
Returns
string | null
handleClientCacheBlobStatus()
handleClientCacheBlobStatus(
packet):Promise<number>
Defined in: prismarine/src/network/PlayerSession.ts:798
Responds to requested blob misses and applies the client's acknowledgements.
Every status is answered, with an empty ClientCacheMissResponse when the client missed nothing. Bedrock Dedicated Server 1.26.60 does the same, 105 answers to 105 statuses in the capture docs/research/sub-chunk-requests-and-blob-cache.md describes. Do not skip the empty one to save a packet: the answer is what closes the client's cache transaction.
Parameters
packet
Returns
Promise<number>
How many blobs went out.
handleSubChunkRequest()
handleSubChunkRequest(
packet):Promise<number>
Defined in: prismarine/src/network/PlayerSession.ts:826
Answers requested sections with their bytes, block entities, heightmaps, and cache ids.
The shape of each entry follows a capture of Bedrock Dedicated Server 1.26.60 answering a retail client, recorded in docs/research/sub-chunk-requests-and-blob-cache.md. With the client's blob cache on:
- A section with blocks carries the hash of its terrain and a payload that is present even when empty. The payload holds the section's block entities only.
- An all-air section carries neither payload nor hash.
- The answer is the same whether or not the client has confirmed the blob before.
These look like things to simplify, such as dropping an empty payload or sending the terrain inline to save a round trip. A retail client leaves with a bad packet error (ClientDisconnection-90) on either, so change them only against a new capture.
Parameters
packet
The requested chunk columns and absolute subchunk center.
Returns
Promise<number>
holdsMovementForTeleport()
holdsMovementForTeleport(
position,handledTeleport):boolean
Defined in: prismarine/src/network/PlayerSession.ts:2964
Whether an input's position must be ignored because the client has not yet handled a teleport the server sent it.
Mojang's packet documentation, on HandledTeleport: "The server should ignore any client predicted positions from the moment a MovePlayerPacket was sent until receipt of this action." That covers every teleport, the one that ends a dimension change included.
The client goes on sending inputs from where it was until it applies the MovePlayer, and the first input from the new place carries HandledTeleport. A retail client was captured doing exactly that, with one stale input arriving after the teleport about one time in three. Taking the stale position moves the player back on the server while the client stands at the target, and the server then sends chunks for the wrong place. A client that stops sending inputs while it waits for chunks never recovers from that.
The hold ends on a HandledTeleport input at the target, which tells two teleports sent in a row apart, or after TELEPORT_ACK_TIMEOUT_TICKS, so a client that never sets the flag is not frozen in place.
Parameters
position
Where the input says the player is.
handledTeleport
boolean
Whether the input carries HandledTeleport.
Returns
boolean
inputs()
inputs():
EntityRuntime
Defined in: prismarine/src/network/PlayerSession.ts:3237
The entity runtime of the player's world, whose player inputs write what the client reports: through its player systems while the player is in its store, and onto the store player's components while it is in none.
Returns
EntityRuntime
isConnected()
isConnected():
boolean
Defined in: prismarine/src/network/PlayerSession.ts:924
Whether the player has joined and not left.
Returns
boolean
isFlying()
isFlying():
boolean
Defined in: prismarine/src/network/PlayerSession.ts:3362
Whether the player is flying.
Returns
boolean
isOnGround()
isOnGround():
boolean
Defined in: prismarine/src/network/PlayerSession.ts:3347
Whether the client last reported the player on the ground.
Returns
boolean
isOp()
isOp():
boolean
Defined in: prismarine/src/network/PlayerSession.ts:3417
Whether the player is an operator.
Returns
boolean
isSneaking()
isSneaking():
boolean
Defined in: prismarine/src/network/PlayerSession.ts:3357
Whether the client last reported the player sneaking.
Returns
boolean
isSprinting()
isSprinting():
boolean
Defined in: prismarine/src/network/PlayerSession.ts:3352
Whether the client last reported the player sprinting.
Returns
boolean
keyed()
keyed():
KeyedPlayer
Defined in: prismarine/src/network/PlayerSession.ts:3284
The key and the server the player's advancements and enchantment seed are kept by.
Returns
KeyedPlayer
kick()
kick(
reason?,code?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3180
Disconnects this client with a reason it shows, and hangs up its connection.
Parameters
reason?
string = 'unknown reason'
Shown to the client.
code?
DisconnectReason = DisconnectReason.KICKED
The code the client shows beside the reason. Server.shutdown passes SHUTDOWN.
Returns
Promise<void>
Remarks
Torn down through the connection rather than by calling disable directly, so the player and its session are released together and exactly once, and the RakNet session is hung up on rather than left for a client that never hangs up to hold its slot.
needNewChunks()
needNewChunks(
forceResend?,dist?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1310
Parameters
forceResend?
boolean = false
dist?
number
Returns
Promise<void>
openBlockContainer()
openBlockContainer(
at,identifier,contents?):Promise<OpenBlockContainer|undefined>
Defined in: prismarine/src/network/PlayerSession.ts:1643
Opens the screen a block draws, with whatever the block is holding.
The one call the interaction path needs. Until this existed no block opened a container anywhere in this server: a chest, a furnace and a crafting table all did nothing when they were clicked, because openMainInventory was the only ContainerOpen ever sent.
The contents follow the open for the same reason they do there: a window whose contents never arrive is one the client has no reason to keep. Each packet uses the container name that screen assigns to its slots, so a furnace's fuel list arrives under its fuel name. A workstation stores nothing of its own, so no contents follow its open. A crafting table is followed by the player's own inventory under window 0 instead, which is what a Bedrock Dedicated Server 1.26.52 sent after a click on one. Repeated requests for the same open block return the current window without sending another open packet.
Parameters
at
The block position, which is what ContainerOpen carries for a block.
identifier
string
The block standing there, which decides the screen.
contents?
ContainerEntry[] = []
What the block holds, one entry per slot.
Returns
Promise<OpenBlockContainer | undefined>
The window it was opened under, or undefined when the block opens no screen.
openMainInventory()
openMainInventory():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1613
Opens the player's own inventory, as the client asked.
Under its own window id rather than under zero. Zero is the inventory the client always has open; asking it to open that one is asking for something it is already doing, and it answered by closing the window again straight away - which is as far as opening an inventory ever got, so no drag inside it was ever attempted.
The contents follow the open, because a window whose contents never arrive is one the client has no reason to keep.
Returns
Promise<void>
See
https://github.com/pmmp/PocketMine-MP/blob/stable/src/network/mcpe/InventoryManager.php (onClientOpenMainInventory)
openTradeWindow()
openTradeWindow(
trade):Promise<OpenBlockContainer|undefined>
Defined in: prismarine/src/network/PlayerSession.ts:1751
Opens a villager's trade screen and shows it the trader's offers.
The screen is a window like a block's: it has two payment slots the player's items go into and a result the trade comes out of, and closing it gives the payment back. It differs in being open on an actor, which the packet names, and in what follows the open: an UpdateTradePacket carrying the offers, which the client draws the screen from.
Parameters
trade
The trader, where its offers come from and what happens when the player leaves.
Returns
Promise<OpenBlockContainer | undefined>
The window, or undefined when this session already has a trade open on that trader.
pendingCreditsArrival()
pendingCreditsArrival():
Arrival|undefined
Defined in: prismarine/src/network/PlayerSession.ts:2661
The arrival held while the credits roll on the client, or undefined when none are. While one is held, the client's PlayerAuthInput is dropped, as it is during a pending dimension change.
Returns
Arrival | undefined
pendingDimensionChange()
pendingDimensionChange():
PendingDimensionChange|undefined
Defined in: prismarine/src/network/PlayerSession.ts:2590
The world change the client has not yet finished loading into, or undefined when the player is settled. While one is pending, the client's positions are still the old world's and PlayerAuthInputHandler drops them.
Returns
PendingDimensionChange | undefined
queueChunks()
queueChunks(
centerX,centerZ,coordinates):void
Defined in: prismarine/src/network/PlayerSession.ts:929
Queues the chunks around a position, nearest first, without sending anything yet.
Parameters
centerX
number
centerZ
number
coordinates
[number, number][]
Returns
void
queueMoveActor()
queueMoveActor(
entity,teleport?):void
Defined in: prismarine/src/network/PlayerSession.ts:3143
Adds an entity's movement to this tick's batch.
Sending each one on its own is what made mobs move in fits and starts, and for two reasons. Every packet became its own compressed batch and its own RakNet frame, so thirty mobs cost thirty compressions and thirty frames a tick, per player. Worse, sendDataPacket queues behind any chunk still compressing - so while a walking player streams terrain, every mob's movement waited behind it and then arrived in a burst. Mobs froze and jumped in exactly the rhythm the chunks were arriving in.
One batch a tick fixes both: one compression, one frame, and one place in the queue for the lot of them.
Parameters
entity
The entity that moved.
teleport?
boolean = false
Returns
void
reconcileTrackedEntities()
reconcileTrackedEntities(
entities?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1016
Shows and hides entities so the client matches where the player now is.
Records an entity as tracked only after its spawn has gone out. Marking first would mean a spawn that failed left the entity flagged as delivered, and nothing would ever send it again - the same lesson flushChunkBatch records for chunks, where it left a permanent hole in the world.
Parameters
entities?
Iterable<ShownEntity, any, any>
Every entity in the world, and it must be every one - anything tracked and absent from it is taken to have left and is despawned. Defaults to asking the world. For a single arrival, use PlayerSession.considerEntity.
Returns
Promise<void>
recordInputTick()
recordInputTick(
tick):void
Defined in: prismarine/src/network/PlayerSession.ts:2356
Remember the tick of a PlayerAuthInputPacket just handled, so packets about this player can carry it as their PlayerInputTick.
Ticks only move forward; an input that arrives out of order does not wind the value back.
Parameters
tick
bigint
The packet's Tick field.
Returns
void
releaseArrivalChunks()
releaseArrivalChunks(
loadingScreenId):Promise<boolean>
Defined in: prismarine/src/network/PlayerSession.ts:2680
Lets the columns of a pending dimension change go out, once the client says it has opened that change's loading screen, and sends the ones already waiting.
Until then they are held. A client that decodes a column before it has switched dimension files it under the dimension it is leaving and drops it at the switch, then waits on its loading screen for a column the server believes it has: cinnabar did this on about one full e2e run in two. The client reports the screen open only after its switch has begun, so a column sent from then on lands in the new dimension. Sending the lost ones again is not a remedy: in sub chunk request mode a second LevelChunk resets the column the client holds, and a player standing on it falls through. ARRIVAL_HOLD_TICKS bounds the wait for a client that never reports the screen.
Parameters
loadingScreenId
number
The id the client's StartLoadingScreen carried.
Returns
Promise<boolean>
Whether this released the pending change's columns. Any other id changes nothing.
releaseChangeHeldOverDeath()
releaseChangeHeldOverDeath():
void
Defined in: prismarine/src/network/PlayerSession.ts:2570
Files the change PlayerSession.changeWorld held while the player was dead, for the next input step. Called by PlayerSession.respawn once the client is told its player is alive. A change still pending, the respawn's own included, files the held one when it closes instead.
Returns
void
released()
released(
sends):void
Defined in: prismarine/src/network/PlayerSession.ts:1241
Lets sends that are already queued go without waiting for the transport, and logs a failure to frame them. For simulation code, which never reads the result of a send.
Parameters
sends
Promise<void>
The sends, already started.
Returns
void
removeFromPlayerList()
removeFromPlayerList():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2997
Removes a player from other players list
Returns
Promise<void>
requestChunk()
requestChunk(
x,z):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1376
Parameters
x
number
z
number
Returns
Promise<void>
requestRespawn()
requestRespawn():
void
Defined in: prismarine/src/network/PlayerSession.ts:3719
Brings the player back after a death, at its respawn point and in one piece.
Returns
void
Remarks
Called when the client asks, not when the player dies - the death screen is the client's, and it decides how long it stays up. The client reports ClientReadyToSpawn before it sends this, and has already put itself where the answer to that said: see RespawnHandler.
The respawn waits for the search's answer, so it is filed as a request and the input step that has the answer applies it (requestRespawnPoint).
requestRespawnPoint()
requestRespawnPoint(
apply):void
Defined in: prismarine/src/network/PlayerSession.ts:3628
Where the player comes back after a death, given as a Bedrock Dedicated Server gives it.
Their own spawn point when they have one that still holds, in the world it was set in, which need not be the one they died in: a player who dies in the Nether with an Overworld bed comes back in the Overworld, as Java's findRespawnPositionAndUseSpawnBlock has it. Otherwise the Overworld spawn of the default level, which is Java's server.overworld(). A bed or a respawn anchor only holds a spawn while the block is still there with somewhere free to stand beside it, and a point /spawnpoint set is used whatever is standing there. The level's respawn search answers the question from plain data. A spawn that stopped holding is cleared here, so the player is told once rather than on every death.
The caller compares world with the player's own and changes world first when they differ: see RespawnHandler.
The search reads loaded chunks only, so the answer is not always there at once (attemptRespawnPoint).
Parameters
apply
(destination) => void
Returns
void
See
respawnPoint for the three positions the exchange needs.
send()
send(
packet):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1232
Sends one packet to this client.
Returns the send rather than dropping it: without this, every await session.send(...) and every Promise.all over a broadcast resolved immediately and any framing error went nowhere.
Parameters
packet
NetworkPacket<unknown>
The packet to send.
Returns
Promise<void>
sendAbilities()
sendAbilities(
player?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1297
Sends UpdateAbilitiesPacket describing player to this client (abilitiesPacket).
Parameters
player?
ShownPlayer
The player described. Defaults to this session's own player.
Returns
Promise<void>
sendAbilityChange()
sendAbilityChange():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2038
The last sends of a game mode change, which read off the new game mode: the settings, the game type again, whether the player may fly, which is in its metadata, and its abilities.
Returns
Promise<void>
sendArmorFor()
sendArmorFor(
wearer):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3054
Tells this client what a human is wearing and holding in the off hand (armorPackets), read from the wearer's equipment, which for a player is its inventory.
Parameters
wearer
ShownActor
Whose armor it is.
Returns
Promise<void>
sendAttributes()
sendAttributes(
attributes?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2288
Send the player's whole attribute set.
The client rebuilds the local player during the spawn sequence, so this has to be sent again once the player is in the world - anything sent before that is thrown away, which is why the hunger bar sat empty however correct the values were here.
Parameters
attributes?
Attributes = ...
The attributes to send, the player's own by default.
Returns
Promise<void>
sendAttributesFor()
sendAttributesFor(
entity,attributes):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2337
Tell this client about another entity's changed attributes.
The gap that made mob combat invisible. Everything above sends the local player's own attributes, with their runtime id baked in, so a mob losing health changed a number on the server that no client was ever told about - the health bar over a hurt zombie never moved, and it died in one apparent hit from full. Attributes only reached a client once, inside the AddActorPacket that spawned the entity.
Parameters
entity
Pick<ShownActor, "getRuntimeId">
Whose attributes these are.
attributes
Attribute[]
The ones that changed; nothing is sent for an empty list.
Returns
Promise<void>
sendAvailableCommands()
sendAvailableCommands():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2083
Tells the client which commands this player may run and what each one takes.
One CommandData per command, each branch of its tree an overload, with overloads that come out the same folded into one. Only commands the player's permissions allow are sent, so the list is built per recipient and sent again when those permissions change.
The list is the command manager's one registry, already flattened into Bedrock's overload shape by @jsprismarine/commands, which carries chained subcommands and therefore the chained /execute tree.
Returns
Promise<void>
sendContainerData()
sendContainerData(
at,properties):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1833
Sets properties on the open block container's screen, which is how a progress bar moves.
A property whose value has not changed since the last send is skipped; see PlayerSession.containerData. Nothing is sent when the screen was opened from a different block, so a station ticking across the world cannot write over the screen the player is actually looking at.
Parameters
at
The block the properties belong to.
properties
ReadonlyMap<number, number>
The property values by id, as the station reports them.
Returns
Promise<void>
sendContainerSlot()
sendContainerSlot(
windowId,containerId,slot,item):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1552
Tells this client that one slot of a container it has open now holds something else.
An ItemStackResponse only ever reaches the client that sent the request, so this is the only way to tell the other players standing at the same chest that a stack has gone.
Parameters
windowId
number
The Container Id this client opened the block under, which is its own.
containerId
number
The Container Name the client numbers the slot by.
slot
number
The slot within that container.
item
Item | null
What is in it now, or null to empty it.
Returns
Promise<void>
sendCraftingData()
sendCraftingData():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1906
Tells the client which recipes exist.
Until it has these the client proposes nothing and never sends a CRAFTING_RECIPE, so everything below this - the matcher, the stations, the grid - is invisible without it.
The recipes come from the content build's recipe book, and a recipe's net id is its position in that book, which is what an ItemStackRequest names it by. A build that produced no payload sends nothing, so the client proposes nothing it cannot craft.
How many go out is crafting-recipe-limit in the config: 0 sends nothing, -1 sends everything, and it starts at one. See there for why.
Returns
Promise<void>
sendCreativeContents()
sendCreativeContents(
empty?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1931
Parameters
empty?
boolean = false
Returns
Promise<void>
sendDeathScreen()
sendDeathScreen(
announced,cause):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2843
The death screen's half of a death, once the respawn search has answered: where the player will come back, which the client waits for before it offers the respawn button, and then the screen's own copy of the cause, as PocketMine's DeathPacketHandler sends it after the Respawn.
Parameters
announced
Where the player will reappear.
cause
DeathMessage
The death message, as the chat line has it. DeathInfo takes the key without the % the chat packet wants.
Returns
Promise<void>
sendGamemode()
sendGamemode(
gamemode?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1992
Send gamemode to a client.
Parameters
gamemode?
the numeric gamemode ID.
Returns
Promise<void>
sendGameRules()
sendGameRules(
rules):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2056
Tells this client that game rules changed.
Parameters
rules
GameRule[]
The rules that changed, spelled as the client spells them.
Returns
Promise<void>
sendGameTypeChange()
sendGameTypeChange():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2021
The first sends of a game mode change: this client's own game type, and the game type every client in the world caches for this player. Replication sends the metadata a game mode decides, not the game type, so these are the sends. PlayerSession.sendAbilityChange follows them.
Returns
Promise<void>
sendGameTypeFor()
sendGameTypeFor(
target):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2007
Tells this client which game type a player now has.
UpdatePlayerGameTypePacket is what the docs have the server send to every client after it accepts a game type change, because each client caches the game type and permission flags of every player it knows about. The Tick is this client's last input tick when the player is its own, so the client can reconcile the movement it predicted while the packet was in flight, and zero for anyone else, as the docs allow.
Parameters
target
ShownPlayer
The player whose game type changed.
Returns
Promise<void>
sendHandItem()
sendHandItem(
item):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1966
Sets the item in the player hand.
Parameters
item
Item
The entity.
Returns
Promise<void>
sendInitialSpawnChunks()
sendInitialSpawnChunks():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2160
Opens the window the client accepts chunks in and queues the chunks around the player, with an initial view radius of DEFAULT_VIEW_DISTANCE_CHUNKS, as a join and a world change start.
Returns
Promise<void>
sendInventory()
sendInventory(
windowId?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1503
Tells the client what the player is carrying.
The send was commented out, so the client was never told: it had no model of the player's own slots, and the server authoritative inventory system will not move a stack into a container it does not know. Every drag was refused on the client's side, before an ItemStackRequest was ever sent.
Parameters
windowId?
number = WindowIds.INVENTORY
Returns
Promise<void>
sendMessage()
sendMessage(
delivery):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2864
Send a chat message to the client.
A bare string is a raw line, which is how a command answers the player that ran it.
Parameters
delivery
string | { message: string; needsTranslation?: boolean; parameters?: string[]; platformChatId?: string; sourceName?: string; type?: TextPacketType; xuid?: string; }
The message, or the options for it.
string
Type Literal
{ message: string; needsTranslation?: boolean; parameters?: string[]; platformChatId?: string; sourceName?: string; type?: TextPacketType; xuid?: string; }
The message, or the options for it.
message
string
The message to send.
needsTranslation?
boolean
Whether the message needs translation.
parameters?
string[]
The parameters for the message.
platformChatId?
string
The platform chat ID.
sourceName?
string
The source of the message.
type?
The type of the message.
xuid?
string
The XUID of the player.
Returns
Promise<void>
A promise that resolves when the message is sent.
sendMetadata()
sendMetadata(
metadata?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2758
Parameters
metadata?
Metadata
Returns
Promise<void>
sendMetadataFor()
sendMetadataFor(
entity,metadata?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2772
Tell this client what another entity now looks like.
The same gap sendAttributesFor fills, for the other half of an entity's state: everything above had the local player's runtime id baked in, so metadata reached a client exactly once, inside the packet that spawned the entity. A creeper could light its fuse, a mob could catch fire, and nobody would ever see either.
Parameters
entity
Pick<ShownActor, "getRuntimeId" | "metadata" | "getSyncedProperties">
Whose metadata this is.
metadata?
Metadata
What to send; the entity's own by default.
Returns
Promise<void>
sendMotion()
sendMotion(
motion):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2750
Hand the client a velocity and let it move the player itself.
The only way to shove a player. Their position is theirs - the server stores what it is told - so setting it from here is overruled by the next movement packet and read as rubber-banding. A velocity is a request the client is happy to honor.
The Tick is the client's last input tick, as the docs ask for a packet about the player: the client rewinds to that tick, applies the velocity and replays what it predicted since. See PlayerSession.recordInputTick.
Parameters
motion
Blocks per tick, in each axis.
Returns
Promise<void>
sendMove()
sendMove(
player,mode?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2918
Sends one player's movement to this client.
Named for what it does. It was broadcastMove, which reads as a fan-out and is not one - the fan-out is World.broadcastMove, and having both made it easy to write the wrong one.
For this client's own player the packet is a server-initiated move: a teleport, a respawn, or a reset after a canceled move event. Its Tick is the client's last input tick, as the docs ask, so the client rewinds to it and replays its predictions from there. For any other player the packet is what this client sees of them, and the tick is zero because it relates to none of this client's inputs.
Parameters
player
ShownActor
The player that moved.
mode?
PositionMode = PositionMode.Normal
What produced the movement.
Returns
Promise<void>
sendMoveActor()
sendMoveActor(
entity):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3125
Tells this connection an entity has moved, on its own.
For a move that happens outside the world tick - a teleport, a command. Movement produced by the tick goes through queueMoveActor instead.
Parameters
entity
The entity that moved.
Returns
Promise<void>
sendNetworkChunkPublisher()
sendNetworkChunkPublisher(
distance,savedChunks):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2062
Parameters
distance
number
savedChunks
Returns
Promise<void>
sendOwnSlot()
sendOwnSlot(
container,slot):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1579
Tells this client what one of its player's own slots holds now, under the stack network id the client is to name it by. Replication sends it for a slot-shown occurrence: a slot whose write was undone holds a stack with a new id.
Parameters
container
string
The container, as an inventory-slot entry names it.
slot
number
The slot within that container.
Returns
Promise<void>
The send, or a settled promise for a container the client has no window for.
sendPlayerList()
sendPlayerList():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3013
Sends the full player list to the player.
Returns
Promise<void>
sendPlayStatus()
sendPlayStatus(
status):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3186
Sends a PlayStatus to this player's client.
Parameters
status
Returns
Promise<void>
sendRemoveActor()
sendRemoveActor(
entity):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3066
Takes an entity off this connection.
Parameters
entity
ShownActor
The entity to remove.
Returns
Promise<void>
sendRemoveActorById()
sendRemoveActorById(
runtimeId):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3078
Takes an entity off this client by id.
By id rather than by entity because the tracker has to be able to hide something that has already left the world - there is no object left to ask. Correct for every kind of entity, players included: RemoveActorPacket names only the id.
Parameters
runtimeId
bigint
The entity's runtime id.
Returns
Promise<void>
sendRespawn()
sendRespawn(
position,state):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2825
One of the server's two halves of the respawn exchange.
The order matters and is not obvious. SearchingForSpawn goes out the moment the player dies, carrying where they will reappear; the client then shows its death screen. ReadyToSpawn is the answer to the client saying it has finished loading, and goes out only then.
Sending the second in place of the first leaves the client on "Respawning" for ever: it is waiting to be told where it will come back before it will even offer the button.
Player Runtime Id is always 0, as in every Respawn a Bedrock Dedicated Server 1.26.52 sends, at the join and after a death.
Parameters
position
Where the player will reappear.
state
Which half of the exchange this is.
Returns
Promise<void>
See
https://github.com/pmmp/PocketMine-MP/blob/stable/src/network/mcpe/handler/DeathPacketHandler.php
sendRespawned()
sendRespawned():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2793
Tells the client its player is alive again, as a Bedrock Dedicated Server 1.26.52 does when the respawn button is pressed: ActorEvent(SPAWN_ALIVE) for the player, its health, then its attributes and actor data.
No MovePlayer: the client has put itself at the ReadyToSpawn position already.
Returns
Promise<void>
sendSettings()
sendSettings(
player?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1250
Notify a client about change(s) to the adventure settings.
Parameters
player?
Pick<ShownPlayer, "gamemode">
The client-controlled entity
Returns
Promise<void>
sendStatusEffect()
sendStatusEffect(
entity,effect,change):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3034
Sends one effect state change to this client.
Parameters
entity
Pick<ShownActor, "getRuntimeId">
The actor whose effect changed.
effect
StatusEffect
The effect state.
change
StatusEffectChange
Whether it was added, updated, or removed.
Returns
Promise<void>
sendStatusEffects()
sendStatusEffects(
entity):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3024
Sends every active effect after the actor that owns them has spawned.
Parameters
entity
ShownActor
The spawned actor.
Returns
Promise<void>
sendTime()
sendTime(
tick):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1983
Send the current tick to a client.
Parameters
tick
number
The tick
Returns
Promise<void>
sendTradeOffers()
sendTradeOffers(
window?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:1787
Sends the open trade screen the trader's offers as they stand, after a trade or a restock.
Parameters
window?
OpenBlockContainer | undefined = ...
Returns
Promise<void>
setAttributeValue()
setAttributeValue(
name,value):boolean
Defined in: prismarine/src/network/PlayerSession.ts:3392
Sets an attribute, through the component field it is kept in when it has one, so it is logged.
Parameters
name
string
value
number
Returns
boolean
setClientCacheEnabled()
setClientCacheEnabled(
enabled):void
Defined in: prismarine/src/network/PlayerSession.ts:779
Enables or clears client blob caching for subsequent subchunk requests.
Parameters
enabled
boolean
Returns
void
setFlying()
setFlying(
flying):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3513
Starts or stops the player flying, after the playerToggleFlight event, and sends the settings. A game mode that may not fly only ever lands.
The flight is written and the settings queued before this returns.
Parameters
flying
boolean
Returns
Promise<void>
setGamemode()
setGamemode(
mode?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3486
Changes the player's game mode, after the playerSetGamemode event, and tells this client and every client that caches it.
Every write is made, and every packet queued, before this returns. The promise only says when the transport has framed the packets.
Parameters
mode?
The new mode; the current one by default, which sends it again.
Returns
Promise<void>
setJoinSpawn()
setJoinSpawn(
spawn):void
Defined in: prismarine/src/network/PlayerSession.ts:2151
Records where the join placed the player, which the join packets report.
Parameters
spawn
PlayerSpawn | null
The placement, or null for a player who came back to a saved position.
Returns
void
setOnGround()
setOnGround(
onGround):void
Defined in: prismarine/src/network/PlayerSession.ts:3754
Records whether the client reports the player on the ground, as a move to where the player already is: the store pays for a fall the moment it lands.
Parameters
onGround
boolean
Returns
void
setPlayerPosition()
setPlayerPosition(
options,broadcast?):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3784
Moves the player, with a movement mode.
The client owns a player's movement (ADR 0008), so a move the server makes is a request the client has to acknowledge, and the positions it reports until then are dropped (PlayerSession.holdsMovementForTeleport).
Parameters
options
The options to set the position.
headYaw?
number
The new head yaw.
pitch?
number
The new pitch.
position
The new eye position. A Position in another world, given while the player is in no store, is the world it enters next.
type?
PositionMode = PositionMode.Normal
The position mode.
yaw?
number
The new yaw.
broadcast?
boolean = true
Whether to tell this client.
Returns
Promise<void>
Remarks
Observers snap to a respawn or a teleport instead of interpolating to it.
setSpawnPoint()
setSpawnPoint(
spawn):void
Defined in: prismarine/src/network/PlayerSession.ts:3402
Moves the player's own spawn point, or clears it back to the world spawn.
Parameters
spawn
StoredSpawnPoint | undefined
Returns
void
setSprinting()
setSprinting(
sprinting):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:3531
Starts or stops the player sprinting, after the playerToggleSprint event.
Parameters
sprinting
boolean
Returns
Promise<void>
setViewDistance()
setViewDistance(
distance):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2218
Set the client's maximum view distance.
Parameters
distance
number
The view distance
Returns
Promise<void>
setWorld()
setWorld(
world):void
Defined in: prismarine/src/network/PlayerSession.ts:3554
Moves the player to another world, arriving at that world's spawn.
The stored spawn is the block under a joining player's feet, so the feet go one block above it, centered, as requestedSpawnPosition says before the terrain is consulted. The move is a message: DimensionTravel.moveTo files it, a world that has not found its spawn searches for it outside every tick, and the next input step at which the spawn is known carries out PlayerSession.changeWorld. This is the entry point for callers that have a world and no arrival of their own, such as the changeWorld command.
Parameters
world
The new world.
Returns
void
shown()
shown():
ShownPlayer
Defined in: prismarine/src/network/PlayerSession.ts:3259
The session's own player as clients are shown it: its actor while it is in a store, and otherwise what this client is shown of it before its spawn and between two worlds.
Returns
ShownPlayer
The player as it is shown.
Throws
Once PlayerSession.disable has forgotten the player.
startCredits()
startCredits(
arrival):Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2612
Rolls the end credits on the client and holds the arrival until they finish.
Sent on a player's first exit through the End's portal. The world change waits for the client's ShowCredits Finished rather than going out under the credits screen, because a ChangeDimension during the credits has not been verified against a retail client (open question 4 of the End dragon fight plan); Java holds its transfer the same way, on the PERFORM_RESPAWN exchange. While the arrival is held, the client's PlayerAuthInput is dropped, as during a pending dimension change. The held change is completed by PlayerSession.completeCredits. A disconnect in between strands nobody: the player record already carries seenCredits, so the next join finds the player still in the End, standing in the portal, and transfers them at once.
A second start while one is pending is logged at debug and dropped, like a second changeWorld.
Parameters
arrival
Where the player lands once the credits are over.
Returns
Promise<void>
Settles once the transport has framed the packet, which is queued before this returns.
stopMining()
stopMining():
void
Defined in: prismarine/src/network/PlayerSession.ts:3469
Stops the cracks on the block the player was mining, if any, and forgets it.
For whatever ends the mining without the client saying so: a disconnect, a change of game mode or of world. A death is the player systems', inside the blow. Left alone, the cracks would go out every tick for good.
Returns
void
syncAttributes()
syncAttributes():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:2300
Send only the attributes that changed since the last sync, if any.
Called every tick from the player's update: a value nothing tells the client about is a value that only exists on the server.
Returns
Promise<void>
tracks()
tracks(
runtimeId):boolean
Defined in: prismarine/src/network/PlayerSession.ts:1001
Whether this client knows about the entity.
True for the player's own entity, which the tracker itself never holds - a client is not sent a spawn for the thing it is driving, but it plainly has it. Without this the gates built on tracks would drop a player's own hurt animation and the pickup animation for the item they just walked over.
Parameters
runtimeId
bigint
The entity's runtime id.
Returns
boolean
true if the client can act on a packet naming that id.
tryDeliverLoaded()
tryDeliverLoaded(
x,z):CachedChunkDelivery
Defined in: prismarine/src/network/PlayerSession.ts:766
Queues a resident chunk without entering the generation and disk-read depth gate.
Parameters
x
number
z
number
Returns
CachedChunkDelivery
update()
update(
tick):void
Defined in: prismarine/src/network/PlayerSession.ts:949
Per-tick work for this client: terrain to request, entities to show or hide.
Both hang off the same question - has the player walked into a different chunk. Asking it here rather than inside each is what stops needNewChunks rebuilding a heap of a few hundred candidates twenty times a second for a player who has not moved, and it is what makes a moving player see entities appear within a tick rather than on the next interval.
Parameters
tick
number
Returns
void
updatePlayer()
updatePlayer(
tick):void
Defined in: prismarine/src/network/PlayerSession.ts:3435
Runs the player's own part of a tick, which its actor runs after the entity's part: this session, the attribute sync and the triggers. Breath, hunger, a meal, the void and the mining cracks are the store's, in its entity pass.
Parameters
tick
number
The current world-tick.
Returns
void
Lifecycle
disable()
disable():
void
Defined in: prismarine/src/network/PlayerSession.ts:576
Takes this client back out of the chunk rotation and off every boss bar, lets go of the player's state kept outside the player, and forgets the player itself, after which PlayerSession.getPlayer throws. Paired with PlayerSession.enable and safe to call more than once.
PlayerSession.leave runs this after the player has been saved and taken off the server, whether or not that succeeded or the join ever completed.
Returns
void
enable()
enable():
void
Defined in: prismarine/src/network/PlayerSession.ts:562
Puts this client into the server-wide rotation that feeds it chunks.
Not done in the constructor: a session that is built and then thrown away - a join that fails part way through - would stay in the scheduler's set for the life of the server, because the scheduler only ever skips the disconnected and removes on request.
Returns
void
join()
join():
Promise<void>
Defined in: prismarine/src/network/PlayerSession.ts:624
Loads what the server knows about this session's player and marks it joined.
Returns
Promise<void>
Remarks
Sends nothing. This runs from LoginHandler, before the client has been told its login succeeded, and a retail client at protocol 2193 that is handed game packets in that state drops the connection with InitialConnection-90 (bad packet). The game mode, adventure settings and abilities go out from the join burst after StartGame, and AddPlayer carries each other player's position when they come into view.
leave()
leave():
void
Defined in: prismarine/src/network/PlayerSession.ts:601
Takes the player off the server and then this session down with it: the player is saved, taken out of its world and the player list, and said to have left, and PlayerSession.disable runs whether or not that succeeded.
ClientConnection.closePlayerSession calls this once per connection. Outside a unit of the world's change log, every write is made and every packet queued before this returns. Inside one, such as a kick from an input, all of it waits for the unit to end, whether it commits or is undone. The record's save is handed to work outside the tick, and a later read of the record waits for it.
Returns
void
Throws
What the player's leave threw, after the session is disabled, when no unit is open. Inside one, the store reports it.