Skip to content

Commit

Permalink
refactor: call command error event
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Sep 25, 2022
1 parent 4f8fcd3 commit 7472930
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "omp-node-lib",
"version": "0.2.0",
"version": "0.2.1",
"description": "Better with omp-node-ts",
"main": "dist/bundle.js",
"types": "dist/bundle.d.ts",
Expand Down
14 changes: 9 additions & 5 deletions src/controllers/player/playerEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ import { playerBus, playerHooks } from "./playerBus";
// Each instance can be called to callbacks, so you can split the logic.

const ICmdErrInfo: Record<string, ICmdErr> = {
format: { code: 0, msg: "Please enter the correct command" },
notExist: { code: 1, msg: "The command %s you entered does not exist" },
format: { code: 0, msg: "incorrect command" },
notExist: { code: 1, msg: "does not exist" },
};

abstract class AbstractPlayerEvent<P extends BasePlayer> {
Expand All @@ -48,7 +48,11 @@ abstract class AbstractPlayerEvent<P extends BasePlayer> {
protected abstract onConnect(player: P): number;
protected abstract onDisconnect(player: P, reason: number): number;
protected abstract onText(player: P, text: string): number;
protected abstract onCommandError(player: P, err: ICmdErr): number;
protected abstract onCommandError(
player: P,
command: string,
err: ICmdErr
): number;
protected abstract onEnterExitModShop(
player: P,
enterexit: number,
Expand Down Expand Up @@ -152,7 +156,7 @@ export abstract class BasePlayerEvent<
const cmdtext = I18n.decodeFromBuf(buf, p.charset);
const regCmdtext = cmdtext.match(/[^/\s]+/gi);
if (regCmdtext === null || regCmdtext.length === 0) {
this.onCommandError(p, ICmdErrInfo.format);
this.onCommandError(p, cmdtext, ICmdErrInfo.format);
return 0;
}
/*
Expand All @@ -166,7 +170,7 @@ export abstract class BasePlayerEvent<
);
if (exist) return 1;
// The command %s you entered does not exist
return this.onCommandError(p, ICmdErrInfo.notExist);
return this.onCommandError(p, regCmdtext.join(" "), ICmdErrInfo.notExist);
});

OnEnterExitModShop(
Expand Down

0 comments on commit 7472930

Please sign in to comment.