Class in @minecraft/server
Extends Entity
A player in the world. Players can’t be constructed; get them from events or the world.
import { Player } from '@minecraft/server';Example
Section titled “Example”import { world, type Player } from '@minecraft/server';
function heal(player: Player): void { const health = player.getComponent('minecraft:health'); health?.setCurrentValue(health.effectiveMax); player.sendMessage('You have been healed.');}
// Heal players every time they spawn.world.afterEvents.playerSpawn.subscribe((event) => heal(event.player));import { world } from '@minecraft/server';
function heal(player) { const health = player.getComponent('minecraft:health'); health?.setCurrentValue(health.effectiveMax); player.sendMessage('You have been healed.');}
// Heal players every time they spawn.world.afterEvents.playerSpawn.subscribe((event) => heal(event.player));Properties
Section titled “Properties”read-only
readonly name: string;The player’s gamertag.
nameTag
Section titled “nameTag”nameTag: string;The name shown above the player, their gamertag until set. Setting it changes what other players see, now and when they next come into view.
typeId
Section titled “typeId”read-only
readonly typeId: string;Always "minecraft:player".
isValid
Section titled “isValid”read-only
readonly isValid: boolean;False once the player has left. Calls on a player who left throw.
location
Section titled “location”read-only
readonly location: Vector3;Where their feet are.
onScreenDisplay
Section titled “onScreenDisplay”read-only
readonly onScreenDisplay: ScreenDisplay;What the player sees over the world: titles, the action bar, the HUD.
isSneaking
Section titled “isSneaking”read-only
readonly isSneaking: boolean;Whether the player is sneaking, as their client last said.
isSprinting
Section titled “isSprinting”read-only
readonly isSprinting: boolean;Whether the player is sprinting, as their client last said.
isFlying
Section titled “isFlying”read-only
readonly isFlying: boolean;Whether the player is flying, in creative or spectator.
isEmoting
Section titled “isEmoting”read-only
readonly isEmoting: boolean;Whether the player is playing an emote; it ends when they move or it finishes.
isGliding
Section titled “isGliding”read-only
readonly isGliding: boolean;Whether the player is gliding with elytra.
isJumping
Section titled “isJumping”read-only
readonly isJumping: boolean;Whether the player holds jump, as their latest input said.
selectedSlotIndex
Section titled “selectedSlotIndex”selectedSlotIndex: number;The hotbar slot held, from 0 to 8. Setting it selects another.
locale
Section titled “locale”read-only
readonly locale: string;The client’s language, as en_US.
clientSystemInfo
Section titled “clientSystemInfo”read-only
readonly clientSystemInfo: ClientSystemInfo;The device the player joined on.
read-only
readonly level: number;The experience level.
xpEarnedAtCurrentLevel
Section titled “xpEarnedAtCurrentLevel”read-only
readonly xpEarnedAtCurrentLevel: number;Experience gained since the level was reached.
totalXpNeededForNextLevel
Section titled “totalXpNeededForNextLevel”read-only
readonly totalXpNeededForNextLevel: number;Experience the level takes to finish.
inputInfo
Section titled “inputInfo”read-only
readonly inputInfo: PlayerInputInfo;How the player last steered: keyboard, touch, gamepad or motion controller.
inputPermissions
Section titled “inputPermissions”read-only
readonly inputPermissions: PlayerInputPermissions;Which of the player’s controls work; turn some off to hold them still.
commandPermissionLevel
Section titled “commandPermissionLevel”commandPermissionLevel: CommandPermissionLevel;The player’s permission level for slash commands.
playerPermissionLevel
Section titled “playerPermissionLevel”read-only
readonly playerPermissionLevel: PlayerPermissionLevel;The player’s operator/member permission level.
camera
Section titled “camera”read-only
readonly camera: Camera;The player’s camera.
fogSettings
Section titled “fogSettings”read-only
readonly fogSettings: FogSettings;The player’s client fog stack.
graphicsMode
Section titled “graphicsMode”read-only
readonly graphicsMode: GraphicsMode;The player’s graphics mode.
locatorBar
Section titled “locatorBar”read-only
readonly locatorBar: LocatorBar;The player’s locator bar.
Methods
Section titled “Methods”getRotation
Section titled “getRotation”getRotation(): Vector2;x is the pitch, y the yaw.
Vector2getGameMode
Section titled “getGameMode”getGameMode(): GameMode;The player’s game mode.
GameModesetGameMode
Section titled “setGameMode”setGameMode(gameMode?: GameMode): void;Puts the player in a game mode; undefined gives them the world’s default.
gameModeoptionalGameMode
getSpawnPoint
Section titled “getSpawnPoint”getSpawnPoint(): DimensionLocation | undefined;The bed or anchor they spawn at, if they set one.
DimensionLocation | undefinedsetSpawnPoint
Section titled “setSpawnPoint”setSpawnPoint(spawnPoint?: DimensionLocation | Vector3): void;Sets where the player comes back after dying, or with nothing the world’s spawn again. The dimension is always the overworld in Basalt.
spawnPointoptionalDimensionLocation | Vector3
getItemCooldown
Section titled “getItemCooldown”getItemCooldown(cooldownCategory: string): number;Ticks the player still waits on an item cooldown category, 0 for none.
cooldownCategorystring
numberstartItemCooldown
Section titled “startItemCooldown”startItemCooldown(cooldownCategory: string, tickDuration: number): void;Starts an item cooldown, greying the category’s items out on their screen.
cooldownCategorystringtickDurationnumber
getTotalXp
Section titled “getTotalXp”getTotalXp(): number;Every experience point the player has, their levels counted in.
numberaddExperience
Section titled “addExperience”addExperience(amount: number): number;Adds experience points, or takes them with a negative amount.
amountnumber
numberThe total after.addLevels
Section titled “addLevels”addLevels(amount: number): number;amountnumber
numberThe level after.resetLevel
Section titled “resetLevel”resetLevel(): void;Takes away every level and point of experience.
clearEffects
Section titled “clearEffects”clearEffects(): void;Takes every effect off. (addEffect/getEffect/getEffects/removeEffect are inherited from Entity.)
isOp(): boolean;Whether the player is an operator in permissions.json.
booleansendMessage
Section titled “sendMessage”sendMessage(message: string | RawMessage | (string | RawMessage)[]): void;Sends a chat message to this player alone.
messagestring | RawMessage | (string | RawMessage)[]
playSound
Section titled “playSound”playSound(soundId: string, soundOptions?: PlayerSoundOptions): void;Plays a sound to this player alone.
soundIdstringsoundOptionsoptionalPlayerSoundOptions
stopSound
Section titled “stopSound”stopSound(soundId: string): void;Stops a sound playing to this player, as /stopsound.
soundIdstring
stopAllSounds
Section titled “stopAllSounds”stopAllSounds(): void;Stops every sound playing to this player.
playMusic
Section titled “playMusic”playMusic(trackId: string, musicOptions?: MusicOptions): void;Plays a music track, as music.menu or record.pigstep, in place of what’s playing.
trackIdstringmusicOptionsoptionalMusicOptions
queueMusic
Section titled “queueMusic”queueMusic(trackId: string, musicOptions?: MusicOptions): void;Plays a music track once what’s playing ends.
trackIdstringmusicOptionsoptionalMusicOptions
stopMusic
Section titled “stopMusic”stopMusic(): void;Stops the music, the queue too.
spawnParticle
Section titled “spawnParticle”spawnParticle(effectName: string, location: Vector3, molangVariables?: MolangVariableMap): void;Shows this player alone a particle effect, built in or a pack’s, as minecraft:heart_particle.
effectNamestringlocationVector3molangVariablesoptionalMolangVariableMap
eatItem
Section titled “eatItem”eatItem(itemStack: ItemStack): void;Gives the player what eating the food would, at once: hunger, saturation and its effects. Nothing is taken from their inventory. A potion gives its effects.
itemStackItemStack
- If the item isn’t a food or potion.
teleport
Section titled “teleport”teleport(location: Vector3, teleportOptions?: TeleportOptions): void;Moves the player, turned to rotation if given.
locationVector3teleportOptionsoptionalTeleportOptions
runCommand
Section titled “runCommand”runCommand(commandString: string): CommandResult;Runs a command as this player, without its slash, at the player’s own permission.
commandStringstring
CommandResultA result whose count is 1 once the command is queued.runCommandAsync
Section titled “runCommandAsync”runCommandAsync(commandString: string): Promise<CommandResult>;Runs a command as this player.
commandStringstring
Promise<CommandResult>setVelocity
Section titled “setVelocity”setVelocity(velocity: Vector3): void;Sets the player’s motion outright, sent to their client at once.
velocityVector3
applyImpulse
Section titled “applyImpulse”applyImpulse(vector: Vector3): void;Adds to the player’s motion: what their client last reported, plus the push.
vectorVector3
getVelocity
Section titled “getVelocity”getVelocity(): Vector3;How the player moves, in blocks a tick, as their client last reported it.
Vector3setInputPermissions
Section titled “setInputPermissions”setInputPermissions(categories: Partial<Record<InputPermissionCategory, boolean>>): void;Turns input permission categories on or off at once, keyed by
InputPermissionCategory; categories left out are unchanged.
categoriesPartial<Record<InputPermissionCategory, boolean>>
Example
player.setInputPermissions({ [InputPermissionCategory.Movement]: false });resetInputPermissions
Section titled “resetInputPermissions”resetInputPermissions(): void;Turns every input permission category back on.
kick(reason?: string): void;Disconnects the player with a reason.
reasonoptionalstring
sendToast
Section titled “sendToast”sendToast(title: string | RawMessage, message: string | RawMessage): void;A toast at the top of the screen.
titlestring | RawMessagemessagestring | RawMessage
addBossBar
Section titled “addBossBar”addBossBar(title: string | RawMessage, options?: BossBarOptions): BossBar;Shows this player a boss bar, to change or remove later.
titlestring | RawMessageoptionsoptionalBossBarOptions
BossBarhidePlayer
Section titled “hidePlayer”hidePlayer(player: Player): void;This player stops seeing player, who stays in the player list.
playerPlayer
showPlayer
Section titled “showPlayer”showPlayer(player: Player): void;Undoes Player.hidePlayer.
playerPlayer
canSee
Section titled “canSee”canSee(player: Player): boolean;Whether this player sees player.
playerPlayer
booleangetAimAssist
Section titled “getAimAssist”getAimAssist(): PlayerAimAssist;The player’s aim-assist settings.
PlayerAimAssistgetControlScheme
Section titled “getControlScheme”getControlScheme(): ControlScheme;How the player’s controls are laid out.
ControlSchemesetControlScheme
Section titled “setControlScheme”setControlScheme(controlScheme?: ControlScheme): void;Sets the control scheme, or clears an override with nothing.
controlSchemeoptionalControlScheme
setPropertyOverrideForEntity
Section titled “setPropertyOverrideForEntity”setPropertyOverrideForEntity(targetEntity: Entity, identifier: string, value: boolean | number | string): void;Overrides a client entity property this player sees on an entity.
targetEntityEntityidentifierstringvalueboolean | number | string
removePropertyOverrideForEntity
Section titled “removePropertyOverrideForEntity”removePropertyOverrideForEntity(targetEntity: Entity, identifier: string): void;Clears one such override.
targetEntityEntityidentifierstring
clearPropertyOverridesForEntity
Section titled “clearPropertyOverridesForEntity”clearPropertyOverridesForEntity(targetEntity: Entity | string): void;Clears every such override on an entity.
targetEntityEntity | string
Used by
Section titled “Used by”ItemCooldownComponent.getCooldownTicksRemaining, ItemCooldownComponent.startCooldown, ItemEntity.owner, ItemEntity.showTo, ItemEntity.hideFrom, BossBar.player, Dimension.getPlayers, ChatSendAfterEvent.sender, ChatSendBeforeEvent.sender, PlayerSpawnAfterEvent.player, PlayerLeaveBeforeEvent.player, PlayerHurtAfterEvent.hurtEntity, PlayerHurtBeforeEvent.hurtEntity, PlayerBreakBlockBeforeEvent.player, PlayerBreakBlockAfterEvent.player, PlayerPlaceBlockBeforeEvent.player, PlayerPlaceBlockAfterEvent.player, PlayerInteractWithBlockAfterEvent.player, PlayerInteractWithEntityAfterEvent.player, ItemUseAfterEvent.source, PlayerPickupItemAfterEvent.player, PlayerDropItemAfterEvent.player, PlayerGameModeChangeAfterEvent.player, PlayerTeleportAfterEvent.player and 59 more
Inherited
Section titled “Inherited”From Entity: id, dimension, localizationKey, isOnGround, isInWater, isFalling, fallDistance, isClimbing, isSwimming, getHeadLocation, getComponent, getComponents, hasComponent, matches, getViewDirection, clearVelocity, applyKnockback, getTags, hasTag, addTag, removeTag, getDynamicProperty, setDynamicProperty, setDynamicProperties, getDynamicPropertyIds, getDynamicPropertyTotalByteCount, clearDynamicProperties, scoreboardIdentity, kill, remove, isSleeping, addEffect, getEffect, getEffects, removeEffect, addItem, applyDamage, setOnFire, extinguishFire, lookAt, setRotation, playAnimation, triggerEvent, tryTeleport, getProperty, setProperty, resetProperty, getBlockFromViewDirection, getEntitiesFromViewDirection, getBlockStandingOn, getAllBlocksStandingOn, getAABB, nameplateDepthTested, nameplateRenderDistance