@minecraft/server
    Preparing search index...

    Class WorldBeforeEventsBeta

    A set of events that fire before an actual action occurs. In most cases, you can potentially cancel or modify the impending event. Note that in before events any APIs that modify gameplay state will not function and will throw an error. (e.g., dimension.spawnEntity)

    Index

    Properties

    This event is triggered after a chat message has been broadcast or sent to players.

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

    function customCommand(targetLocation: DimensionLocation) {
    const chatCallback = world.beforeEvents.chatSend.subscribe((eventData) => {
    if (eventData.message.includes("cancel")) {
    // Cancel event if the message contains "cancel"
    eventData.cancel = true;
    } else {
    const args = eventData.message.split(" ");

    if (args.length > 0) {
    switch (args[0].toLowerCase()) {
    case "echo":
    // Send a modified version of chat message
    world.sendMessage(`Echo '${eventData.message.substring(4).trim()}'`);
    break;
    case "help":
    world.sendMessage(`Available commands: echo <message>`);
    break;
    }
    }
    }
    });
    }

    This event is triggered after an event has been added to an entity.

    Fires before an entity is removed from the world (for example, unloaded or removed after being killed.)

    This event is fired after an explosion occurs.

    This event fires when an item is successfully used by a player.

    This event fires when an item is used on a block by a player.

    This event fires before a block is broken by a player.

    Fires before a player interacts with a block.

    Fires before a player interacts with an entity.

    Fires when a player leaves the game.

    This event fires before a block is placed by a player.