@armoury/fivem-framework-common 1.0.55 → 1.0.61
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.
|
@@ -3,32 +3,51 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Command = Command;
|
|
4
4
|
exports.Commands = Commands;
|
|
5
5
|
const decorator_utils_1 = require("./decorator.utils");
|
|
6
|
-
// TODO: adminLevelRequired is not supposed to be here. Move it to @armoury/fivem-gamemode
|
|
7
6
|
function Command(data) {
|
|
8
7
|
return function (target, propertyKey) {
|
|
9
8
|
Reflect.defineMetadata(`arm_command_${propertyKey}`, data, target);
|
|
10
9
|
};
|
|
11
10
|
}
|
|
12
11
|
function Commands(target, _prototype, providers) {
|
|
13
|
-
decorator_utils_1.DecoratorUtils.map(target, _prototype, providers ?? [])
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const mappings = decorator_utils_1.DecoratorUtils.map(target, _prototype, providers ?? []);
|
|
13
|
+
const isServer = Cfx.Client.IsDuplicityVersion();
|
|
14
|
+
for (const mapping of mappings) {
|
|
15
|
+
if (!mapping.key.startsWith('arm_command_')) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const rawCommandName = mapping.key.substring(12);
|
|
17
19
|
const commandName = rawCommandName.toLowerCase() + (mapping.value?.suffix || '');
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
const instance = mapping.target;
|
|
21
|
+
const handler = instance[rawCommandName];
|
|
22
|
+
if (!isServer) {
|
|
23
|
+
Cfx.Client.RegisterCommand(commandName, (_source, args) => {
|
|
24
|
+
handler.apply(instance, args);
|
|
21
25
|
}, false);
|
|
26
|
+
continue;
|
|
22
27
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
28
|
+
const configuredPermissions = mapping.value?.permissions;
|
|
29
|
+
let permissions = null;
|
|
30
|
+
if (configuredPermissions != null) {
|
|
31
|
+
if (Array.isArray(configuredPermissions)) {
|
|
32
|
+
permissions = configuredPermissions.slice();
|
|
33
|
+
}
|
|
34
|
+
else if (typeof configuredPermissions === 'string') {
|
|
35
|
+
permissions = [configuredPermissions];
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.error(`Invalid permissions specified for command ${commandName}.`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
32
41
|
}
|
|
33
|
-
|
|
42
|
+
Cfx.Server.RegisterCommand(commandName, (source, args) => {
|
|
43
|
+
if (permissions) {
|
|
44
|
+
for (let i = 0; i < permissions.length; i++) {
|
|
45
|
+
if (!Cfx.Server.IsPlayerAceAllowed(source, permissions[i])) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
handler.call(instance, source, ...args);
|
|
51
|
+
}, false);
|
|
52
|
+
}
|
|
34
53
|
}
|
|
@@ -1,30 +1,49 @@
|
|
|
1
|
-
import { DecoratorUtils } from
|
|
2
|
-
// TODO: adminLevelRequired is not supposed to be here. Move it to @armoury/fivem-gamemode
|
|
1
|
+
import { DecoratorUtils } from './decorator.utils';
|
|
3
2
|
export function Command(data) {
|
|
4
3
|
return function (target, propertyKey) {
|
|
5
4
|
Reflect.defineMetadata(`arm_command_${propertyKey}`, data, target);
|
|
6
5
|
};
|
|
7
6
|
}
|
|
8
7
|
export function Commands(target, _prototype, providers) {
|
|
9
|
-
DecoratorUtils.map(target, _prototype, providers ?? [])
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const mappings = DecoratorUtils.map(target, _prototype, providers ?? []);
|
|
9
|
+
const isServer = Cfx.Client.IsDuplicityVersion();
|
|
10
|
+
for (const mapping of mappings) {
|
|
11
|
+
if (!mapping.key.startsWith('arm_command_')) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
const rawCommandName = mapping.key.substring(12);
|
|
13
15
|
const commandName = rawCommandName.toLowerCase() + (mapping.value?.suffix || '');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
const instance = mapping.target;
|
|
17
|
+
const handler = instance[rawCommandName];
|
|
18
|
+
if (!isServer) {
|
|
19
|
+
Cfx.Client.RegisterCommand(commandName, (_source, args) => {
|
|
20
|
+
handler.apply(instance, args);
|
|
17
21
|
}, false);
|
|
22
|
+
continue;
|
|
18
23
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
24
|
+
const configuredPermissions = mapping.value?.permissions;
|
|
25
|
+
let permissions = null;
|
|
26
|
+
if (configuredPermissions != null) {
|
|
27
|
+
if (Array.isArray(configuredPermissions)) {
|
|
28
|
+
permissions = configuredPermissions.slice();
|
|
29
|
+
}
|
|
30
|
+
else if (typeof configuredPermissions === 'string') {
|
|
31
|
+
permissions = [configuredPermissions];
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
console.error(`Invalid permissions specified for command ${commandName}.`);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
28
37
|
}
|
|
29
|
-
|
|
38
|
+
Cfx.Server.RegisterCommand(commandName, (source, args) => {
|
|
39
|
+
if (permissions) {
|
|
40
|
+
for (let i = 0; i < permissions.length; i++) {
|
|
41
|
+
if (!Cfx.Server.IsPlayerAceAllowed(source, permissions[i])) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
handler.call(instance, source, ...args);
|
|
47
|
+
}, false);
|
|
48
|
+
}
|
|
30
49
|
}
|