跳到主要内容

世界前事件

本文主要记录世界前事件相关接口。

前事件在事件实际发生前触发,多数前事件都可以取消事件的发生。在前事件的回调中,代码处于受限执行状态,无法执行会更改世界的代码,必须使用system.run()延后执行。


世界前事件表​

世界前事件(World Before Events) 是指事件实际发生前执行的代码。多数前事件都可以取消事件实际发生。前事件会导致代码进入受限执行,无法执行会更改世界的代码,必须使用system.run()延后执行。

事件事件类是否支持筛选项是否可取消脚本版本
使用物品ItemUseBeforeEvent不支持是1.4.0
实体移除EntityRemoveBeforeEvent不支持否1.6.0
玩家破坏方块PlayerBreakBlockBeforeEventBlockEventOptions是1.6.0
玩家离开PlayerLeaveBeforeEvent不支持否1.7.0
添加状态效果EffectAddBeforeEvent不支持是1.9.0
爆炸ExplosionBeforeEvent不支持是1.9.0
玩家游戏模式更改PlayerGameModeChangeBeforeEvent不支持是1.11.0
天气更改WeatherChangeBeforeEvent不支持是1.11.0
玩家与方块交互PlayerInteractWithBlockBeforeEvent不支持是1.15.0
玩家与实体交互PlayerInteractWithEntityBeforeEvent不支持是1.15.0
实体回复生命EntityHealBeforeEventEntityHealEventOptions是2.6.0
实体受伤EntityHurtBeforeEventEntityHurtBeforeEventOptions是2.6.0
实体拾取物品EntityItemPickupBeforeEventEntityItemPickupEventOptions是2.6.0
实体被驯服EntityTamedBeforeEventEntityTamedEventOptions是2.10.0
世界时钟重启WorldClockOnRestartBeforeEventWorldClockEventOptions是2.11.0
发送聊天消息ChatSendBeforeEvent不支持是beta
玩家放置方块PlayerPlaceBlockBeforeEventBlockEventOptions是beta
玩家物品攻击实体PlayerItemAttackEntityBeforeEvent不支持是beta

备注:

  • 是否支持筛选项是指事件的订阅函数subscribe是否支持第二个参数options。若支持,则给出它的类型。

使用物品事件​

ItemUseBeforeEventSignal 类​

1.4.0+
该特性在server模块脚本版本1.4.0+下可用。

当使用物品前触发该事件信号。

class ItemUseBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: ItemUseBeforeEvent) => void): (arg0: ItemUseBeforeEvent) => void;
unsubscribe(callback: (arg0: ItemUseBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: ItemUseBeforeEvent) => void) => (arg0: ItemUseBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: ItemUseBeforeEvent) => void) => void,取消订阅该事件。

ItemUseBeforeEvent 类​

1.4.0+
该特性在server模块脚本版本1.4.0+下可用。

使用物品前的事件信息。

class ItemUseBeforeEvent {
private constructor();
cancel: boolean;
}

属性​

  • cancel: boolean,若设为true,将取消使用物品的行为。

实体移除事件​

EntityRemoveBeforeEventSignal 类​

1.6.0+
该特性在server模块脚本版本1.6.0+下可用。

当实体移除前触发该事件信号。

class EntityRemoveBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: EntityRemoveBeforeEvent) => void): (arg0: EntityRemoveBeforeEvent) => void;
unsubscribe(callback: (arg0: EntityRemoveBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: EntityRemoveBeforeEvent) => void) => (arg0: EntityRemoveBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: EntityRemoveBeforeEvent) => void) => void,取消订阅该事件。

EntityRemoveBeforeEvent 类​

1.6.0+
该特性在server模块脚本版本1.6.0+下可用。

实体移除前的事件信息。

class EntityRemoveBeforeEvent {
private constructor();
readonly removedEntity: Entity;
}

属性​

  • 只读 removedEntity: Entity,即将从游戏中移除的实体的引用。

玩家破坏方块事件​

PlayerBreakBlockBeforeEventSignal 类​

1.6.0+
该特性在server模块脚本版本1.6.0+下可用。

当玩家破坏方块前触发该事件信号。

