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)

Implements

Constructors

Accessors

  • get chatSend(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.chatSend",
            ChatSendBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.chatSend">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<"world.beforeEvents.chatSend">,
        ): void;
    }
    Beta

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.chatSend",
            ChatSendBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.chatSend">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<"world.beforeEvents.chatSend">,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.chatSend">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.chatSend event.

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

    This property can be read in early-execution mode.

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

    function customCommand(targetLocation: DimensionLocation) {
    const chatCallback = Events.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;
    }
    }
    }
    }`);
    }
  • get effectAdd(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.effectAdd",
            EffectAddBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.effectAdd">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<"world.beforeEvents.effectAdd">,
        ): void;
    }

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.effectAdd",
            EffectAddBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.effectAdd">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<"world.beforeEvents.effectAdd">,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.effectAdd">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.effectAdd event.

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

    This property can be read in early-execution mode.

  • get entityRemove(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.entityRemove",
            EntityRemoveBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.entityRemove">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.entityRemove",
            >,
        ): void;
    }

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.entityRemove",
            EntityRemoveBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.entityRemove">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.entityRemove",
            >,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.entityRemove">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.entityRemove event.

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

    This property can be read in early-execution mode.

  • get explosion(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.explosion",
            ExplosionBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.explosion">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<"world.beforeEvents.explosion">,
        ): void;
    }

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.explosion",
            ExplosionBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.explosion">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<"world.beforeEvents.explosion">,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.explosion">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.explosion event.

    This event is fired after an explosion occurs.

    This property can be read in early-execution mode.

  • get itemUse(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.itemUse",
            ItemUseBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.itemUse">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<"world.beforeEvents.itemUse">,
        ): void;
    }

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.itemUse",
            ItemUseBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.itemUse">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<"world.beforeEvents.itemUse">,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.itemUse">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.itemUse event.

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

    This property can be read in early-execution mode.

  • get playerBreakBlock(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerBreakBlock",
            PlayerBreakBlockBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerBreakBlock">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.playerBreakBlock",
            >,
        ): void;
    }

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerBreakBlock",
            PlayerBreakBlockBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerBreakBlock">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.playerBreakBlock",
            >,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.playerBreakBlock">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.playerBreakBlock event.

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

    This property can be read in early-execution mode.

  • get playerGameModeChange(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerGameModeChange",
            PlayerGameModeChangeBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerGameModeChange">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.playerGameModeChange",
            >,
        ): void;
    }

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerGameModeChange",
            PlayerGameModeChangeBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerGameModeChange">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.playerGameModeChange",
            >,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.playerGameModeChange">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.playerGameModeChange event.

    This property can be read in early-execution mode.

  • get playerInteractWithBlock(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerInteractWithBlock",
            PlayerInteractWithBlockBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerInteractWithBlock">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.playerInteractWithBlock",
            >,
        ): void;
    }

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerInteractWithBlock",
            PlayerInteractWithBlockBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerInteractWithBlock">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.playerInteractWithBlock",
            >,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.playerInteractWithBlock">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.playerInteractWithBlock event.

    Fires before a player interacts with a block.

    This property can be read in early-execution mode.

  • get playerInteractWithEntity(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerInteractWithEntity",
            PlayerInteractWithEntityBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerInteractWithEntity">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.playerInteractWithEntity",
            >,
        ): void;
    }

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerInteractWithEntity",
            PlayerInteractWithEntityBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerInteractWithEntity">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.playerInteractWithEntity",
            >,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.playerInteractWithEntity">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.playerInteractWithEntity event.

    Fires before a player interacts with an entity.

    This property can be read in early-execution mode.

  • get playerLeave(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerLeave",
            PlayerLeaveBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerLeave">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<"world.beforeEvents.playerLeave">,
        ): void;
    }

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerLeave",
            PlayerLeaveBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerLeave">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<"world.beforeEvents.playerLeave">,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.playerLeave">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.playerLeave event.

    Fires when a player leaves the game.

    This property can be read in early-execution mode.

  • get playerPlaceBlock(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerPlaceBlock",
            PlayerPlaceBlockBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerPlaceBlock">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.playerPlaceBlock",
            >,
        ): void;
    }
    Beta

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.playerPlaceBlock",
            PlayerPlaceBlockBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.playerPlaceBlock">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.playerPlaceBlock",
            >,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.playerPlaceBlock">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.playerPlaceBlock event.

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

    This property can be read in early-execution mode.

  • get weatherChange(): {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.weatherChange",
            WeatherChangeBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.weatherChange">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.weatherChange",
            >,
        ): void;
    }

    Returns {
        getAll(): Globals.SubscribedEvent<
            "world.beforeEvents.weatherChange",
            WeatherChangeBeforeEventSignal,
        >[];
        subscribe(
            callback: string,
        ): Globals.SubscribedEvent<"world.beforeEvents.weatherChange">;
        unsubscribe(
            subscription: Globals.SubscribedEvent<
                "world.beforeEvents.weatherChange",
            >,
        ): void;
    }

    • getAll:function
    • subscribe:function
      • Creates a new event subscription.

        Parameters

        • callback: string

        Returns Globals.SubscribedEvent<"world.beforeEvents.weatherChange">

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the event callback is an empty string.

        If the event callback is not a string.

        If the event callback is not a valid stringified JavaScript function.

    • unsubscribe:function
      • Deletes the provided event subscription.

        Parameters

        Returns void

        This function can't be called in read-only mode.

        This function can be called in early-execution mode.

        If the subscription is not an instance of SubscribedEvent.

        If the subscription is not for the world.beforeEvents.weatherChange event.

    This property can be read in early-execution mode.