Skip to content
BasaltSoftware
Bedrock 1.26.60

Site colour

Discord
Esc

    ↑↓ moveEnter openEsc close

    Keyboard shortcuts
    Ctrl K
    Search the whole site, from any page
    /
    Jump to the sidebar search, or search the whole site where there isn't one
    Enter
    Open the top search result
    Esc
    Clear the search, or close this panel
    ?
    Show these shortcuts

    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';
    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));

    read-only

    readonly name: string;

    The player’s gamertag.

    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.

    read-only

    readonly typeId: string;

    Always "minecraft:player".

    read-only

    readonly isValid: boolean;

    False once the player has left. Calls on a player who left throw.

    read-only

    readonly location: Vector3;

    Where their feet are.

    Types

    read-only

    readonly onScreenDisplay: ScreenDisplay;

    What the player sees over the world: titles, the action bar, the HUD.

    read-only

    readonly isSneaking: boolean;

    Whether the player is sneaking, as their client last said.

    read-only

    readonly isSprinting: boolean;

    Whether the player is sprinting, as their client last said.

    read-only

    readonly isFlying: boolean;

    Whether the player is flying, in creative or spectator.

    read-only

    readonly isEmoting: boolean;

    Whether the player is playing an emote; it ends when they move or it finishes.

    read-only

    readonly isGliding: boolean;

    Whether the player is gliding with elytra.

    read-only

    readonly isJumping: boolean;

    Whether the player holds jump, as their latest input said.

    selectedSlotIndex: number;

    The hotbar slot held, from 0 to 8. Setting it selects another.

    read-only

    readonly locale: string;

    The client’s language, as en_US.

    read-only

    readonly clientSystemInfo: ClientSystemInfo;

    The device the player joined on.

    read-only

    readonly level: number;

    The experience level.

    read-only

    readonly xpEarnedAtCurrentLevel: number;

    Experience gained since the level was reached.

    read-only

    readonly totalXpNeededForNextLevel: number;

    Experience the level takes to finish.

    read-only

    readonly inputInfo: PlayerInputInfo;

    How the player last steered: keyboard, touch, gamepad or motion controller.

    read-only

    readonly inputPermissions: PlayerInputPermissions;

    Which of the player’s controls work; turn some off to hold them still.

    commandPermissionLevel: CommandPermissionLevel;

    The player’s permission level for slash commands.

    read-only

    readonly playerPermissionLevel: PlayerPermissionLevel;

    The player’s operator/member permission level.

    read-only

    readonly camera: Camera;

    The player’s camera.

    Types

    read-only

    readonly fogSettings: FogSettings;

    The player’s client fog stack.

    read-only

    readonly graphicsMode: GraphicsMode;

    The player’s graphics mode.

    read-only

    readonly locatorBar: LocatorBar;

    The player’s locator bar.

    getRotation(): Vector2;

    x is the pitch, y the yaw.

    Returns
    Vector2
    Types
    getGameMode(): GameMode;

    The player’s game mode.

    Returns
    GameMode
    setGameMode(gameMode?: GameMode): void;

    Puts the player in a game mode; undefined gives them the world’s default.

    Parameters
    gameModeoptional
    GameMode
    getSpawnPoint(): DimensionLocation | undefined;

    The bed or anchor they spawn at, if they set one.

    Returns
    DimensionLocation | undefined
    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.

    Parameters
    spawnPointoptional
    DimensionLocation | Vector3
    getItemCooldown(cooldownCategory: string): number;

    Ticks the player still waits on an item cooldown category, 0 for none.

    Parameters
    cooldownCategory
    string
    Returns
    number
    startItemCooldown(cooldownCategory: string, tickDuration: number): void;

    Starts an item cooldown, greying the category’s items out on their screen.

    Parameters
    cooldownCategory
    string
    tickDuration
    number
    getTotalXp(): number;

    Every experience point the player has, their levels counted in.

    Returns
    number
    addExperience(amount: number): number;

    Adds experience points, or takes them with a negative amount.

    Parameters
    amount
    number
    Returns
    numberThe total after.
    addLevels(amount: number): number;
    Parameters
    amount
    number
    Returns
    numberThe level after.
    resetLevel(): void;

    Takes away every level and point of experience.

    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.

    Returns
    boolean
    sendMessage(message: string | RawMessage | (string | RawMessage)[]): void;

    Sends a chat message to this player alone.

    Parameters
    message
    string | RawMessage | (string | RawMessage)[]
    playSound(soundId: string, soundOptions?: PlayerSoundOptions): void;

    Plays a sound to this player alone.

    Parameters
    soundId
    string
    soundOptionsoptional
    PlayerSoundOptions
    stopSound(soundId: string): void;

    Stops a sound playing to this player, as /stopsound.

    Parameters
    soundId
    string
    stopAllSounds(): void;

    Stops every sound playing to this player.

    playMusic(trackId: string, musicOptions?: MusicOptions): void;

    Plays a music track, as music.menu or record.pigstep, in place of what’s playing.

    Parameters
    trackId
    string
    musicOptionsoptional
    MusicOptions
    queueMusic(trackId: string, musicOptions?: MusicOptions): void;

    Plays a music track once what’s playing ends.

    Parameters
    trackId
    string
    musicOptionsoptional
    MusicOptions
    stopMusic(): void;

    Stops the music, the queue too.

    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.

    Parameters
    effectName
    string
    location
    Vector3
    molangVariablesoptional
    MolangVariableMap
    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.

    Parameters
    itemStack
    ItemStack
    Throws
    • If the item isn’t a food or potion.
    teleport(location: Vector3, teleportOptions?: TeleportOptions): void;

    Moves the player, turned to rotation if given.

    Parameters
    location
    Vector3
    teleportOptionsoptional
    TeleportOptions
    runCommand(commandString: string): CommandResult;

    Runs a command as this player, without its slash, at the player’s own permission.

    Parameters
    commandString
    string
    Returns
    CommandResultA result whose count is 1 once the command is queued.
    runCommandAsync(commandString: string): Promise<CommandResult>;

    Runs a command as this player.

    Parameters
    commandString
    string
    Returns
    Promise<CommandResult>
    setVelocity(velocity: Vector3): void;

    Sets the player’s motion outright, sent to their client at once.

    Parameters
    velocity
    Vector3
    Types
    applyImpulse(vector: Vector3): void;

    Adds to the player’s motion: what their client last reported, plus the push.

    Parameters
    vector
    Vector3
    Types
    getVelocity(): Vector3;

    How the player moves, in blocks a tick, as their client last reported it.

    Returns
    Vector3
    Types
    setInputPermissions(categories: Partial<Record<InputPermissionCategory, boolean>>): void;

    Turns input permission categories on or off at once, keyed by InputPermissionCategory; categories left out are unchanged.

    Parameters
    categories
    Partial<Record<InputPermissionCategory, boolean>>

    Example

    player.setInputPermissions({ [InputPermissionCategory.Movement]: false });
    resetInputPermissions(): void;

    Turns every input permission category back on.

    kick(reason?: string): void;

    Disconnects the player with a reason.

    Parameters
    reasonoptional
    string
    sendToast(title: string | RawMessage, message: string | RawMessage): void;

    A toast at the top of the screen.

    Parameters
    title
    string | RawMessage
    message
    string | RawMessage
    addBossBar(title: string | RawMessage, options?: BossBarOptions): BossBar;

    Shows this player a boss bar, to change or remove later.

    Parameters
    title
    string | RawMessage
    optionsoptional
    BossBarOptions
    Returns
    BossBar
    hidePlayer(player: Player): void;

    This player stops seeing player, who stays in the player list.

    Parameters
    player
    Player
    showPlayer(player: Player): void;

    Undoes Player.hidePlayer.

    Parameters
    player
    Player
    canSee(player: Player): boolean;

    Whether this player sees player.

    Parameters
    player
    Player
    Returns
    boolean
    getAimAssist(): PlayerAimAssist;

    The player’s aim-assist settings.

    Returns
    PlayerAimAssist
    getControlScheme(): ControlScheme;

    How the player’s controls are laid out.

    Returns
    ControlScheme
    setControlScheme(controlScheme?: ControlScheme): void;

    Sets the control scheme, or clears an override with nothing.

    Parameters
    controlSchemeoptional
    ControlScheme
    setPropertyOverrideForEntity(targetEntity: Entity, identifier: string, value: boolean | number | string): void;

    Overrides a client entity property this player sees on an entity.

    Parameters
    targetEntity
    Entity
    identifier
    string
    value
    boolean | number | string
    Types
    removePropertyOverrideForEntity(targetEntity: Entity, identifier: string): void;

    Clears one such override.

    Parameters
    targetEntity
    Entity
    identifier
    string
    Types
    clearPropertyOverridesForEntity(targetEntity: Entity | string): void;

    Clears every such override on an entity.

    Parameters
    targetEntity
    Entity | string
    Types

    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

    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