Script API - v1.20.10
    Preparing search index...

    Contains a set of events that are available across the scope of the World.

    Index

    Properties

    This event fires when a button is pushed.

    import { world } from "@minecraft/server";

    world.afterEvents.buttonPush.subscribe((event) => {
    console.log("Button: ", event.block.typeId);
    console.log("Dimension: ", event.dimension.id);
    console.log("Source: ", event.source.typeId);
    });

    This event fires when a player joins a world. See also playerSpawn for another related event you can trap for when a player is spawned the first time within a world.

    import { world } from "@minecraft/server";
    world.afterEvents.playerJoin.subscribe(({ playerId, playerName }) => {
    world.sendMessage(
    `Player ${playerName} (${playerId}) has just joined the world.`
    );
    });

    This event fires when a player leaves a world.

    import { world } from "@minecraft/server";
    world.afterEvents.playerLeave.subscribe(({ playerId, playerName }) => {
    world.sendMessage(
    `Player ${playerName} (${playerId}) has just left the world.`
    );
    });

    This event fires when a player spawns or respawns. Note that an additional flag within this event will tell you whether the player is spawning right after join vs. a respawn.

    import { world } from "@minecraft/server";

    world.afterEvents.playerSpawn.subscribe((eventData) => {
    let { player, initialSpawn } = eventData;
    if (!initialSpawn) return;

    // This runs when the player joins the game for the first time!
    });