class PlayerBreakBlockBeforeEventSignal {
private constructor();
subscribe(
callback: (arg0: PlayerBreakBlockBeforeEvent) => void,
options?: BlockEventOptions,
): (arg0: PlayerBreakBlockBeforeEvent) => void;
unsubscribe(callback: (arg0: PlayerBreakBlockBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: PlayerBreakBlockBeforeEvent) => void, options?: BlockEventOptions) => (arg0: PlayerBreakBlockBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: PlayerBreakBlockBeforeEvent) => void) => void,取消订阅该事件。

PlayerBreakBlockBeforeEvent 类​

1.6.0+
该特性在server模块脚本版本1.6.0+下可用。

玩家破坏方块前的事件信息。其筛选项见BlockEventOptions。

class PlayerBreakBlockBeforeEvent {
private constructor();
cancel: boolean;
itemStack?: ItemStack;
readonly player: Player;
}

属性​

  • cancel: boolean,若设为true,将取消该方块破坏事件。
  • 可选 itemStack: ItemStack,用于破坏该方块的物品堆叠,空手时为undefined。
  • 只读 player: Player,触发该事件的破坏方块的玩家。

玩家离开事件​

PlayerLeaveBeforeEventSignal 类​

1.7.0+
该特性在server模块脚本版本1.7.0+下可用。

当玩家离开前触发该事件信号。

class PlayerLeaveBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: PlayerLeaveBeforeEvent) => void): (arg0: PlayerLeaveBeforeEvent) => void;
unsubscribe(callback: (arg0: PlayerLeaveBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: PlayerLeaveBeforeEvent) => void) => (arg0: PlayerLeaveBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: PlayerLeaveBeforeEvent) => void) => void,取消订阅该事件。

PlayerLeaveBeforeEvent 类​

1.7.0+
该特性在server模块脚本版本1.7.0+下可用。

玩家离开前的事件信息。

class PlayerLeaveBeforeEvent {
private constructor();
readonly player: Player;
}

属性​

  • 只读 player: Player,离开的玩家。

添加状态效果事件​

EffectAddBeforeEventSignal 类​

1.9.0+
该特性在server模块脚本版本1.9.0+下可用。

当添加状态效果前触发该事件信号。

class EffectAddBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: EffectAddBeforeEvent) => void): (arg0: EffectAddBeforeEvent) => void;
unsubscribe(callback: (arg0: EffectAddBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: EffectAddBeforeEvent) => void) => (arg0: EffectAddBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: EffectAddBeforeEvent) => void) => void,取消订阅该事件。

EffectAddBeforeEvent 类​

1.9.0+
该特性在server模块脚本版本1.9.0+下可用。

添加状态效果前的事件信息。

class EffectAddBeforeEvent {
private constructor();
cancel: boolean;
duration: number;
readonly effectType: string;
readonly entity: Entity;
}

属性​

  • cancel: boolean,设为true时将取消该事件。
  • duration: number,状态效果的持续时间。
  • 只读 effectType: string,即将添加的状态效果的类型。
  • 只读 entity: Entity,即将被添加状态效果的实体。

爆炸事件​

ExplosionBeforeEventSignal 类​

1.9.0+
该特性在server模块脚本版本1.9.0+下可用。

当爆炸前触发该事件信号。

class ExplosionBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: ExplosionBeforeEvent) => void): (arg0: ExplosionBeforeEvent) => void;
unsubscribe(callback: (arg0: ExplosionBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: ExplosionBeforeEvent) => void) => (arg0: ExplosionBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: ExplosionBeforeEvent) => void) => void,取消订阅该事件。

ExplosionBeforeEvent 类​

1.9.0+
该特性在server模块脚本版本1.9.0+下可用。

爆炸前的事件信息。

class ExplosionBeforeEvent {
private constructor();
cancel: boolean;
setImpactedBlocks(blocks: Block[]): void;
}

属性​

  • cancel: boolean,若设为true,将取消该爆炸事件。

方法​

  • setImpactedBlocks: (blocks: Block[]) => void,更新受该爆炸事件影响的方块集合。

玩家游戏模式更改事件​

PlayerGameModeChangeBeforeEventSignal 类​

1.11.0+
该特性在server模块脚本版本1.11.0+下可用。

当玩家游戏模式更改前触发该事件信号。

class PlayerGameModeChangeBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: PlayerGameModeChangeBeforeEvent) => void): (arg0: PlayerGameModeChangeBeforeEvent) => void;
unsubscribe(callback: (arg0: PlayerGameModeChangeBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: PlayerGameModeChangeBeforeEvent) => void) => (arg0: PlayerGameModeChangeBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: PlayerGameModeChangeBeforeEvent) => void) => void,取消订阅该事件。

