@nativewrappers/server 0.0.98 → 0.0.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/Command.d.ts +22 -0
- package/common/Command.js +33 -21
- package/common/decors/Events.js +12 -1
- package/package.json +1 -1
package/common/Command.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ interface ParameterTypes {
|
|
|
8
8
|
interface Parameter {
|
|
9
9
|
name: string;
|
|
10
10
|
type: keyof ParameterTypes;
|
|
11
|
+
defaultValue?: any;
|
|
11
12
|
help?: string;
|
|
12
13
|
optional?: boolean;
|
|
13
14
|
}
|
|
@@ -18,6 +19,27 @@ type MappedParameters<T extends Parameter[]> = {
|
|
|
18
19
|
raw: string;
|
|
19
20
|
};
|
|
20
21
|
type CommandHandler<T extends Parameter[]> = (args: MappedParameters<T>) => void | Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* ```typescript
|
|
24
|
+
* new Command(["do", "deleteobjects"], async ({source, radius}) => {
|
|
25
|
+
* const entities = Prop.AllProps();
|
|
26
|
+
* const ply = new Player(source);
|
|
27
|
+
* const pos = ply.Ped.Position
|
|
28
|
+
* for (const ent of entities) {
|
|
29
|
+
* // if they're outside of the range of our specified radius just continue to next
|
|
30
|
+
* if (ent.Position.distance(pos) > radius) continue;
|
|
31
|
+
* ent.delete();
|
|
32
|
+
* }
|
|
33
|
+
* }, "Deletes all objects in the specified range", [
|
|
34
|
+
* {
|
|
35
|
+
* name: "radius",
|
|
36
|
+
* type: "number",
|
|
37
|
+
* help: "The radius to delete the entities in",
|
|
38
|
+
* defaultValue: 5.0
|
|
39
|
+
* }
|
|
40
|
+
* ] as const, "group.moderator")
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
21
43
|
export declare class Command<T extends Parameter[] = Parameter[]> {
|
|
22
44
|
#private;
|
|
23
45
|
readonly name: string | string[];
|
package/common/Command.js
CHANGED
|
@@ -49,7 +49,9 @@ class Command {
|
|
|
49
49
|
if (params) {
|
|
50
50
|
for (const parameter of params) {
|
|
51
51
|
if (parameter.type) {
|
|
52
|
-
|
|
52
|
+
const defaultString = parameter.defaultValue !== void 0 ? `[default: ${parameter.defaultValue}]` : "";
|
|
53
|
+
const typeString = `[type: ${parameter.type}] ${defaultString}`;
|
|
54
|
+
parameter.help = parameter.help ? `${parameter.help} ${typeString}` : `${typeString}`;
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
}
|
|
@@ -87,26 +89,36 @@ class Command {
|
|
|
87
89
|
const result = this.params.every((param, index) => {
|
|
88
90
|
const arg = args[index];
|
|
89
91
|
let value = arg;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
92
|
+
const hasDefaultValue = param.defaultValue !== void 0;
|
|
93
|
+
const hasArg = typeof arg === "string";
|
|
94
|
+
if (!hasArg && hasDefaultValue) {
|
|
95
|
+
value = param.defaultValue;
|
|
96
|
+
} else {
|
|
97
|
+
switch (param.type) {
|
|
98
|
+
case "number":
|
|
99
|
+
if (hasDefaultValue && !hasArg) {
|
|
100
|
+
value = param.defaultValue;
|
|
101
|
+
} else {
|
|
102
|
+
value = +arg;
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
case "string":
|
|
106
|
+
value = !Number(arg) ? arg : false;
|
|
107
|
+
break;
|
|
108
|
+
case "playerId":
|
|
109
|
+
$SERVER: {
|
|
110
|
+
value = arg === "me" ? source2 : +arg;
|
|
111
|
+
if (!value || !DoesPlayerExist(value.toString())) value = void 0;
|
|
112
|
+
}
|
|
113
|
+
$CLIENT: {
|
|
114
|
+
value = arg === "me" ? GetPlayerServerId(PlayerId()) : +arg;
|
|
115
|
+
if (!value || GetPlayerFromServerId(value) === -1) value = void 0;
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
case "longString":
|
|
119
|
+
value = raw.substring(raw.indexOf(arg));
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
110
122
|
}
|
|
111
123
|
if (value === void 0 && (!param.optional || param.optional && arg)) {
|
|
112
124
|
return Citizen.trace(
|
package/common/decors/Events.js
CHANGED
|
@@ -16,7 +16,18 @@ function Exports(exportName) {
|
|
|
16
16
|
}
|
|
17
17
|
context.addInitializer(function() {
|
|
18
18
|
exports(exportName, (...args) => {
|
|
19
|
-
|
|
19
|
+
try {
|
|
20
|
+
return originalMethod.call(this, ...args);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
REMOVE_EVENT_LOG: {
|
|
23
|
+
if (!GlobalData.EnablePrettyPrint) return;
|
|
24
|
+
console.error("------- EXPORT ERROR --------");
|
|
25
|
+
console.error(`Call to ${exportName} errored`);
|
|
26
|
+
console.error(`Data: ${JSON.stringify(args)}`);
|
|
27
|
+
console.error(`Error: ${err}`);
|
|
28
|
+
console.error("------- END EXPORT ERROR --------");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
20
31
|
});
|
|
21
32
|
});
|
|
22
33
|
}, "actualDecorator");
|