@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.
@@ -1,7 +1,11 @@
1
1
  type Restricted = boolean | string | string[];
2
- export interface ParameterTypes {
2
+ export interface ParameterTypeOverrides {
3
+ }
4
+ export interface ParameterTypes extends ParameterTypeOverrides {
3
5
  number: number;
4
- playerId: number;
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: number;
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 ${restricted} ${ace} allow`);
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
- const target = isMe ? GetPlayerServerId(PlayerId()) : parseInt(arg, 10);
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 $${target} didn't exist`);
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
- const target = arg === "me" ? source2 : parseInt(arg, 10);
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 ${source2} didn't exist`);
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 mapped = {
141
+ const defaultContextObject = {
139
142
  source: source2,
140
143
  raw
141
144
  };
142
- if (!this.params) return mapped;
143
- const defaultContextObject = {
144
- source: source2,
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 parser = commandTypeParserRegistry.get(param.type);
155
- if (!parser) {
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 = parser(arg, defaultContextObject);
167
+ value = parser2(arg, defaultContextObject);
163
168
  } catch (e) {
164
169
  globalThis.printError("command parsing", e);
165
170
  return false;
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.0.161",
11
+ "version": "0.0.163",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"