PlayerGameModeChangeBeforeEvent 类​

1.11.0+
该特性在server模块脚本版本1.11.0+下可用。

玩家游戏模式更改前的事件信息。

class PlayerGameModeChangeBeforeEvent {
private constructor();
cancel: boolean;
readonly fromGameMode: GameMode;
readonly player: Player;
toGameMode: GameMode;
}

属性​

  • cancel: boolean,若设为true,将取消该游戏模式更改。
  • 只读 fromGameMode: GameMode,当前游戏模式。
  • 只读 player: Player,触发该事件的玩家。
  • toGameMode: GameMode,即将更改到的游戏模式。

天气更改事件​

WeatherChangeBeforeEventSignal 类​

1.11.0+
该特性在server模块脚本版本1.11.0+下可用。

当天气更改前触发该事件信号。

class WeatherChangeBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: WeatherChangeBeforeEvent) => void): (arg0: WeatherChangeBeforeEvent) => void;
unsubscribe(callback: (arg0: WeatherChangeBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: WeatherChangeBeforeEvent) => void) => (arg0: WeatherChangeBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: WeatherChangeBeforeEvent) => void) => void,取消订阅该事件。

WeatherChangeBeforeEvent 类​

1.11.0+
该特性在server模块脚本版本1.11.0+下可用。

天气更改前的事件信息。

class WeatherChangeBeforeEvent {
private constructor();
cancel: boolean;
duration: number;
newWeather: WeatherType;
readonly previousWeather: WeatherType;
}

属性​

  • cancel: boolean,若设为true,将取消该天气更改。
  • duration: number,设置新天气的持续时间(单位:游戏刻)。
  • newWeather: WeatherType,即将应用的天气类型。
  • 只读 previousWeather: WeatherType,事件触发前的天气类型。

玩家与方块交互事件​

PlayerInteractWithBlockBeforeEventSignal 类​

1.15.0+
该特性在server模块脚本版本1.15.0+下可用。

当玩家与方块交互前触发该事件信号。

class PlayerInteractWithBlockBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: PlayerInteractWithBlockBeforeEvent) => void): (arg0: PlayerInteractWithBlockBeforeEvent) => void;
unsubscribe(callback: (arg0: PlayerInteractWithBlockBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: PlayerInteractWithBlockBeforeEvent) => void) => (arg0: PlayerInteractWithBlockBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: PlayerInteractWithBlockBeforeEvent) => void) => void,取消订阅该事件。

PlayerInteractWithBlockBeforeEvent 类​

1.15.0+
该特性在server模块脚本版本1.15.0+下可用。

玩家与方块交互前的事件信息。

class PlayerInteractWithBlockBeforeEvent {
private constructor();
readonly block: Block;
readonly blockFace: Direction;
cancel: boolean;
readonly faceLocation: Vector3;
readonly isFirstEvent: boolean;
readonly itemStack?: ItemStack;
readonly player: Player;
}

属性​

  • 只读 block: Block,即将被交互的方块。
  • 只读 blockFace: Direction,被交互的方块的面。
  • cancel: boolean,若设为true,将取消该交互。
  • 只读 faceLocation: Vector3,相对于所交互方块的底部西北角的坐标。
  • 只读 isFirstEvent: boolean,若事件由玩家初次按下交互按钮触发,该值为true;若是长按交互按钮触发,则为false。
  • 只读 可选 itemStack: ItemStack,交互中所使用的物品堆叠,空手时为undefined。
  • 只读 player: Player,触发该事件的玩家。

玩家与实体交互事件​

PlayerInteractWithEntityBeforeEventSignal 类​

1.15.0+
该特性在server模块脚本版本1.15.0+下可用。

当玩家与实体交互前触发该事件信号。

class PlayerInteractWithEntityBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: PlayerInteractWithEntityBeforeEvent) => void): (arg0: PlayerInteractWithEntityBeforeEvent) => void;
unsubscribe(callback: (arg0: PlayerInteractWithEntityBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: PlayerInteractWithEntityBeforeEvent) => void) => (arg0: PlayerInteractWithEntityBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: PlayerInteractWithEntityBeforeEvent) => void) => void,取消订阅该事件。

PlayerInteractWithEntityBeforeEvent 类​

1.15.0+
该特性在server模块脚本版本1.15.0+下可用。

玩家与实体交互前的事件信息。

