@nativewrappers/redm 0.0.161 → 0.0.163
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 +7 -3
- package/common/Command.js +20 -15
- package/package.json +1 -1
package/common/Command.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
type Restricted = boolean | string | string[];
|
|
2
|
-
export interface
|
|
2
|
+
export interface ParameterTypeOverrides {
|
|
3
|
+
}
|
|
4
|
+
export interface ParameterTypes extends ParameterTypeOverrides {
|
|
3
5
|
number: number;
|
|
4
|
-
playerId:
|
|
6
|
+
playerId: ParameterTypeOverrides extends {
|
|
7
|
+
playerId: infer T;
|
|
8
|
+
} ? T : number;
|
|
5
9
|
string: string;
|
|
6
10
|
longString: string;
|
|
7
11
|
}
|
|
@@ -15,7 +19,7 @@ interface Parameter {
|
|
|
15
19
|
type MappedParameters<T extends Parameter[]> = {
|
|
16
20
|
[K in T[number] as K["name"]]: ParameterTypes[K["type"]];
|
|
17
21
|
} & {
|
|
18
|
-
source:
|
|
22
|
+
source: ParameterTypes["playerId"];
|
|
19
23
|
raw: string;
|
|
20
24
|
};
|
|
21
25
|
type CommandHandler<T extends Parameter[]> = (args: MappedParameters<T>) => void | Promise<void>;
|
package/common/Command.js
CHANGED
|
@@ -27,7 +27,7 @@ function registerCommand(name, commandHandler, restricted = true) {
|
|
|
27
27
|
}
|
|
28
28
|
if (Array.isArray(restricted)) {
|
|
29
29
|
for (const principal of restricted) {
|
|
30
|
-
if (!IsPrincipalAceAllowed(principal, ace)) ExecuteCommand(`add_ace ${
|
|
30
|
+
if (!IsPrincipalAceAllowed(principal, ace)) ExecuteCommand(`add_ace ${principal} ${ace} allow`);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -52,15 +52,15 @@ registerParameterType("string", (arg) => {
|
|
|
52
52
|
$CLIENT: if (GlobalData.IS_CLIENT) {
|
|
53
53
|
registerParameterType("playerId", (arg) => {
|
|
54
54
|
const isMe = arg === "me";
|
|
55
|
-
|
|
55
|
+
if (isMe) {
|
|
56
|
+
return GetPlayerServerId(PlayerId());
|
|
57
|
+
}
|
|
58
|
+
const target = parseInt(arg, 10);
|
|
56
59
|
if (Number.isNaN(target)) {
|
|
57
60
|
throw new TypeError(`could not parse argument into a valid playerId`);
|
|
58
61
|
}
|
|
59
|
-
if (isMe) {
|
|
60
|
-
return target;
|
|
61
|
-
}
|
|
62
62
|
if (GetPlayerFromServerId(target) === -1) {
|
|
63
|
-
throw new Error(`player with server id
|
|
63
|
+
throw new Error(`player with server id ${target} didn't exist`);
|
|
64
64
|
}
|
|
65
65
|
return target;
|
|
66
66
|
});
|
|
@@ -68,12 +68,15 @@ registerParameterType("string", (arg) => {
|
|
|
68
68
|
}
|
|
69
69
|
$SERVER: {
|
|
70
70
|
registerParameterType("playerId", (arg, { source: source2 }) => {
|
|
71
|
-
|
|
71
|
+
if (arg === "me") {
|
|
72
|
+
return source2;
|
|
73
|
+
}
|
|
74
|
+
const target = parseInt(arg, 10);
|
|
72
75
|
if (Number.isNaN(target)) {
|
|
73
76
|
throw new TypeError(`could not parse argument into a valid playerId`);
|
|
74
77
|
}
|
|
75
78
|
if (!DoesPlayerExist(target)) {
|
|
76
|
-
throw new Error(`player at ${
|
|
79
|
+
throw new Error(`player at ${target} didn't exist`);
|
|
77
80
|
}
|
|
78
81
|
return target;
|
|
79
82
|
});
|
|
@@ -135,15 +138,17 @@ class Command {
|
|
|
135
138
|
* @returns A mapped object containing parsed parameters.
|
|
136
139
|
*/
|
|
137
140
|
mapArguments(source2, args, raw) {
|
|
138
|
-
const
|
|
141
|
+
const defaultContextObject = {
|
|
139
142
|
source: source2,
|
|
140
143
|
raw
|
|
141
144
|
};
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
+
const parser = commandTypeParserRegistry.get("playerId");
|
|
146
|
+
const parsedSource = parser ? parser("me", defaultContextObject) : source2;
|
|
147
|
+
const mapped = {
|
|
148
|
+
source: parsedSource,
|
|
145
149
|
raw
|
|
146
150
|
};
|
|
151
|
+
if (!this.params) return mapped;
|
|
147
152
|
const result = this.params.every((param, index) => {
|
|
148
153
|
const arg = args[index];
|
|
149
154
|
let value = arg;
|
|
@@ -151,15 +156,15 @@ class Command {
|
|
|
151
156
|
if (!hasArg) {
|
|
152
157
|
value = param.defaultValue;
|
|
153
158
|
} else {
|
|
154
|
-
const
|
|
155
|
-
if (!
|
|
159
|
+
const parser2 = commandTypeParserRegistry.get(param.type);
|
|
160
|
+
if (!parser2) {
|
|
156
161
|
console.error(
|
|
157
162
|
`${param.type} didn't have a valid parser, did you forget to register it with 'registerParameterType'?`
|
|
158
163
|
);
|
|
159
164
|
return false;
|
|
160
165
|
}
|
|
161
166
|
try {
|
|
162
|
-
value =
|
|
167
|
+
value = parser2(arg, defaultContextObject);
|
|
163
168
|
} catch (e) {
|
|
164
169
|
globalThis.printError("command parsing", e);
|
|
165
170
|
return false;
|