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.
Example: subscribe.js
import { world } from"@minecraft/server"; world.afterEvents.playerJoin.subscribe(({ playerId, playerName }) => { world.sendMessage( `Player ${playerName} (${playerId}) has just joined the 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.
Example: initialSpawn.js
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! });
Contains a set of events that are available across the scope of the World.