class PlayerInteractWithEntityBeforeEvent {
private constructor();
cancel: boolean;
readonly itemStack?: ItemStack;
readonly player: Player;
readonly target: Entity;
}

属性​

  • cancel: boolean,若设为true,将取消该交互。
  • 只读 可选 itemStack: ItemStack,交互中所使用的物品堆叠,空手时为undefined。
  • 只读 player: Player,触发该事件的玩家。
  • 只读 target: Entity,即将被交互的实体。

实体回复生命事件​

EntityHealBeforeEventSignal 类​

2.6.0+
该特性在server模块脚本版本2.6.0+下可用,但该版本对于当前的中国版版本过高。

当实体回复生命前触发该事件信号。

class EntityHealBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: EntityHealBeforeEvent) => void, options?: EntityHealEventOptions): (arg0: EntityHealBeforeEvent) => void;
unsubscribe(callback: (arg0: EntityHealBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: EntityHealBeforeEvent) => void, options?: EntityHealEventOptions) => (arg0: EntityHealBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: EntityHealBeforeEvent) => void) => void,取消订阅该事件。

EntityHealBeforeEvent 类​

2.6.0+
该特性在server模块脚本版本2.6.0+下可用,但该版本对于当前的中国版版本过高。

实体回复生命前的事件信息。其筛选项见EntityHealEventOptions。

class EntityHealBeforeEvent {
private constructor();
cancel: boolean;
readonly healedEntity: Entity;
healing: number;
readonly healSource: EntityHealSource;
}

属性​

  • cancel: boolean,若设为true,将取消该回复生命事件。
  • 只读 healedEntity: Entity,即将被回复生命的实体。
  • healing: number,回复的生命值数量。
  • 只读 healSource: EntityHealSource,回复生命的来源信息。

实体受伤事件​

EntityHurtBeforeEventSignal 类​

2.6.0+
该特性在server模块脚本版本2.6.0+下可用,但该版本对于当前的中国版版本过高。

当实体受伤前触发该事件信号。

class EntityHurtBeforeEventSignal {
private constructor();
subscribe(
callback: (arg0: EntityHurtBeforeEvent) => void,
options?: EntityHurtBeforeEventOptions,
): (arg0: EntityHurtBeforeEvent) => void;
unsubscribe(callback: (arg0: EntityHurtBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: EntityHurtBeforeEvent) => void, options?: EntityHurtBeforeEventOptions) => (arg0: EntityHurtBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: EntityHurtBeforeEvent) => void) => void,取消订阅该事件。

EntityHurtBeforeEvent 类​

2.6.0+
该特性在server模块脚本版本2.6.0+下可用,但该版本对于当前的中国版版本过高。

实体受伤前的事件信息。其筛选项见EntityHurtBeforeEventOptions。

class EntityHurtBeforeEvent {
private constructor();
cancel: boolean;
damage: number;
readonly damageSource: EntityDamageSource;
readonly hurtEntity: Entity;
}

属性​

  • cancel: boolean,若设为true,将取消该伤害事件。
  • damage: number,即将造成的伤害数量。
  • 只读 damageSource: EntityDamageSource,可能造成该伤害的实体的来源信息。
  • 只读 hurtEntity: Entity,即将受到伤害的实体。

实体拾取物品事件​

EntityItemPickupBeforeEventSignal 类​

2.6.0+
该特性在server模块脚本版本2.6.0+下可用,但该版本对于当前的中国版版本过高。

当实体拾取物品前触发该事件信号。

class EntityItemPickupBeforeEventSignal {
private constructor();
subscribe(
callback: (arg0: EntityItemPickupBeforeEvent) => void,
options?: EntityItemPickupEventOptions,
): (arg0: EntityItemPickupBeforeEvent) => void;
unsubscribe(callback: (arg0: EntityItemPickupBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: EntityItemPickupBeforeEvent) => void, options?: EntityItemPickupEventOptions) => (arg0: EntityItemPickupBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: EntityItemPickupBeforeEvent) => void) => void,取消订阅该事件。

EntityItemPickupBeforeEvent 类​

2.6.0+
该特性在server模块脚本版本2.6.0+下可用,但该版本对于当前的中国版版本过高。

实体拾取物品前的事件信息。其筛选项见EntityItemPickupEventOptions。

class EntityItemPickupBeforeEvent {
private constructor();
cancel: boolean;
readonly entity: Entity;
readonly item: Entity;
}

