Provides a set of events that fire within the broader scripting system within Minecraft.

Hierarchy

  • SystemAfterEvents

Constructors

Properties

Constructors

Properties

Remarks

An event that fires when a /scriptevent command is set. This provides a way for commands and other systems to trigger behavior within script.

Example

entity.js

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

system.afterEvents.scriptEventReceive.subscribe((event) => {
const { id, message, sourceEntity, sourceType } = event;

console.log(id); // wiki:test
console.log(message); // Hello World
console.log(sourceEntity); // Player object
console.log(sourceType); // Entity
});

world.getPlayers().forEach((player) => {
player.runCommand("scriptevent wiki:test Hello World");
});

Example

server.js

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

system.afterEvents.scriptEventReceive.subscribe((event) => {
const { id, message, sourceType } = event;

console.log(id); // wiki:test
console.log(message); // Hello World
console.log(sourceType); // Server
});

world.getDimension("overworld").runCommand("scriptevent wiki:test Hello World");