@nativewrappers/common 0.0.87 → 0.0.89
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/Command.d.ts +25 -0
- package/Command.js +28 -2
- package/package.json +1 -1
package/Command.d.ts
CHANGED
|
@@ -23,8 +23,33 @@ export declare class Command<T extends Parameter[] = Parameter[]> {
|
|
|
23
23
|
readonly name: string | string[];
|
|
24
24
|
readonly help: string;
|
|
25
25
|
readonly params?: T | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Registers a new executable command with optional parameter validation and permission restrictions.
|
|
28
|
+
* @param name The unique identifier(s) for the command, either as a single string or an array of strings.
|
|
29
|
+
* @param help A description of the command, displayed as a chat suggestion.
|
|
30
|
+
* @param handler The function to execute when the command is executed.
|
|
31
|
+
* @param params An optional array of parameter definitions specifying the command's expected arguments,
|
|
32
|
+
* including their names, types, and descriptive help text for chat suggestions.
|
|
33
|
+
* @param restricted Determines the command's access permissions:
|
|
34
|
+
* - Defaults to `true`, restricting usage to users with the "command.commandName" ACE permission.
|
|
35
|
+
* - A string such as `"group.admin"` grants the command permission to the specified principal.
|
|
36
|
+
* - An array of strings grants permission to multiple principals.
|
|
37
|
+
*/
|
|
26
38
|
constructor(name: string | string[], help: string, handler: CommandHandler<T>, params?: T | undefined, restricted?: Restricted);
|
|
39
|
+
/**
|
|
40
|
+
* Maps the arguments received from a command call to the defined parameters while validating the argument types.
|
|
41
|
+
* @param source The client that executed the command, or -1 if executed by the server.
|
|
42
|
+
* @param args The arguments passed to the command.
|
|
43
|
+
* @param raw The raw input string passed to the command.
|
|
44
|
+
* @returns A mapped object containing parsed parameters.
|
|
45
|
+
*/
|
|
27
46
|
private mapArguments;
|
|
47
|
+
/**
|
|
48
|
+
* Executes the command with the given arguments and source, validating and mapping the arguments before calling the handler.
|
|
49
|
+
* @param source The client that executed the command.
|
|
50
|
+
* @param args The arguments passed to the command.
|
|
51
|
+
* @param raw The raw input string passed to the command.
|
|
52
|
+
*/
|
|
28
53
|
call(source: number, args: string[], raw?: string): Promise<void>;
|
|
29
54
|
}
|
|
30
55
|
export {};
|
package/Command.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { GlobalData } from "./GlobalData";
|
|
3
4
|
const commands = [];
|
|
4
5
|
$SERVER: {
|
|
5
6
|
on("playerJoining", () => emitNet("chat:addSuggestions", source, commands));
|
|
6
7
|
}
|
|
7
|
-
function registerCommand(name, commandHandler, restricted) {
|
|
8
|
+
function registerCommand(name, commandHandler, restricted = true) {
|
|
8
9
|
if (Array.isArray(name)) {
|
|
9
10
|
for (const command of name) {
|
|
10
11
|
registerCommand(command, commandHandler, restricted);
|
|
11
12
|
}
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
|
-
RegisterCommand(name, commandHandler, !!restricted);
|
|
15
|
+
RegisterCommand(name, commandHandler, GlobalData.IS_CLIENT ? false : !!restricted);
|
|
15
16
|
$SERVER: {
|
|
16
17
|
const ace = `command.${name}`;
|
|
17
18
|
if (typeof restricted === "string") {
|
|
@@ -27,6 +28,18 @@ function registerCommand(name, commandHandler, restricted) {
|
|
|
27
28
|
}
|
|
28
29
|
__name(registerCommand, "registerCommand");
|
|
29
30
|
class Command {
|
|
31
|
+
/**
|
|
32
|
+
* Registers a new executable command with optional parameter validation and permission restrictions.
|
|
33
|
+
* @param name The unique identifier(s) for the command, either as a single string or an array of strings.
|
|
34
|
+
* @param help A description of the command, displayed as a chat suggestion.
|
|
35
|
+
* @param handler The function to execute when the command is executed.
|
|
36
|
+
* @param params An optional array of parameter definitions specifying the command's expected arguments,
|
|
37
|
+
* including their names, types, and descriptive help text for chat suggestions.
|
|
38
|
+
* @param restricted Determines the command's access permissions:
|
|
39
|
+
* - Defaults to `true`, restricting usage to users with the "command.commandName" ACE permission.
|
|
40
|
+
* - A string such as `"group.admin"` grants the command permission to the specified principal.
|
|
41
|
+
* - An array of strings grants permission to multiple principals.
|
|
42
|
+
*/
|
|
30
43
|
constructor(name, help, handler, params, restricted = true) {
|
|
31
44
|
this.name = name;
|
|
32
45
|
this.help = help;
|
|
@@ -55,6 +68,13 @@ class Command {
|
|
|
55
68
|
__name(this, "Command");
|
|
56
69
|
}
|
|
57
70
|
#handler;
|
|
71
|
+
/**
|
|
72
|
+
* Maps the arguments received from a command call to the defined parameters while validating the argument types.
|
|
73
|
+
* @param source The client that executed the command, or -1 if executed by the server.
|
|
74
|
+
* @param args The arguments passed to the command.
|
|
75
|
+
* @param raw The raw input string passed to the command.
|
|
76
|
+
* @returns A mapped object containing parsed parameters.
|
|
77
|
+
*/
|
|
58
78
|
mapArguments(source2, args, raw) {
|
|
59
79
|
const mapped = {
|
|
60
80
|
source: source2,
|
|
@@ -95,6 +115,12 @@ class Command {
|
|
|
95
115
|
});
|
|
96
116
|
return result ? mapped : null;
|
|
97
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Executes the command with the given arguments and source, validating and mapping the arguments before calling the handler.
|
|
120
|
+
* @param source The client that executed the command.
|
|
121
|
+
* @param args The arguments passed to the command.
|
|
122
|
+
* @param raw The raw input string passed to the command.
|
|
123
|
+
*/
|
|
98
124
|
async call(source2, args, raw = args.join(" ")) {
|
|
99
125
|
const parsed = this.mapArguments(source2, args, raw);
|
|
100
126
|
if (!parsed) return;
|