属性​

  • cancel: boolean,若设为true,该物品将不会被拾取。
  • 只读 entity: Entity,即将拾取该物品的实体。
  • 只读 item: Entity,即将被拾取的物品实体。

实体被驯服事件​

EntityTamedBeforeEventSignal 类​

2.10.0+
该特性在server模块脚本版本2.10.0+下可用,但该版本对于当前的中国版版本过高。

当实体被驯服前触发该事件信号。

class EntityTamedBeforeEventSignal {
private constructor();
subscribe(
callback: (arg0: EntityTamedBeforeEvent) => void,
options?: EntityTamedEventOptions,
): (arg0: EntityTamedBeforeEvent) => void;
unsubscribe(callback: (arg0: EntityTamedBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: EntityTamedBeforeEvent) => void, options?: EntityTamedEventOptions) => (arg0: EntityTamedBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: EntityTamedBeforeEvent) => void) => void,取消订阅该事件。

EntityTamedBeforeEvent 类​

2.10.0+
该特性在server模块脚本版本2.10.0+下可用,但该版本对于当前的中国版版本过高。

实体被驯服前的事件信息。其筛选项见EntityTamedEventOptions。

class EntityTamedBeforeEvent {
private constructor();
cancel: boolean;
readonly entity: Entity;
readonly tamingEntity: Entity;
}

属性​

  • cancel: boolean,设为true时将取消该事件。
  • 只读 entity: Entity,即将被驯服的实体。
  • 只读 tamingEntity: Entity,正在尝试驯服该实体的实体。

世界时钟重启事件​

WorldClockOnRestartBeforeEventSignal 类​

2.11.0+
该特性在server模块脚本版本2.11.0+下可用,但该版本对于当前的中国版版本过高。

当世界时钟重启前触发该事件信号。

class WorldClockOnRestartBeforeEventSignal {
private constructor();
subscribe(
callback: (arg0: WorldClockOnRestartBeforeEvent) => void,
options?: WorldClockEventOptions,
): (arg0: WorldClockOnRestartBeforeEvent) => void;
unsubscribe(callback: (arg0: WorldClockOnRestartBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: WorldClockOnRestartBeforeEvent) => void, options?: WorldClockEventOptions) => (arg0: WorldClockOnRestartBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: WorldClockOnRestartBeforeEvent) => void) => void,取消订阅该事件。

WorldClockOnRestartBeforeEvent 类​

2.11.0+
该特性在server模块脚本版本2.11.0+下可用,但该版本对于当前的中国版版本过高。

世界时钟重启前的事件信息。其筛选项见WorldClockEventOptions。

class WorldClockOnRestartBeforeEvent {
private constructor();
cancel: boolean;
readonly clock: WorldClock;
newTime: number;
}

属性​

  • cancel: boolean,若设为true,将取消该世界时钟重启事件。这会使世界时钟保持在最大时间值,并阻止其继续推进。
  • 只读 clock: WorldClock,即将重启的世界时钟。
  • newTime: number,世界时钟重启后将被设置为的时间。若未设置,世界时钟将被设置为0。最小值:0。

发送聊天消息事件​

ChatSendBeforeEventSignal 类​

实验性玩法
该特性必须开启「测试版API」实验性玩法后方可使用。请注意,实验性玩法存在功能不稳定、功能更改甚至未来被移除的风险。

当发送聊天消息前触发该事件信号。

class ChatSendBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: ChatSendBeforeEvent) => void): (arg0: ChatSendBeforeEvent) => void;
unsubscribe(callback: (arg0: ChatSendBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: ChatSendBeforeEvent) => void) => (arg0: ChatSendBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: ChatSendBeforeEvent) => void) => void,取消订阅该事件。

ChatSendBeforeEvent 类​

实验性玩法
该特性必须开启「测试版API」实验性玩法后方可使用。请注意,实验性玩法存在功能不稳定、功能更改甚至未来被移除的风险。

发送聊天消息前的事件信息。

class ChatSendBeforeEvent {
private constructor();
cancel: boolean;
readonly message: string;
readonly sender: Player;
targets?: Player[];
}

属性​

  • cancel: boolean,若在聊天发送前事件的处理函数中设为true,该消息将不会被广播。
  • 只读 message: string,即将被广播的消息。
  • 只读 sender: Player,发送该聊天消息的玩家。
  • 可选 targets: Player[],即将接收该消息的玩家列表。若已定义,该消息将直接发送给一个或多个玩家(即不广播)。可修改该列表以更改消息的接收者。

