@pma-network/redm-server 0.0.1

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/PMA.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ import type { ItemData, ItemName } from "@common-types/Inventory";
2
+ import type { PlayerUID } from "@common-types/PMAPlayer";
3
+ import type { UsableItemCall } from "./types/Inventory";
4
+ import { PMAPlayerWrapper } from "./class/PMAPlayerWrapper";
5
+ /**
6
+ * A static class that's used for invoking framework types
7
+ */
8
+ export declare class PMA {
9
+ /**
10
+ * @returns the item data for {@param item_name}, or `null` if the item doesn't exist
11
+ */
12
+ static get_item(item_name: ItemName): Readonly<ItemData | null>;
13
+ /**
14
+ * Registers the {@param item_name} to be used as a usable item
15
+ * @throws this will throw an error if {@param item_name} isn't usable
16
+ */
17
+ static register_usable_item(item_name: ItemName, fn: UsableItemCall): void;
18
+ /**
19
+ * Gets the player from the specified source
20
+ * @note the PMAPlayer is lazy initialized so we don't do un-needed scrt
21
+ * calls, this means that we *can* possibly end up in a state where the player
22
+ * isn't initialized, this won't break anything though.
23
+ * @returns the PMAPlayer wrapper, or `null` if the player doesn't exist
24
+ */
25
+ static from_source(source: number): PMAPlayerWrapper | null;
26
+ /**
27
+ * Gets the player from the specified UID
28
+ * @returns the PMAPlayer wrapper, or `null` if there wasn't a player
29
+ */
30
+ static from_uid(uid: PlayerUID): PMAPlayerWrapper | null;
31
+ /**
32
+ * Gets all of the players that habe the specified job(s), and the specified {@param job_rank} if specified.
33
+ */
34
+ static get_players_with_job(job_names: string | string[], job_rank?: number): PMAPlayerWrapper[];
35
+ /**
36
+ * Generic logging
37
+ * TODO: Setup a clickhouse wrapper
38
+ */
39
+ static log(log_message: string, additional_data?: {
40
+ [key: string]: any;
41
+ }): void;
42
+ }
package/PMA.js ADDED
@@ -0,0 +1,61 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { Ped, randomInt } from "@nativewrappers/server";
4
+ import { PMAPlayerWrapper } from "./class/PMAPlayerWrapper";
5
+ class PMA {
6
+ static {
7
+ __name(this, "PMA");
8
+ }
9
+ /**
10
+ * @returns the item data for {@param item_name}, or `null` if the item doesn't exist
11
+ */
12
+ static get_item(item_name) {
13
+ return exports["pma"].get_item(item_name);
14
+ }
15
+ /**
16
+ * Registers the {@param item_name} to be used as a usable item
17
+ * @throws this will throw an error if {@param item_name} isn't usable
18
+ */
19
+ static register_usable_item(item_name, fn) {
20
+ const usable_item_wrapper = /* @__PURE__ */ __name((abstract_ply, inventory, item) => {
21
+ const ply = PMAPlayerWrapper.from_raw(abstract_ply);
22
+ fn(ply, inventory, item);
23
+ }, "usable_item_wrapper");
24
+ exports["pma"].register_usable_item(item_name, usable_item_wrapper);
25
+ }
26
+ /**
27
+ * Gets the player from the specified source
28
+ * @note the PMAPlayer is lazy initialized so we don't do un-needed scrt
29
+ * calls, this means that we *can* possibly end up in a state where the player
30
+ * isn't initialized, this won't break anything though.
31
+ * @returns the PMAPlayer wrapper, or `null` if the player doesn't exist
32
+ */
33
+ static from_source(source) {
34
+ return PMAPlayerWrapper.from_source(source);
35
+ }
36
+ /**
37
+ * Gets the player from the specified UID
38
+ * @returns the PMAPlayer wrapper, or `null` if there wasn't a player
39
+ */
40
+ static from_uid(uid) {
41
+ const data = exports["pma"].from_uid(uid);
42
+ return data ? PMAPlayerWrapper.from_raw(data) : null;
43
+ }
44
+ /**
45
+ * Gets all of the players that habe the specified job(s), and the specified {@param job_rank} if specified.
46
+ */
47
+ static get_players_with_job(job_names, job_rank) {
48
+ const players = exports["pma"].get_players_with_job(job_names, job_rank);
49
+ return players.map((v) => PMAPlayerWrapper.from_raw(v));
50
+ }
51
+ /**
52
+ * Generic logging
53
+ * TODO: Setup a clickhouse wrapper
54
+ */
55
+ static log(log_message, additional_data) {
56
+ console.log(log_message, additional_data);
57
+ }
58
+ }
59
+ export {
60
+ PMA
61
+ };
package/README.md ADDED
@@ -0,0 +1,45 @@
1
+ <h1 align="center">Monorepo for a FiveM server/client wrapper</h1>
2
+
3
+ <p align="center">
4
+ <i>🔥 A Javascript/Typescript package for FiveM resource development 🎮</i>
5
+ <br>
6
+ <small>This project is in no way affiliated with FiveM or the Cfx.re Collective.</small>
7
+ </br></br>
8
+ <a href="https://github.com/nativewrappers/nativewrappers/blob/master/LICENSE">
9
+ <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat" alt="License: MIT">
10
+ </a>
11
+ <a href="https://www.npmjs.com/package/@nativewrappers/fivem">
12
+ <img src="https://img.shields.io/npm/v/@nativewrappers/fivem?style=flat" alt="npm version">
13
+ </a>
14
+ <a href="https://www.npmjs.com/package/@nativewrappers/fivem">
15
+ <img src="https://img.shields.io/npm/dm/@nativewrappers/fivem?style=flat">
16
+ </a>
17
+ <a href="https://github.com/nativewrappers/nativewrappers/actions/workflows/config.yml">
18
+ <img src="https://github.com/nativewrappers/nativewrappers/actions/workflows/config.yml/badge.svg" alt="Workflow Status">
19
+ </a>
20
+ <a href="https://github.com/nativewrappers/nativewrappers/commits/master">
21
+ <img src="https://img.shields.io/github/last-commit/nativewrappers/fivem.svg?style=flat" alt="Last commit">
22
+ </a>
23
+ </p>
24
+
25
+ <h3 align="center">This project is currently iterating rapidly, there will be breaking changes.</h3>
26
+
27
+ <p align="center">
28
+ <h2 align="center"><a href="https://github.com/nativewrappers/nativewrappers/tree/main/docs">Documentation</a></h2>
29
+ <!-- <a href="https://forum.fivem.net/t/fivem-js-v1-3-2-javascript-typescript-wrapper-now-with-menu-class-nativeui/268640">Forum</a> -->
30
+ </p>
31
+
32
+ ## Features
33
+
34
+ - No runtime dependencies
35
+ - Entity management through class objects (i.e. `Vehicle` and `Ped` entities)
36
+ - Server and Client side variants on wrapper
37
+
38
+
39
+ ## Download & Install
40
+ ```
41
+ pnpm add @nativewrappers/redm # for redm,
42
+ pnpm add @nativewrappers/fivem # for fivem
43
+ pnpm add @nativewrappers/common # for any, should be game agnostic, provides Vector3, decors, kvps, helper functions, etc
44
+ pnpm add @nativewrappers/server # for server
45
+ ```
@@ -0,0 +1,37 @@
1
+ import type { ItemName, OptionalItem } from "@common-types/Inventory";
2
+ import type { NotificationVariant, PMAPartialNotification } from "@common-types/Notifications";
3
+ import type { AbstractPMAPlayer, CallSign, PlayerJob, PlayerUID } from "@common-types/PMAPlayer";
4
+ import { Player } from "@nativewrappers/server";
5
+ export declare class PMAPlayerWrapper extends Player implements AbstractPMAPlayer {
6
+ #private;
7
+ /**
8
+ * Creates the player from the ScRT msgpack'd class
9
+ */
10
+ static from_raw(ply: AbstractPMAPlayer): PMAPlayerWrapper;
11
+ /**
12
+ * Does basic checks that the player exists before lazy initializing the player
13
+ */
14
+ static from_source(source: number): PMAPlayerWrapper | null;
15
+ constructor(source: number);
16
+ constructor(pma_player: AbstractPMAPlayer);
17
+ ensure_init(): void;
18
+ send_notification(title?: string, description?: string, variant?: NotificationVariant): void;
19
+ send_notification_object(partial: PMAPartialNotification): void;
20
+ get_sex(): number;
21
+ get_height(): number;
22
+ get_dob(): string;
23
+ get_unique_id(): PlayerUID;
24
+ get_call_sign(): CallSign;
25
+ get_character_name(): string;
26
+ get_log_name(): string;
27
+ get_item(item_name: ItemName): OptionalItem;
28
+ add_item(item_name: ItemName, quantity: number): OptionalItem;
29
+ remove_item(item_name: ItemName, quantity: number): void;
30
+ has_enough_of_item(item_name: ItemName, quantity: number): boolean;
31
+ get_job(): PlayerJob;
32
+ set_job(job_name: string, rank: number): void;
33
+ get_bank(): number;
34
+ add_to_bank(positive_amount: number): void;
35
+ remove_from_bank(negative_amount: number): void;
36
+ save(): Promise<void>;
37
+ }
@@ -0,0 +1,124 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { Player } from "@nativewrappers/server";
4
+ class PMAPlayerWrapper extends Player {
5
+ static {
6
+ __name(this, "PMAPlayerWrapper");
7
+ }
8
+ // This will get lazy-initialized whenever we actually call a function that needs it,
9
+ // this will make sure we don't pay the un-needed serialize cost if we're only using this for
10
+ // basic nativewrappers types
11
+ #pma_player;
12
+ /**
13
+ * Creates the player from the ScRT msgpack'd class
14
+ */
15
+ static from_raw(ply) {
16
+ return new PMAPlayerWrapper(ply);
17
+ }
18
+ /**
19
+ * Does basic checks that the player exists before lazy initializing the player
20
+ */
21
+ static from_source(source) {
22
+ if (!DoesPlayerExist(source)) {
23
+ return null;
24
+ }
25
+ return new PMAPlayerWrapper(source);
26
+ }
27
+ constructor(source) {
28
+ if (typeof source !== "number") {
29
+ const ply = source;
30
+ super(ply.source);
31
+ this.#pma_player = ply;
32
+ } else {
33
+ super(source);
34
+ }
35
+ }
36
+ // Ensure we initialize the player whenever we're doing something that needs it.
37
+ ensure_init() {
38
+ if (!this.#pma_player) {
39
+ this.#pma_player = exports["pma"].from_source(this.Source);
40
+ }
41
+ }
42
+ send_notification(title, description, variant = "default") {
43
+ const noti = {
44
+ title,
45
+ body: description,
46
+ variant
47
+ };
48
+ this.emit("pma:add_notifications", noti);
49
+ }
50
+ send_notification_object(partial) {
51
+ this.emit("pma:add_notification", partial);
52
+ }
53
+ get_sex() {
54
+ this.ensure_init();
55
+ return this.#pma_player.get_sex();
56
+ }
57
+ get_height() {
58
+ this.ensure_init();
59
+ return this.#pma_player.get_height();
60
+ }
61
+ get_dob() {
62
+ this.ensure_init();
63
+ return this.#pma_player.get_dob();
64
+ }
65
+ get_unique_id() {
66
+ this.ensure_init();
67
+ return this.#pma_player.get_unique_id();
68
+ }
69
+ get_call_sign() {
70
+ this.ensure_init();
71
+ return this.#pma_player.get_call_sign();
72
+ }
73
+ get_character_name() {
74
+ this.ensure_init();
75
+ return this.#pma_player.get_character_name();
76
+ }
77
+ get_log_name() {
78
+ this.ensure_init();
79
+ return this.#pma_player.get_character_name();
80
+ }
81
+ get_item(item_name) {
82
+ this.ensure_init();
83
+ return this.#pma_player.get_item(item_name);
84
+ }
85
+ add_item(item_name, quantity) {
86
+ this.ensure_init();
87
+ return this.#pma_player.add_item(item_name, quantity);
88
+ }
89
+ remove_item(item_name, quantity) {
90
+ this.ensure_init();
91
+ return this.#pma_player.remove_item(item_name, quantity);
92
+ }
93
+ has_enough_of_item(item_name, quantity) {
94
+ this.ensure_init();
95
+ return this.#pma_player.has_enough_of_item(item_name, quantity);
96
+ }
97
+ get_job() {
98
+ this.ensure_init();
99
+ return this.#pma_player.get_job();
100
+ }
101
+ set_job(job_name, rank) {
102
+ this.ensure_init();
103
+ return this.#pma_player.set_job(job_name, rank);
104
+ }
105
+ get_bank() {
106
+ this.ensure_init();
107
+ return this.#pma_player.get_bank();
108
+ }
109
+ add_to_bank(positive_amount) {
110
+ this.ensure_init();
111
+ return this.#pma_player.add_to_bank(positive_amount);
112
+ }
113
+ remove_from_bank(negative_amount) {
114
+ this.ensure_init();
115
+ return this.#pma_player.remove_from_bank(negative_amount);
116
+ }
117
+ save() {
118
+ this.ensure_init();
119
+ return this.#pma_player.save();
120
+ }
121
+ }
122
+ export {
123
+ PMAPlayerWrapper
124
+ };
@@ -0,0 +1,37 @@
1
+ import { Player } from "@nativewrappers/server";
2
+ import type { ItemName, OptionalItem } from "redm-types/Inventory";
3
+ import type { NotificationVariant, PMAPartialNotification } from "redm-types/Notifications";
4
+ import type { AbstractPMAPlayer, CallSign, PlayerJob, PlayerUID } from "redm-types/PMAPlayer";
5
+ export declare class PMAPlayerWrapper extends Player implements AbstractPMAPlayer {
6
+ #private;
7
+ /**
8
+ * Creates the player from the ScRT msgpack'd class
9
+ */
10
+ static from_raw(ply: AbstractPMAPlayer): PMAPlayerWrapper;
11
+ /**
12
+ * Does basic checks that the player exists before lazy initializing the player
13
+ */
14
+ static from_source(source: number): PMAPlayerWrapper | null;
15
+ constructor(source: number);
16
+ constructor(pma_player: AbstractPMAPlayer);
17
+ ensure_init(): void;
18
+ show_notification(title?: string, description?: string, variant?: NotificationVariant): void;
19
+ show_notification_object(partial: PMAPartialNotification): void;
20
+ get_sex(): number;
21
+ get_height(): number;
22
+ get_dob(): string;
23
+ get_unique_id(): PlayerUID;
24
+ get_call_sign(): CallSign;
25
+ get_character_name(): string;
26
+ get_log_name(): string;
27
+ get_item(item_name: ItemName): OptionalItem;
28
+ add_item(item_name: ItemName, quantity: number): OptionalItem;
29
+ remove_item(item_name: ItemName, quantity: number): void;
30
+ has_enough_of_item(item_name: ItemName, quantity: number): boolean;
31
+ get_job(): PlayerJob;
32
+ set_job(job_name: string, rank: number): void;
33
+ get_bank(): number;
34
+ add_to_bank(positive_amount: number): void;
35
+ remove_from_bank(negative_amount: number): void;
36
+ save(): Promise<void>;
37
+ }
@@ -0,0 +1,124 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { Player } from "@nativewrappers/server";
4
+ class PMAPlayerWrapper extends Player {
5
+ static {
6
+ __name(this, "PMAPlayerWrapper");
7
+ }
8
+ // This will get lazy-initialized whenever we actually call a function that needs it,
9
+ // this will make sure we don't pay the un-needed serialize cost if we're only using this for
10
+ // basic nativewrappers types
11
+ #pma_player;
12
+ /**
13
+ * Creates the player from the ScRT msgpack'd class
14
+ */
15
+ static from_raw(ply) {
16
+ return new PMAPlayerWrapper(ply);
17
+ }
18
+ /**
19
+ * Does basic checks that the player exists before lazy initializing the player
20
+ */
21
+ static from_source(source) {
22
+ if (!DoesPlayerExist(source)) {
23
+ return null;
24
+ }
25
+ return new PMAPlayerWrapper(source);
26
+ }
27
+ constructor(source) {
28
+ if (typeof source !== "number") {
29
+ const ply = source;
30
+ super(ply.source);
31
+ this.#pma_player = ply;
32
+ } else {
33
+ super(source);
34
+ }
35
+ }
36
+ // Ensure we initialize the player whenever we're doing something that needs it.
37
+ ensure_init() {
38
+ if (!this.#pma_player) {
39
+ this.#pma_player = exports["pma"].from_source(this.Source);
40
+ }
41
+ }
42
+ show_notification(title, description, variant = "default") {
43
+ const noti = {
44
+ title,
45
+ body: description,
46
+ variant
47
+ };
48
+ this.emit("pma:add_notifications", noti);
49
+ }
50
+ show_notification_object(partial) {
51
+ this.emit("pma:add_notification", partial);
52
+ }
53
+ get_sex() {
54
+ this.ensure_init();
55
+ return this.#pma_player.get_sex();
56
+ }
57
+ get_height() {
58
+ this.ensure_init();
59
+ return this.#pma_player.get_height();
60
+ }
61
+ get_dob() {
62
+ this.ensure_init();
63
+ return this.#pma_player.get_dob();
64
+ }
65
+ get_unique_id() {
66
+ this.ensure_init();
67
+ return this.#pma_player.get_unique_id();
68
+ }
69
+ get_call_sign() {
70
+ this.ensure_init();
71
+ return this.#pma_player.get_call_sign();
72
+ }
73
+ get_character_name() {
74
+ this.ensure_init();
75
+ return this.#pma_player.get_character_name();
76
+ }
77
+ get_log_name() {
78
+ this.ensure_init();
79
+ return this.#pma_player.get_log_name();
80
+ }
81
+ get_item(item_name) {
82
+ this.ensure_init();
83
+ return this.#pma_player.get_item(item_name);
84
+ }
85
+ add_item(item_name, quantity) {
86
+ this.ensure_init();
87
+ return this.#pma_player.add_item(item_name, quantity);
88
+ }
89
+ remove_item(item_name, quantity) {
90
+ this.ensure_init();
91
+ return this.#pma_player.remove_item(item_name, quantity);
92
+ }
93
+ has_enough_of_item(item_name, quantity) {
94
+ this.ensure_init();
95
+ return this.#pma_player.has_enough_of_item(item_name, quantity);
96
+ }
97
+ get_job() {
98
+ this.ensure_init();
99
+ return this.#pma_player.get_job();
100
+ }
101
+ set_job(job_name, rank) {
102
+ this.ensure_init();
103
+ return this.#pma_player.set_job(job_name, rank);
104
+ }
105
+ get_bank() {
106
+ this.ensure_init();
107
+ return this.#pma_player.get_bank();
108
+ }
109
+ add_to_bank(positive_amount) {
110
+ this.ensure_init();
111
+ return this.#pma_player.add_to_bank(positive_amount);
112
+ }
113
+ remove_from_bank(negative_amount) {
114
+ this.ensure_init();
115
+ return this.#pma_player.remove_from_bank(negative_amount);
116
+ }
117
+ save() {
118
+ this.ensure_init();
119
+ return this.#pma_player.save();
120
+ }
121
+ }
122
+ export {
123
+ PMAPlayerWrapper
124
+ };
@@ -0,0 +1,10 @@
1
+ import { PMAPlayerWrapper } from "../class/PMAPlayerWrapper";
2
+ type PMAServerEventType = (player: PMAPlayerWrapper, ...args: any[]) => Promise<void> | void;
3
+ /**
4
+ * Registers the Net Event call for {@link eventName} to this method
5
+ *
6
+ * @param eventName the event to bind this net event to
7
+ * @param remoteOnly if the event should only accept remote calls, if set to true it will ignore any local call via `emit`, defaults to true
8
+ */
9
+ export declare function PMAServerEvent(eventName: string): (originalMethod: PMAServerEventType, context: ClassMethodDecoratorContext) => void;
10
+ export {};
@@ -0,0 +1,46 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { PMAPlayerWrapper } from "../class/PMAPlayerWrapper";
4
+ function PMAServerEvent(eventName) {
5
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
6
+ if (context.private) {
7
+ throw new Error("NetEvent does not work on private methods, please mark the method as public");
8
+ }
9
+ context.addInitializer(function() {
10
+ const _t = this;
11
+ onNet(eventName, async (...args) => {
12
+ const ply = new PMAPlayerWrapper(source);
13
+ if (_t.__permissionMap) {
14
+ const permissions = _t.__permissionMap.get(context.name);
15
+ if (permissions) {
16
+ let hasPermission = false;
17
+ for (const perm of permissions) {
18
+ if (ply.isAceAllowed(perm)) {
19
+ hasPermission = true;
20
+ break;
21
+ }
22
+ }
23
+ if (!hasPermission) {
24
+ emit("@nativewrappers:no_permission", { eventName, method: context.name, source: ply.Source });
25
+ return;
26
+ }
27
+ }
28
+ }
29
+ try {
30
+ return await originalMethod.call(this, ply, ...args);
31
+ } catch (e) {
32
+ console.error("------- NET EVENT ERROR --------");
33
+ console.error(`Call to ${eventName} errored`);
34
+ console.error(`Caller: ${ply.Source}`);
35
+ console.error(`Data: ${JSON.stringify(args)}`);
36
+ console.error(`Error: ${e}`);
37
+ console.error("------- END NET EVENT ERROR --------");
38
+ }
39
+ });
40
+ });
41
+ }, "actualDecorator");
42
+ }
43
+ __name(PMAServerEvent, "PMAServerEvent");
44
+ export {
45
+ PMAServerEvent
46
+ };
@@ -0,0 +1,10 @@
1
+ import { PMAPlayerWrapper } from "../class/PMAPlayer";
2
+ type PMAServerEventType = (player: PMAPlayerWrapper, ...args: any[]) => Promise<void> | void;
3
+ /**
4
+ * Registers the Net Event call for {@link eventName} to this method
5
+ *
6
+ * @param eventName the event to bind this net event to
7
+ * @param remoteOnly if the event should only accept remote calls, if set to true it will ignore any local call via `emit`, defaults to true
8
+ */
9
+ export declare function PMAServerEvent(eventName: string): (originalMethod: PMAServerEventType, context: ClassMethodDecoratorContext) => void;
10
+ export {};
@@ -0,0 +1,46 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { PMAPlayerWrapper } from "../class/PMAPlayer";
4
+ function PMAServerEvent(eventName) {
5
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
6
+ if (context.private) {
7
+ throw new Error("NetEvent does not work on private methods, please mark the method as public");
8
+ }
9
+ context.addInitializer(function() {
10
+ const _t = this;
11
+ onNet(eventName, async (...args) => {
12
+ const ply = new PMAPlayerWrapper(source);
13
+ if (_t.__permissionMap) {
14
+ const permissions = _t.__permissionMap.get(context.name);
15
+ if (permissions) {
16
+ let hasPermission = false;
17
+ for (const perm of permissions) {
18
+ if (ply.isAceAllowed(perm)) {
19
+ hasPermission = true;
20
+ break;
21
+ }
22
+ }
23
+ if (!hasPermission) {
24
+ emit("@nativewrappers:no_permission", { eventName, method: context.name, source: ply.Source });
25
+ return;
26
+ }
27
+ }
28
+ }
29
+ try {
30
+ return await originalMethod.call(this, ply, ...args);
31
+ } catch (e) {
32
+ console.error("------- NET EVENT ERROR --------");
33
+ console.error(`Call to ${eventName} errored`);
34
+ console.error(`Caller: ${ply.Source}`);
35
+ console.error(`Data: ${JSON.stringify(args)}`);
36
+ console.error(`Error: ${e}`);
37
+ console.error("------- END NET EVENT ERROR --------");
38
+ }
39
+ });
40
+ });
41
+ }, "actualDecorator");
42
+ }
43
+ __name(PMAServerEvent, "PMAServerEvent");
44
+ export {
45
+ PMAServerEvent
46
+ };
@@ -0,0 +1,9 @@
1
+ import type { ItemName } from "@common-types/Inventory";
2
+ import type { UsableItemCall } from "../types/Inventory";
3
+ /**
4
+ * Registers the Net Event call for {@link eventName} to this method
5
+ *
6
+ * @param eventName the event to bind this net event to
7
+ * @param remoteOnly if the event should only accept remote calls, if set to true it will ignore any local call via `emit`, defaults to true
8
+ */
9
+ export declare function RegisterUsableItem(item_name: ItemName): (originalMethod: UsableItemCall, context: ClassMethodDecoratorContext) => void;
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { PMAPlayerWrapper } from "../class/PMAPlayer";
4
+ import { PMA } from "../PMA";
5
+ function RegisterUsableItem(item_name) {
6
+ return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
7
+ if (context.private) {
8
+ throw new Error("NetEvent does not work on private methods, please mark the method as public");
9
+ }
10
+ context.addInitializer(function() {
11
+ const t = this;
12
+ PMA.register_usable_item(item_name, (ply, ...args) => {
13
+ try {
14
+ originalMethod.call(t, ply, ...args);
15
+ } catch (e) {
16
+ console.error("------- USABLE ITEM ERROR --------");
17
+ console.error(`Call for ${item_name} errored`);
18
+ console.error(`Caller: ${ply.Source}`);
19
+ console.error(`Data: ${JSON.stringify(args)}`);
20
+ console.error(`Error: ${e}`);
21
+ console.error("------- END USABLE ITEM ERROR --------");
22
+ }
23
+ });
24
+ });
25
+ }, "actualDecorator");
26
+ }
27
+ __name(RegisterUsableItem, "RegisterUsableItem");
28
+ export {
29
+ RegisterUsableItem
30
+ };
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./PMA";
2
+ export * from "./types/Inventory";
3
+ export * from "./decors/PMANetServerEvent";
4
+ export * from "./decors/PMAServerEvent";
5
+ export * from "./decors/RegisterUsableItems";
6
+ export * from "./class/PMAPlayer";
7
+ export * from "./class/PMAPlayerWrapper";
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./PMA";
2
+ export * from "./types/Inventory";
3
+ export * from "./decors/PMANetServerEvent";
4
+ export * from "./decors/PMAServerEvent";
5
+ export * from "./decors/RegisterUsableItems";
6
+ export * from "./class/PMAPlayer";
7
+ export * from "./class/PMAPlayerWrapper";
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@pma-network/redm-server",
3
+ "description": "Native wrappers and utilities for use with PMA RedM Server.",
4
+ "contributors": [
5
+ "Dillon Skaggs <AvarianKnight>"
6
+ ],
7
+ "type": "module",
8
+ "version": "0.0.1",
9
+ "files": [
10
+ "./**/*.js",
11
+ "./**/*.d.ts"
12
+ ],
13
+ "sideEffects": false,
14
+ "exports": {
15
+ ".": "./index.js",
16
+ "./*": "./*"
17
+ }
18
+ }
@@ -0,0 +1,7 @@
1
+ import type { BaseInventory, InventoryItem } from "@common-types/Inventory";
2
+ import type { PMAPlayerWrapper } from "../class/PMAPlayerWrapper";
3
+ export type UsableItemCall = (ply: PMAPlayerWrapper, inventory: BaseInventory, item: InventoryItem) => void;
4
+ export type UsableItems = {
5
+ fn: UsableItemCall;
6
+ resource: string;
7
+ };
File without changes