mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 15:06:02 +01:00
fix(addCommand): catch errors in command handler
+ additional minor changes. Use DoesPlayerExist native. Mark addCommand cb as async.
This commit is contained in:
@@ -51,7 +51,7 @@ function parseArguments(
|
||||
|
||||
case 'playerId':
|
||||
value = arg === 'me' ? source : +arg;
|
||||
if (!value || !GetPlayerGuid(value.toString())) value = false;
|
||||
if (!value || !DoesPlayerExist(value.toString())) value = false;
|
||||
|
||||
break;
|
||||
|
||||
@@ -79,7 +79,7 @@ function parseArguments(
|
||||
|
||||
export function addCommand<T extends OxCommandArguments>(
|
||||
commandName: string | string[],
|
||||
cb: (source: number, args: T, raw: string) => any,
|
||||
cb: (source: number, args: T, raw: string) => Promise<any>,
|
||||
properties?: OxCommandProperties
|
||||
) {
|
||||
const restricted = properties?.restricted;
|
||||
@@ -100,7 +100,9 @@ export function addCommand<T extends OxCommandArguments>(
|
||||
|
||||
if (!parsed) return;
|
||||
|
||||
cb(source, parsed, raw);
|
||||
cb(source, parsed, raw).catch((e) =>
|
||||
Citizen.trace(`^1command '${raw.split(' ')[0] || raw}' failed to execute!^0\n${e.message}`)
|
||||
);
|
||||
};
|
||||
|
||||
commands.forEach((commandName, index) => {
|
||||
|
||||
Reference in New Issue
Block a user