diff --git a/package.json b/package.json index d51901b..aac32f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "omp-node-lib", - "version": "0.2.1", + "version": "0.2.2", "description": "Better with omp-node-ts", "main": "dist/bundle.js", "types": "dist/bundle.d.ts", diff --git a/src/controllers/command/index.ts b/src/controllers/command/index.ts index 1c165ca..612c597 100644 --- a/src/controllers/command/index.ts +++ b/src/controllers/command/index.ts @@ -24,14 +24,16 @@ export class CmdBus { CmdBus.eventList.splice(idx, 1); } - static emit( + static async emit( player: T, userEventName: TEventName, userEventArgs: Array - ): boolean { + ): Promise { const idx: number = CmdBus.findEventIdxByName(userEventName); if (idx > -1) { - const result = CmdBus.eventList[idx].fn.apply(player, userEventArgs); + let result = CmdBus.eventList[idx].fn.apply(player, userEventArgs); + if (result instanceof Promise) result = await result; + if (result === undefined || result === null) return false; if (typeof result === "number") return Boolean(result); return result; } diff --git a/src/controllers/player/playerEvent.ts b/src/controllers/player/playerEvent.ts index 326fd89..35a12fa 100644 --- a/src/controllers/player/playerEvent.ts +++ b/src/controllers/player/playerEvent.ts @@ -163,11 +163,10 @@ export abstract class BasePlayerEvent< Use eventBus to observe and subscribe to level 1 instructions, support string and array pass, array used for alias. */ - const exist: boolean = CmdBus.emit( - p, - regCmdtext[0], - regCmdtext.splice(1) - ); + let exist = false; + (async () => { + exist = await CmdBus.emit(p, regCmdtext[0], regCmdtext.splice(1)); + })(); if (exist) return 1; // The command %s you entered does not exist return this.onCommandError(p, regCmdtext.join(" "), ICmdErrInfo.notExist); diff --git a/src/types/index.ts b/src/types/index.ts index dfec263..d6d8c6d 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -13,7 +13,7 @@ export type TEventName = string | string[]; export type TEventFunc = ( this: T, ...args: string[] -) => boolean | number; +) => boolean | number | void | Promise; export type TLocales = Record;