@ascentbv/ts-common - v1.0.123
    Preparing search index...

    Class EventUtilAbstract

    Index

    Constructors

    Methods

    • Unsubscribe a callback from an event.

      Type Parameters

      • T

      Parameters

      Returns void

      const handle = EventUtil.subscribe(world.afterEvents.playerJoin, cb);

      EventUtil.unsubscribe(world.afterEvents.playerJoin, handle);
    • Subscribe to a custom event (internal event system).

      Parameters

      • eventName: string

        The name of the custom event to listen for.

      • callback: (data: any) => void

        The callback to run when the event is emitted.

      • Optionaloptions: { once?: boolean }

        Supports once to auto-unsubscribe after the first trigger.

      Returns number

      EventUtil.subscribeCustom("onNewDay", (data) => {
      console.log(`Day ${data.currentDay} has started!`);
      });

      Use EventUtil.subscribe with an EventSignal instead

    • Emit (trigger) a custom event.

      You can pass either:

      • A plain object with event data.
      • A class instance (this), and all its properties and methods will be collected and passed as the event data.

      Parameters

      • eventName: string

        The custom event name.

      • OptionaldataOrEmitter: any

        An object with event data, or an instance whose properties will be collected.

      Returns void

      // Emit with plain data
      EventUtil.emitCustom("onNewDay", { day: 5 });

      // Emit with all properties/methods of a class instance
      EventUtil.emitCustom("onNewDay", this);

      Use EventUtil.emit with an EventSignal instead