玩家物品攻击实体事件​

PlayerItemAttackEntityBeforeEventSignal 类​

实验性玩法
该特性必须开启「测试版API」实验性玩法后方可使用。请注意,实验性玩法存在功能不稳定、功能更改甚至未来被移除的风险。

当玩家物品攻击实体前触发该事件信号。

class PlayerItemAttackEntityBeforeEventSignal {
private constructor();
subscribe(callback: (arg0: PlayerItemAttackEntityBeforeEvent) => void): (arg0: PlayerItemAttackEntityBeforeEvent) => void;
unsubscribe(callback: (arg0: PlayerItemAttackEntityBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: PlayerItemAttackEntityBeforeEvent) => void) => (arg0: PlayerItemAttackEntityBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: PlayerItemAttackEntityBeforeEvent) => void) => void,取消订阅该事件。

PlayerItemAttackEntityBeforeEvent 类​

实验性玩法
该特性必须开启「测试版API」实验性玩法后方可使用。请注意,实验性玩法存在功能不稳定、功能更改甚至未来被移除的风险。

玩家物品攻击实体前的事件信息。

class PlayerItemAttackEntityBeforeEvent {
private constructor();
readonly aimDirection?: Vector3;
cancel: boolean;
readonly itemStack?: ItemStack;
readonly player: Player;
readonly target: Entity;
}

属性​

  • 只读 可选 aimDirection: Vector3,攻击所使用的归一化世界空间方向。对于标准的客户端发起的攻击,该方向由客户端提供的命中位置与玩家服务端的眼部位置计算得出。其它攻击路径可提供服务端推导出的方向。当攻击路径不提供瞄准方向时,该属性为undefined。
  • cancel: boolean,若设为true,该攻击不会造成伤害或其它权威的攻击效果。
  • 只读 可选 itemStack: ItemStack,发起攻击的玩家所持物品的快照。当玩家未持有物品时,该属性为undefined。
  • 只读 player: Player,发起该攻击的玩家。
  • 只读 target: Entity,被该攻击锁定的实体。

玩家放置方块事件​

PlayerPlaceBlockBeforeEventSignal 类​

实验性玩法
该特性必须开启「测试版API」实验性玩法后方可使用。请注意,实验性玩法存在功能不稳定、功能更改甚至未来被移除的风险。

当玩家放置方块前触发该事件信号。

class PlayerPlaceBlockBeforeEventSignal {
private constructor();
subscribe(
callback: (arg0: PlayerPlaceBlockBeforeEvent) => void,
options?: BlockEventOptions,
): (arg0: PlayerPlaceBlockBeforeEvent) => void;
unsubscribe(callback: (arg0: PlayerPlaceBlockBeforeEvent) => void): void;
}

方法​

  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    subscribe: (callback: (arg0: PlayerPlaceBlockBeforeEvent) => void, options?: BlockEventOptions) => (arg0: PlayerPlaceBlockBeforeEvent) => void,订阅该事件,返回的函数可用于取消订阅。
  • 受限执行
    该属性/方法不能在受限执行模式下使用。
    早期执行
    该方法可以在早期执行阶段调用。
    unsubscribe: (callback: (arg0: PlayerPlaceBlockBeforeEvent) => void) => void,取消订阅该事件。

PlayerPlaceBlockBeforeEvent 类​

实验性玩法
该特性必须开启「测试版API」实验性玩法后方可使用。请注意,实验性玩法存在功能不稳定、功能更改甚至未来被移除的风险。

玩家放置方块前的事件信息。其筛选项见BlockEventOptions。

class PlayerPlaceBlockBeforeEvent {
private constructor();
cancel: boolean;
readonly face: Direction;
readonly faceLocation: Vector3;
readonly permutationToPlace: BlockPermutation;
readonly player: Player;
}

属性​

  • cancel: boolean,若设为true,将取消该方块放置事件。
  • 只读 face: Direction,新方块所放置到的方块的被放置面。
  • 只读 faceLocation: Vector3,相对于新方块所放置到的方块的底部西北角的坐标。
  • 只读 permutationToPlace: BlockPermutation,若事件未被取消,即将放置的方块置换。
  • 只读 player: Player,触发该事件的放置方块的玩家。

参考文档​

本文主要参考文档如下,读者可以在这些文档获得更多信息。