@armoury/fivem-framework-common 1.0.54 → 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.
@@ -16,23 +16,21 @@ function Config(key, index = 0) {
16
16
  const token = new injection_js_1.InjectionToken(`Config(${key}, ${index})`);
17
17
  const inject = (0, injection_js_1.Inject)(token);
18
18
  return (target, propertyKey, parameterIndex) => {
19
- var _a;
20
19
  if (propertyKey !== undefined) {
21
20
  throw new Error('Config can only decorate constructor parameters.');
22
21
  }
23
22
  inject(target, propertyKey, parameterIndex);
24
- const bindings = (_a = Reflect.getOwnMetadata(CONFIG_PARAMETERS_METADATA, target)) !== null && _a !== void 0 ? _a : [];
23
+ const bindings = Reflect.getOwnMetadata(CONFIG_PARAMETERS_METADATA, target) ?? [];
25
24
  const binding = { token, key, index };
26
25
  Reflect.defineMetadata(CONFIG_PARAMETERS_METADATA, [...bindings, binding], target);
27
26
  };
28
27
  }
29
28
  function createConfigProviders(targets, readValue) {
30
- var _a;
31
29
  const bindings = new Map();
32
30
  for (const target of targets) {
33
31
  let constructor = target;
34
32
  while (constructor && constructor !== Function.prototype) {
35
- const constructorBindings = (_a = Reflect.getOwnMetadata(CONFIG_PARAMETERS_METADATA, constructor)) !== null && _a !== void 0 ? _a : [];
33
+ const constructorBindings = Reflect.getOwnMetadata(CONFIG_PARAMETERS_METADATA, constructor) ?? [];
36
34
  constructorBindings.forEach((binding) => bindings.set(binding.token, binding));
37
35
  constructor = Object.getPrototypeOf(constructor);
38
36
  }
@@ -63,7 +61,7 @@ function parseConfigValue(value, metadataKey) {
63
61
  try {
64
62
  return JSON.parse(expression);
65
63
  }
66
- catch (_a) {
64
+ catch {
67
65
  // Resource manifest tables use Lua syntax rather than JSON.
68
66
  }
69
67
  }
@@ -93,9 +93,8 @@ function hasProviderForToken(providers, token) {
93
93
  return false;
94
94
  }
95
95
  async function bootstrapWithProviders(entryPoint, parentProviders, options = {}, decorationType = decorator_utils_2.DecorationType.SERVER, readConfigValue, readResourceExports, defaultEagerProviders = []) {
96
- var _a, _b;
97
- const eagerProviders = (_a = options.eager) !== null && _a !== void 0 ? _a : [];
98
- const optionProviders = (_b = options.providers) !== null && _b !== void 0 ? _b : [];
96
+ const eagerProviders = options.eager ?? [];
97
+ const optionProviders = options.providers ?? [];
99
98
  const platformDefaultProviders = flattenProviders(defaultEagerProviders);
100
99
  const activeDefaultEagerProviders = platformDefaultProviders.filter((defaultProvider) => {
101
100
  const token = getProviderToken(defaultProvider);
@@ -26,22 +26,20 @@ function Resource(resourceName) {
26
26
  const token = new injection_js_1.InjectionToken(`Resource(${resourceName})`);
27
27
  const inject = (0, injection_js_1.Inject)(token);
28
28
  return (target, propertyKey, parameterIndex) => {
29
- var _a;
30
29
  if (propertyKey !== undefined) {
31
30
  throw new Error('Resource can only decorate constructor parameters.');
32
31
  }
33
32
  inject(target, propertyKey, parameterIndex);
34
- const bindings = (_a = Reflect.getOwnMetadata(RESOURCE_PARAMETERS_METADATA, target)) !== null && _a !== void 0 ? _a : [];
33
+ const bindings = Reflect.getOwnMetadata(RESOURCE_PARAMETERS_METADATA, target) ?? [];
35
34
  Reflect.defineMetadata(RESOURCE_PARAMETERS_METADATA, [...bindings, { token, resourceName }], target);
36
35
  };
37
36
  }
38
37
  function createResourceProviders(targets, readExports) {
39
- var _a;
40
38
  const bindings = new Map();
41
39
  for (const target of targets) {
42
40
  let constructor = target;
43
41
  while (constructor && constructor !== Function.prototype) {
44
- const constructorBindings = (_a = Reflect.getOwnMetadata(RESOURCE_PARAMETERS_METADATA, constructor)) !== null && _a !== void 0 ? _a : [];
42
+ const constructorBindings = Reflect.getOwnMetadata(RESOURCE_PARAMETERS_METADATA, constructor) ?? [];
45
43
  constructorBindings.forEach((binding) => bindings.set(binding.token, binding));
46
44
  constructor = Object.getPrototypeOf(constructor);
47
45
  }
@@ -3,34 +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 !== null && providers !== void 0 ? providers : [])
14
- .filter((mapping) => mapping.key.startsWith('arm_command_'))
15
- .forEach((mapping) => {
16
- var _a;
17
- const rawCommandName = mapping.key.split('_').slice(2).join('_');
18
- const commandName = rawCommandName.toLowerCase() + (((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.suffix) || '');
19
- if (!Cfx.Client.IsDuplicityVersion()) {
20
- Cfx.Client.RegisterCommand(commandName, (_source, args, _raw) => {
21
- mapping.target[rawCommandName].apply(mapping.target, args);
22
- }, false);
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;
23
17
  }
24
- else {
25
- Cfx.Server.RegisterCommand(commandName, (source, args, _raw) => {
26
- var _a, _b;
27
- // TODO: This conditional is not generic enough. This conditional should actually check a function given through an injection token.
28
- if (((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.adminLevelRequired) && Number(Cfx.exports['authentication'].getPlayerInfo(source, 'adminLevel')) < ((_b = mapping.value) === null || _b === void 0 ? void 0 : _b.adminLevelRequired)) {
29
- // TODO: Add error chat message OR some kind of visual notice here
30
- return;
31
- }
32
- mapping.target[rawCommandName].apply(mapping.target, [source, ...args]);
18
+ const rawCommandName = mapping.key.substring(12);
19
+ const commandName = rawCommandName.toLowerCase() + (mapping.value?.suffix || '');
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);
33
25
  }, false);
26
+ continue;
34
27
  }
35
- });
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
+ }
41
+ }
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
+ }
36
53
  }
@@ -6,14 +6,14 @@ exports.EventListeners = EventListeners;
6
6
  const decorator_utils_1 = require("./decorator.utils");
7
7
  function EventListener(data) {
8
8
  return function (target, propertyKey) {
9
- const eventName = (exports.DEFAULT_EVENTS[propertyKey] || (data === null || data === void 0 ? void 0 : data.eventName));
10
- const direction = (data === null || data === void 0 ? void 0 : data.direction) || EVENT_DIRECTIONS.CLIENT_TO_SERVER;
11
- const type = (data === null || data === void 0 ? void 0 : data.type) || 'default';
9
+ const eventName = (exports.DEFAULT_EVENTS[propertyKey] || data?.eventName);
10
+ const direction = data?.direction || EVENT_DIRECTIONS.CLIENT_TO_SERVER;
11
+ const type = data?.type || 'default';
12
12
  Reflect.defineMetadata(`arm_eventListener_${propertyKey}`, { eventName, direction, type }, target);
13
13
  };
14
14
  }
15
15
  function EventListeners(target, _prototype, providers) {
16
- decorator_utils_1.DecoratorUtils.map(target, _prototype, providers !== null && providers !== void 0 ? providers : [])
16
+ decorator_utils_1.DecoratorUtils.map(target, _prototype, providers ?? [])
17
17
  .filter((mapping) => mapping.key.startsWith('arm_eventListener_'))
18
18
  .forEach((mapping) => {
19
19
  const { eventName, direction, type } = mapping.value;
@@ -9,7 +9,7 @@ function Export() {
9
9
  };
10
10
  }
11
11
  function Exports(target, _prototype, providers) {
12
- decorator_utils_1.DecoratorUtils.map(target, _prototype, providers !== null && providers !== void 0 ? providers : [])
12
+ decorator_utils_1.DecoratorUtils.map(target, _prototype, providers ?? [])
13
13
  .filter((mapping) => mapping.key.startsWith('arm_export_'))
14
14
  .forEach((mapping) => {
15
15
  const exportName = mapping.key.split('_').slice(2).join('_');
@@ -17,20 +17,19 @@ function KeyBindings(target, _prototype, providers) {
17
17
  if (Cfx.Client.IsDuplicityVersion()) {
18
18
  return;
19
19
  }
20
- const mappings = decorator_utils_1.DecoratorUtils.map(target, _prototype, providers !== null && providers !== void 0 ? providers : []);
20
+ const mappings = decorator_utils_1.DecoratorUtils.map(target, _prototype, providers ?? []);
21
21
  mappings
22
22
  .filter((mapping) => mapping.key.startsWith('arm_keybinding_'))
23
23
  .forEach((mapping) => {
24
- var _a, _b, _c, _d, _e;
25
24
  const keybindingName = mapping.key.split('_').slice(2).join('_');
26
25
  const commandMapping = mappings.find((entry) => entry.target === mapping.target && entry.key === `arm_command_${keybindingName}`);
27
- const command = ((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.command)
26
+ const command = mapping.value?.command
28
27
  ? mapping.value.command.toLowerCase()
29
- : keybindingName.toLowerCase() + (((_b = commandMapping === null || commandMapping === void 0 ? void 0 : commandMapping.value) === null || _b === void 0 ? void 0 : _b.suffix) || '');
28
+ : keybindingName.toLowerCase() + (commandMapping?.value?.suffix || '');
30
29
  if (!command) {
31
30
  console.error(`Could not find any relevant command for key binding ${keybindingName}`);
32
31
  return;
33
32
  }
34
- Cfx.Client.RegisterKeyMapping(command, (_c = mapping.value) === null || _c === void 0 ? void 0 : _c.description, (_d = mapping.value) === null || _d === void 0 ? void 0 : _d.defaultMapper, (_e = mapping.value) === null || _e === void 0 ? void 0 : _e.key);
33
+ Cfx.Client.RegisterKeyMapping(command, mapping.value?.description, mapping.value?.defaultMapper, mapping.value?.key);
35
34
  });
36
35
  }
@@ -5,12 +5,12 @@ exports.UIListeners = UIListeners;
5
5
  const decorator_utils_1 = require("./decorator.utils");
6
6
  function UIListener(data) {
7
7
  return function (target, propertyKey, _descriptor) {
8
- const eventName = (data === null || data === void 0 ? void 0 : data.eventName) || propertyKey;
8
+ const eventName = data?.eventName || propertyKey;
9
9
  Reflect.defineMetadata(`arm_uiListener_${propertyKey}`, { eventName }, target);
10
10
  };
11
11
  }
12
12
  function UIListeners(target, _prototype, providers) {
13
- decorator_utils_1.DecoratorUtils.map(target, _prototype, providers !== null && providers !== void 0 ? providers : [])
13
+ decorator_utils_1.DecoratorUtils.map(target, _prototype, providers ?? [])
14
14
  .filter((mapping) => mapping.key.startsWith('arm_uiListener_'))
15
15
  .forEach((mapping) => {
16
16
  const { eventName } = mapping.value;
@@ -16,8 +16,7 @@ class Session {
16
16
  * @returns the value from the state, or null if not found.
17
17
  */
18
18
  getState(stateItemName) {
19
- var _a;
20
- return (_a = Cfx.Player(this.id).state[`session:${stateItemName}:value`]) !== null && _a !== void 0 ? _a : null;
19
+ return Cfx.Player(this.id).state[`session:${stateItemName}:value`] ?? null;
21
20
  }
22
21
  /**
23
22
  * Updates the state of a player.
@@ -36,7 +35,7 @@ class Session {
36
35
  * @returns the value which has been set.
37
36
  */
38
37
  setState(stateItemName, value, replicate) {
39
- Cfx.Player(this.id).state.set(`session:${stateItemName}:value`, value, replicate !== null && replicate !== void 0 ? replicate : Cfx.Server.IsDuplicityVersion());
38
+ Cfx.Player(this.id).state.set(`session:${stateItemName}:value`, value, replicate ?? Cfx.Server.IsDuplicityVersion());
40
39
  return value;
41
40
  }
42
41
  /**
@@ -46,7 +45,6 @@ class Session {
46
45
  * @returns the value from the state, or null if not found.
47
46
  */
48
47
  getServerClaimValue(claimName) {
49
- var _a;
50
48
  if (!Cfx.Server.IsDuplicityVersion()) {
51
49
  console.error('Claims are not currently available in client scripts.');
52
50
  return null;
@@ -55,7 +53,7 @@ class Session {
55
53
  if (claimValue == null) {
56
54
  return null;
57
55
  }
58
- const kind = (_a = Cfx.Player(this.id).state[`session:${claimName}:kind`]) !== null && _a !== void 0 ? _a : session_claim_1.SessionClaimType.Direct;
56
+ const kind = Cfx.Player(this.id).state[`session:${claimName}:kind`] ?? session_claim_1.SessionClaimType.Direct;
59
57
  if (kind === session_claim_1.SessionClaimType.Proxied) {
60
58
  const proxiedValue = this.getProxiedServerClaimValue(claimName);
61
59
  Cfx.Player(this.id).state.set(`session:${claimName}:value`, proxiedValue, false);
@@ -71,7 +69,6 @@ class Session {
71
69
  * @returns the value from the proxied state, or null if not found or impossible.
72
70
  */
73
71
  getProxiedServerClaimValue(claimName) {
74
- var _a, _b;
75
72
  if (!Cfx.Server.IsDuplicityVersion()) {
76
73
  console.error('Proxied claims are not currently available in client scripts.');
77
74
  return null;
@@ -82,7 +79,8 @@ class Session {
82
79
  + 'returning null.');
83
80
  return null;
84
81
  }
85
- return (_b = (_a = globalThis.exports[resource]) === null || _a === void 0 ? void 0 : _a.getProxiedClaimValue(claimName, this.id)) !== null && _b !== void 0 ? _b : null;
82
+ return globalThis.exports[resource]
83
+ ?.getProxiedClaimValue(claimName, this.id) ?? null;
86
84
  }
87
85
  /**
88
86
  * Updates the state of the player, but doesn't replicate the value to the client.
@@ -88,12 +88,11 @@ const toThousandsString = (input, args) => {
88
88
  };
89
89
  exports.toThousandsString = toThousandsString;
90
90
  const fromThousandsString = (input) => {
91
- var _a;
92
91
  const existingSuffix = (input.match(/[a-zA-Z]/) || []).pop() || '';
93
92
  if (!existingSuffix) {
94
93
  return Number(input);
95
94
  }
96
- const existingNumber = Number((_a = input.match(/\d+/)) === null || _a === void 0 ? void 0 : _a[0]);
95
+ const existingNumber = Number(input.match(/\d+/)?.[0]);
97
96
  return (existingNumber *
98
97
  Math.pow(1000, 1 +
99
98
  suffixes
@@ -11,23 +11,21 @@ export function Config(key, index = 0) {
11
11
  const token = new InjectionToken(`Config(${key}, ${index})`);
12
12
  const inject = Inject(token);
13
13
  return (target, propertyKey, parameterIndex) => {
14
- var _a;
15
14
  if (propertyKey !== undefined) {
16
15
  throw new Error('Config can only decorate constructor parameters.');
17
16
  }
18
17
  inject(target, propertyKey, parameterIndex);
19
- const bindings = (_a = Reflect.getOwnMetadata(CONFIG_PARAMETERS_METADATA, target)) !== null && _a !== void 0 ? _a : [];
18
+ const bindings = Reflect.getOwnMetadata(CONFIG_PARAMETERS_METADATA, target) ?? [];
20
19
  const binding = { token, key, index };
21
20
  Reflect.defineMetadata(CONFIG_PARAMETERS_METADATA, [...bindings, binding], target);
22
21
  };
23
22
  }
24
23
  export function createConfigProviders(targets, readValue) {
25
- var _a;
26
24
  const bindings = new Map();
27
25
  for (const target of targets) {
28
26
  let constructor = target;
29
27
  while (constructor && constructor !== Function.prototype) {
30
- const constructorBindings = (_a = Reflect.getOwnMetadata(CONFIG_PARAMETERS_METADATA, constructor)) !== null && _a !== void 0 ? _a : [];
28
+ const constructorBindings = Reflect.getOwnMetadata(CONFIG_PARAMETERS_METADATA, constructor) ?? [];
31
29
  constructorBindings.forEach((binding) => bindings.set(binding.token, binding));
32
30
  constructor = Object.getPrototypeOf(constructor);
33
31
  }
@@ -58,7 +56,7 @@ export function parseConfigValue(value, metadataKey) {
58
56
  try {
59
57
  return JSON.parse(expression);
60
58
  }
61
- catch (_a) {
59
+ catch {
62
60
  // Resource manifest tables use Lua syntax rather than JSON.
63
61
  }
64
62
  }
@@ -70,9 +70,8 @@ function hasProviderForToken(providers, token) {
70
70
  return false;
71
71
  }
72
72
  export async function bootstrapWithProviders(entryPoint, parentProviders, options = {}, decorationType = DecorationType.SERVER, readConfigValue, readResourceExports, defaultEagerProviders = []) {
73
- var _a, _b;
74
- const eagerProviders = (_a = options.eager) !== null && _a !== void 0 ? _a : [];
75
- const optionProviders = (_b = options.providers) !== null && _b !== void 0 ? _b : [];
73
+ const eagerProviders = options.eager ?? [];
74
+ const optionProviders = options.providers ?? [];
76
75
  const platformDefaultProviders = flattenProviders(defaultEagerProviders);
77
76
  const activeDefaultEagerProviders = platformDefaultProviders.filter((defaultProvider) => {
78
77
  const token = getProviderToken(defaultProvider);
@@ -20,22 +20,20 @@ export function Resource(resourceName) {
20
20
  const token = new InjectionToken(`Resource(${resourceName})`);
21
21
  const inject = Inject(token);
22
22
  return (target, propertyKey, parameterIndex) => {
23
- var _a;
24
23
  if (propertyKey !== undefined) {
25
24
  throw new Error('Resource can only decorate constructor parameters.');
26
25
  }
27
26
  inject(target, propertyKey, parameterIndex);
28
- const bindings = (_a = Reflect.getOwnMetadata(RESOURCE_PARAMETERS_METADATA, target)) !== null && _a !== void 0 ? _a : [];
27
+ const bindings = Reflect.getOwnMetadata(RESOURCE_PARAMETERS_METADATA, target) ?? [];
29
28
  Reflect.defineMetadata(RESOURCE_PARAMETERS_METADATA, [...bindings, { token, resourceName }], target);
30
29
  };
31
30
  }
32
31
  export function createResourceProviders(targets, readExports) {
33
- var _a;
34
32
  const bindings = new Map();
35
33
  for (const target of targets) {
36
34
  let constructor = target;
37
35
  while (constructor && constructor !== Function.prototype) {
38
- const constructorBindings = (_a = Reflect.getOwnMetadata(RESOURCE_PARAMETERS_METADATA, constructor)) !== null && _a !== void 0 ? _a : [];
36
+ const constructorBindings = Reflect.getOwnMetadata(RESOURCE_PARAMETERS_METADATA, constructor) ?? [];
39
37
  constructorBindings.forEach((binding) => bindings.set(binding.token, binding));
40
38
  constructor = Object.getPrototypeOf(constructor);
41
39
  }
@@ -1,32 +1,49 @@
1
- import { DecoratorUtils } from "./decorator.utils";
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 !== null && providers !== void 0 ? providers : [])
10
- .filter((mapping) => mapping.key.startsWith('arm_command_'))
11
- .forEach((mapping) => {
12
- var _a;
13
- const rawCommandName = mapping.key.split('_').slice(2).join('_');
14
- const commandName = rawCommandName.toLowerCase() + (((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.suffix) || '');
15
- if (!Cfx.Client.IsDuplicityVersion()) {
16
- Cfx.Client.RegisterCommand(commandName, (_source, args, _raw) => {
17
- mapping.target[rawCommandName].apply(mapping.target, args);
18
- }, false);
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;
19
13
  }
20
- else {
21
- Cfx.Server.RegisterCommand(commandName, (source, args, _raw) => {
22
- var _a, _b;
23
- // TODO: This conditional is not generic enough. This conditional should actually check a function given through an injection token.
24
- if (((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.adminLevelRequired) && Number(Cfx.exports['authentication'].getPlayerInfo(source, 'adminLevel')) < ((_b = mapping.value) === null || _b === void 0 ? void 0 : _b.adminLevelRequired)) {
25
- // TODO: Add error chat message OR some kind of visual notice here
26
- return;
27
- }
28
- mapping.target[rawCommandName].apply(mapping.target, [source, ...args]);
14
+ const rawCommandName = mapping.key.substring(12);
15
+ const commandName = rawCommandName.toLowerCase() + (mapping.value?.suffix || '');
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);
29
21
  }, false);
22
+ continue;
30
23
  }
31
- });
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
+ }
37
+ }
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
+ }
32
49
  }
@@ -1,14 +1,14 @@
1
1
  import { DecoratorUtils } from "./decorator.utils";
2
2
  export function EventListener(data) {
3
3
  return function (target, propertyKey) {
4
- const eventName = (DEFAULT_EVENTS[propertyKey] || (data === null || data === void 0 ? void 0 : data.eventName));
5
- const direction = (data === null || data === void 0 ? void 0 : data.direction) || EVENT_DIRECTIONS.CLIENT_TO_SERVER;
6
- const type = (data === null || data === void 0 ? void 0 : data.type) || 'default';
4
+ const eventName = (DEFAULT_EVENTS[propertyKey] || data?.eventName);
5
+ const direction = data?.direction || EVENT_DIRECTIONS.CLIENT_TO_SERVER;
6
+ const type = data?.type || 'default';
7
7
  Reflect.defineMetadata(`arm_eventListener_${propertyKey}`, { eventName, direction, type }, target);
8
8
  };
9
9
  }
10
10
  export function EventListeners(target, _prototype, providers) {
11
- DecoratorUtils.map(target, _prototype, providers !== null && providers !== void 0 ? providers : [])
11
+ DecoratorUtils.map(target, _prototype, providers ?? [])
12
12
  .filter((mapping) => mapping.key.startsWith('arm_eventListener_'))
13
13
  .forEach((mapping) => {
14
14
  const { eventName, direction, type } = mapping.value;
@@ -5,7 +5,7 @@ export function Export() {
5
5
  };
6
6
  }
7
7
  export function Exports(target, _prototype, providers) {
8
- DecoratorUtils.map(target, _prototype, providers !== null && providers !== void 0 ? providers : [])
8
+ DecoratorUtils.map(target, _prototype, providers ?? [])
9
9
  .filter((mapping) => mapping.key.startsWith('arm_export_'))
10
10
  .forEach((mapping) => {
11
11
  const exportName = mapping.key.split('_').slice(2).join('_');
@@ -13,20 +13,19 @@ export function KeyBindings(target, _prototype, providers) {
13
13
  if (Cfx.Client.IsDuplicityVersion()) {
14
14
  return;
15
15
  }
16
- const mappings = DecoratorUtils.map(target, _prototype, providers !== null && providers !== void 0 ? providers : []);
16
+ const mappings = DecoratorUtils.map(target, _prototype, providers ?? []);
17
17
  mappings
18
18
  .filter((mapping) => mapping.key.startsWith('arm_keybinding_'))
19
19
  .forEach((mapping) => {
20
- var _a, _b, _c, _d, _e;
21
20
  const keybindingName = mapping.key.split('_').slice(2).join('_');
22
21
  const commandMapping = mappings.find((entry) => entry.target === mapping.target && entry.key === `arm_command_${keybindingName}`);
23
- const command = ((_a = mapping.value) === null || _a === void 0 ? void 0 : _a.command)
22
+ const command = mapping.value?.command
24
23
  ? mapping.value.command.toLowerCase()
25
- : keybindingName.toLowerCase() + (((_b = commandMapping === null || commandMapping === void 0 ? void 0 : commandMapping.value) === null || _b === void 0 ? void 0 : _b.suffix) || '');
24
+ : keybindingName.toLowerCase() + (commandMapping?.value?.suffix || '');
26
25
  if (!command) {
27
26
  console.error(`Could not find any relevant command for key binding ${keybindingName}`);
28
27
  return;
29
28
  }
30
- Cfx.Client.RegisterKeyMapping(command, (_c = mapping.value) === null || _c === void 0 ? void 0 : _c.description, (_d = mapping.value) === null || _d === void 0 ? void 0 : _d.defaultMapper, (_e = mapping.value) === null || _e === void 0 ? void 0 : _e.key);
29
+ Cfx.Client.RegisterKeyMapping(command, mapping.value?.description, mapping.value?.defaultMapper, mapping.value?.key);
31
30
  });
32
31
  }
@@ -1,12 +1,12 @@
1
1
  import { DecoratorUtils } from "./decorator.utils";
2
2
  export function UIListener(data) {
3
3
  return function (target, propertyKey, _descriptor) {
4
- const eventName = (data === null || data === void 0 ? void 0 : data.eventName) || propertyKey;
4
+ const eventName = data?.eventName || propertyKey;
5
5
  Reflect.defineMetadata(`arm_uiListener_${propertyKey}`, { eventName }, target);
6
6
  };
7
7
  }
8
8
  export function UIListeners(target, _prototype, providers) {
9
- DecoratorUtils.map(target, _prototype, providers !== null && providers !== void 0 ? providers : [])
9
+ DecoratorUtils.map(target, _prototype, providers ?? [])
10
10
  .filter((mapping) => mapping.key.startsWith('arm_uiListener_'))
11
11
  .forEach((mapping) => {
12
12
  const { eventName } = mapping.value;
@@ -13,8 +13,7 @@ export class Session {
13
13
  * @returns the value from the state, or null if not found.
14
14
  */
15
15
  getState(stateItemName) {
16
- var _a;
17
- return (_a = Cfx.Player(this.id).state[`session:${stateItemName}:value`]) !== null && _a !== void 0 ? _a : null;
16
+ return Cfx.Player(this.id).state[`session:${stateItemName}:value`] ?? null;
18
17
  }
19
18
  /**
20
19
  * Updates the state of a player.
@@ -33,7 +32,7 @@ export class Session {
33
32
  * @returns the value which has been set.
34
33
  */
35
34
  setState(stateItemName, value, replicate) {
36
- Cfx.Player(this.id).state.set(`session:${stateItemName}:value`, value, replicate !== null && replicate !== void 0 ? replicate : Cfx.Server.IsDuplicityVersion());
35
+ Cfx.Player(this.id).state.set(`session:${stateItemName}:value`, value, replicate ?? Cfx.Server.IsDuplicityVersion());
37
36
  return value;
38
37
  }
39
38
  /**
@@ -43,7 +42,6 @@ export class Session {
43
42
  * @returns the value from the state, or null if not found.
44
43
  */
45
44
  getServerClaimValue(claimName) {
46
- var _a;
47
45
  if (!Cfx.Server.IsDuplicityVersion()) {
48
46
  console.error('Claims are not currently available in client scripts.');
49
47
  return null;
@@ -52,7 +50,7 @@ export class Session {
52
50
  if (claimValue == null) {
53
51
  return null;
54
52
  }
55
- const kind = (_a = Cfx.Player(this.id).state[`session:${claimName}:kind`]) !== null && _a !== void 0 ? _a : SessionClaimType.Direct;
53
+ const kind = Cfx.Player(this.id).state[`session:${claimName}:kind`] ?? SessionClaimType.Direct;
56
54
  if (kind === SessionClaimType.Proxied) {
57
55
  const proxiedValue = this.getProxiedServerClaimValue(claimName);
58
56
  Cfx.Player(this.id).state.set(`session:${claimName}:value`, proxiedValue, false);
@@ -68,7 +66,6 @@ export class Session {
68
66
  * @returns the value from the proxied state, or null if not found or impossible.
69
67
  */
70
68
  getProxiedServerClaimValue(claimName) {
71
- var _a, _b;
72
69
  if (!Cfx.Server.IsDuplicityVersion()) {
73
70
  console.error('Proxied claims are not currently available in client scripts.');
74
71
  return null;
@@ -79,7 +76,8 @@ export class Session {
79
76
  + 'returning null.');
80
77
  return null;
81
78
  }
82
- return (_b = (_a = globalThis.exports[resource]) === null || _a === void 0 ? void 0 : _a.getProxiedClaimValue(claimName, this.id)) !== null && _b !== void 0 ? _b : null;
79
+ return globalThis.exports[resource]
80
+ ?.getProxiedClaimValue(claimName, this.id) ?? null;
83
81
  }
84
82
  /**
85
83
  * Updates the state of the player, but doesn't replicate the value to the client.
@@ -73,12 +73,11 @@ export const toThousandsString = (input, args) => {
73
73
  return ((isNegative ? '-' : '') + (input / Math.pow(1000, exp)).toFixed(args) + suffixes[exp - 1]);
74
74
  };
75
75
  export const fromThousandsString = (input) => {
76
- var _a;
77
76
  const existingSuffix = (input.match(/[a-zA-Z]/) || []).pop() || '';
78
77
  if (!existingSuffix) {
79
78
  return Number(input);
80
79
  }
81
- const existingNumber = Number((_a = input.match(/\d+/)) === null || _a === void 0 ? void 0 : _a[0]);
80
+ const existingNumber = Number(input.match(/\d+/)?.[0]);
82
81
  return (existingNumber *
83
82
  Math.pow(1000, 1 +
84
83
  suffixes
@@ -1,5 +1,5 @@
1
1
  export declare function Command(data?: {
2
- adminLevelRequired?: number;
2
+ permissions?: string[] | string;
3
3
  suffix?: string;
4
4
  }): (target: any, propertyKey: string) => void;
5
5
  export declare function Commands(target: any, _prototype: any, providers?: Object[]): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armoury/fivem-framework-common",
3
- "version": "1.0.54",
3
+ "version": "1.0.61",
4
4
  "description": "Shared APIs for the Armoury FiveM framework",
5
5
  "main": "dist/cjs/common/index.js",
6
6
  "module": "dist/esm/common/index.js",