@pma-network/redm-server 0.0.7 → 0.0.11
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 +3 -3
- package/PMA.js +1 -2
- package/class/AbstractPMAPlayer.d.ts +21 -0
- package/class/AbstractPMAPlayer.js +11 -0
- package/class/PMAPlayer.d.ts +12 -24
- package/class/PMAPlayer.js +10 -70
- package/decors/{PMAServerEvent.d.ts → PMANetEvent.d.ts} +1 -1
- package/decors/{PMAServerEvent.js → PMANetEvent.js} +3 -3
- package/decors/RegisterUsableItems.d.ts +5 -4
- package/decors/RegisterUsableItems.js +1 -2
- package/index.d.ts +12 -4
- package/index.js +12 -4
- package/package.json +1 -1
- package/shared-server/CommonPMA.d.ts +31 -0
- package/shared-server/CommonPMA.js +44 -0
- package/shared-server/class/CommonPMAPlayer.d.ts +41 -0
- package/{class/PMAPlayerWrapper.js → shared-server/class/CommonPMAPlayer.js} +21 -10
- package/shared-server/types/CommonAbstractPMAPlayer.d.ts +48 -0
- package/shared-server/types/CommonAbstractPMAPlayer.js +10 -0
- package/shared-server/types/CommonNotifications.d.ts +12 -0
- package/shared-server/types/CommonNotifications.js +0 -0
- package/shared-server/types/SharedTypes.d.ts +8 -0
- package/shared-server/types/SharedTypes.js +0 -0
- package/shared-server/utils/CooldownTracker.d.ts +8 -0
- package/shared-server/utils/CooldownTracker.js +35 -0
- package/shared-server/utils/FrameworkName.d.ts +1 -0
- package/shared-server/utils/FrameworkName.js +4 -0
- package/shared-server/utils/GlobalOverrides.d.ts +3 -0
- package/shared-server/utils/GlobalOverrides.js +11 -0
- package/shared-server/utils/InfractionsWrapper.d.ts +0 -0
- package/shared-server/utils/InfractionsWrapper.js +0 -0
- package/types/Inventory.d.ts +3 -3
- package/class/PMAPlayerWrapper.d.ts +0 -37
- package/decors/PMANetServerEvent.d.ts +0 -10
- package/decors/PMANetServerEvent.js +0 -46
package/PMA.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ItemData, ItemName } from "@
|
|
2
|
-
import type { PlayerUID } from "@
|
|
3
|
-
import { PMAPlayerWrapper } from "./class/
|
|
1
|
+
import type { ItemData, ItemName } from "@pma-network/redm-types/Inventory";
|
|
2
|
+
import type { PlayerUID } from "@pma-network/redm-types/PMAPlayer";
|
|
3
|
+
import { PMAPlayerWrapper } from "./class/PMAPlayer";
|
|
4
4
|
import type { UsableItemCall } from "./types/Inventory";
|
|
5
5
|
/**
|
|
6
6
|
* A static class that's used for invoking framework types
|
package/PMA.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import {
|
|
4
|
-
import { PMAPlayerWrapper } from "./class/PMAPlayerWrapper";
|
|
3
|
+
import { PMAPlayerWrapper } from "./class/PMAPlayer";
|
|
5
4
|
class PMA {
|
|
6
5
|
static {
|
|
7
6
|
__name(this, "PMA");
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ItemName, OptionalItem } from "@pma-network/redm-types/Inventory";
|
|
2
|
+
import { CommonAbstractPMAPlayer } from "../shared-server/types/CommonAbstractPMAPlayer";
|
|
3
|
+
export declare abstract class AbstractPMAPlayer extends CommonAbstractPMAPlayer {
|
|
4
|
+
abstract get_item(item_name: ItemName): OptionalItem;
|
|
5
|
+
/**
|
|
6
|
+
* Adds the item with {@param item_name} to the players next free slot
|
|
7
|
+
* @throws This will throw an error if {@param item_name} is invalid, or if {@param quantity} is negative
|
|
8
|
+
* @returns the {@link InventoryItem} that was created, or undefined if there wasn't a free slot to put the item into.
|
|
9
|
+
*/
|
|
10
|
+
abstract add_item(item_name: ItemName, quantity: number): OptionalItem;
|
|
11
|
+
/**
|
|
12
|
+
* Removes the item with {@param item_name} from the players inventory
|
|
13
|
+
* @throws This will throw an error if there wasn't enough {@param quantity} in the players inventory, you should use use has_enough_of_item to check before calling
|
|
14
|
+
*/
|
|
15
|
+
abstract remove_item(item_name: ItemName, quantity: number): void;
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the player has enough of {@param item_name}
|
|
18
|
+
* @returns `true` if they had enough {@param quantity}, `false` otherwise
|
|
19
|
+
*/
|
|
20
|
+
abstract has_enough_of_item(item_name: ItemName, quantity: number): boolean;
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { CommonAbstractPMAPlayer } from "../shared-server/types/CommonAbstractPMAPlayer";
|
|
4
|
+
class AbstractPMAPlayer extends CommonAbstractPMAPlayer {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "AbstractPMAPlayer");
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
AbstractPMAPlayer
|
|
11
|
+
};
|
package/class/PMAPlayer.d.ts
CHANGED
|
@@ -1,37 +1,25 @@
|
|
|
1
|
-
import type { ItemName, OptionalItem } from "@
|
|
2
|
-
import type { NotificationVariant, PMAPartialNotification } from "@
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
export declare class PMAPlayerWrapper extends
|
|
1
|
+
import type { ItemName, OptionalItem } from "@pma-network/redm-types/Inventory";
|
|
2
|
+
import type { NotificationVariant, PMAPartialNotification } from "@pma-network/redm-types/Notifications";
|
|
3
|
+
import { CommonPMAPlayer } from "../shared-server/class/CommonPMAPlayer";
|
|
4
|
+
import type { CommonAbstractPMAPlayer } from "../shared-server/types/CommonAbstractPMAPlayer";
|
|
5
|
+
export declare class PMAPlayerWrapper extends CommonPMAPlayer {
|
|
6
6
|
#private;
|
|
7
7
|
/**
|
|
8
8
|
* Creates the player from the ScRT msgpack'd class
|
|
9
9
|
*/
|
|
10
|
-
static from_raw(ply:
|
|
10
|
+
static from_raw(ply: CommonAbstractPMAPlayer): PMAPlayerWrapper;
|
|
11
11
|
/**
|
|
12
12
|
* Does basic checks that the player exists before lazy initializing the player
|
|
13
13
|
*/
|
|
14
14
|
static from_source(source: number): PMAPlayerWrapper | null;
|
|
15
|
+
/**
|
|
16
|
+
* Creates the player from the source without doing any validity checks
|
|
17
|
+
*/
|
|
18
|
+
static from_source_unchecked(source: number): CommonPMAPlayer;
|
|
15
19
|
constructor(source: number);
|
|
16
|
-
constructor(pma_player:
|
|
17
|
-
|
|
18
|
-
send_notification(title?: string, description?: string, variant?: NotificationVariant): void;
|
|
20
|
+
constructor(pma_player: CommonAbstractPMAPlayer);
|
|
21
|
+
send_notification(title?: string, description?: string, variant?: NotificationVariant, duration?: number): void;
|
|
19
22
|
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
23
|
get_item(item_name: ItemName): OptionalItem;
|
|
28
24
|
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
25
|
}
|
package/class/PMAPlayer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import {
|
|
4
|
-
class PMAPlayerWrapper extends
|
|
3
|
+
import { CommonPMAPlayer } from "../shared-server/class/CommonPMAPlayer";
|
|
4
|
+
class PMAPlayerWrapper extends CommonPMAPlayer {
|
|
5
5
|
static {
|
|
6
6
|
__name(this, "PMAPlayerWrapper");
|
|
7
7
|
}
|
|
@@ -24,6 +24,12 @@ class PMAPlayerWrapper extends Player {
|
|
|
24
24
|
}
|
|
25
25
|
return new PMAPlayerWrapper(source);
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Creates the player from the source without doing any validity checks
|
|
29
|
+
*/
|
|
30
|
+
static from_source_unchecked(source) {
|
|
31
|
+
return new CommonPMAPlayer(source);
|
|
32
|
+
}
|
|
27
33
|
constructor(source) {
|
|
28
34
|
if (typeof source !== "number") {
|
|
29
35
|
const ply = source;
|
|
@@ -33,16 +39,10 @@ class PMAPlayerWrapper extends Player {
|
|
|
33
39
|
super(source);
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
|
-
|
|
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") {
|
|
42
|
+
send_notification(title, description, variant = "default", duration = 5e3) {
|
|
43
43
|
const noti = {
|
|
44
|
-
title,
|
|
45
44
|
body: description,
|
|
45
|
+
duration,
|
|
46
46
|
variant
|
|
47
47
|
};
|
|
48
48
|
this.emit("pma:add_notifications", noti);
|
|
@@ -50,34 +50,6 @@ class PMAPlayerWrapper extends Player {
|
|
|
50
50
|
send_notification_object(partial) {
|
|
51
51
|
this.emit("pma:add_notification", partial);
|
|
52
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
53
|
get_item(item_name) {
|
|
82
54
|
this.ensure_init();
|
|
83
55
|
return this.#pma_player.get_item(item_name);
|
|
@@ -86,38 +58,6 @@ class PMAPlayerWrapper extends Player {
|
|
|
86
58
|
this.ensure_init();
|
|
87
59
|
return this.#pma_player.add_item(item_name, quantity);
|
|
88
60
|
}
|
|
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
61
|
}
|
|
122
62
|
export {
|
|
123
63
|
PMAPlayerWrapper
|
|
@@ -6,5 +6,5 @@ type PMAServerEventType = (player: PMAPlayerWrapper, ...args: any[]) => Promise<
|
|
|
6
6
|
* @param eventName the event to bind this net event to
|
|
7
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
8
|
*/
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function OnPMANetEvent(eventName: string): (originalMethod: PMAServerEventType, context: ClassMethodDecoratorContext) => void;
|
|
10
10
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import { PMAPlayerWrapper } from "../class/PMAPlayer";
|
|
4
|
-
function
|
|
4
|
+
function OnPMANetEvent(eventName) {
|
|
5
5
|
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
6
6
|
if (context.private) {
|
|
7
7
|
throw new Error("NetEvent does not work on private methods, please mark the method as public");
|
|
@@ -40,7 +40,7 @@ function PMAServerEvent(eventName) {
|
|
|
40
40
|
});
|
|
41
41
|
}, "actualDecorator");
|
|
42
42
|
}
|
|
43
|
-
__name(
|
|
43
|
+
__name(OnPMANetEvent, "OnPMANetEvent");
|
|
44
44
|
export {
|
|
45
|
-
|
|
45
|
+
OnPMANetEvent
|
|
46
46
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { ItemName } from "@
|
|
1
|
+
import type { ItemName } from "@pma-network/redm-types/Inventory";
|
|
2
2
|
import type { UsableItemCall } from "../types/Inventory";
|
|
3
3
|
/**
|
|
4
|
-
* Registers the
|
|
4
|
+
* Registers the {@link item_name} to be usable
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* NOTE: On RedM the item needs to have its usable flag for this to work.
|
|
7
|
+
*
|
|
8
|
+
* @param item_name The item to make usable
|
|
8
9
|
*/
|
|
9
10
|
export declare function RegisterUsableItem(item_name: ItemName): (originalMethod: UsableItemCall, context: ClassMethodDecoratorContext) => void;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import { PMA } from "../PMA";
|
|
4
|
-
import { PMAPlayerWrapper } from "../class/PMAPlayer";
|
|
5
4
|
function RegisterUsableItem(item_name) {
|
|
6
5
|
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
7
6
|
if (context.private) {
|
|
8
|
-
throw new Error("
|
|
7
|
+
throw new Error("RegisterUsableItem does not work on private methods, please mark the method as public");
|
|
9
8
|
}
|
|
10
9
|
context.addInitializer(function() {
|
|
11
10
|
const t = this;
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
export * from "./PMA";
|
|
2
2
|
export * from "./types/Inventory";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
3
|
+
export * from "./shared-server/CommonPMA";
|
|
4
|
+
export * from "./shared-server/utils/CooldownTracker";
|
|
5
|
+
export * from "./shared-server/utils/FrameworkName";
|
|
6
|
+
export * from "./shared-server/utils/GlobalOverrides";
|
|
7
|
+
export * from "./shared-server/utils/InfractionsWrapper";
|
|
8
|
+
export * from "./shared-server/types/CommonAbstractPMAPlayer";
|
|
9
|
+
export * from "./shared-server/types/CommonNotifications";
|
|
10
|
+
export * from "./shared-server/types/SharedTypes";
|
|
11
|
+
export * from "./shared-server/class/CommonPMAPlayer";
|
|
12
|
+
export * from "./decors/PMANetEvent";
|
|
5
13
|
export * from "./decors/RegisterUsableItems";
|
|
6
|
-
export * from "./class/
|
|
7
|
-
export * from "./class/
|
|
14
|
+
export * from "./class/AbstractPMAPlayer";
|
|
15
|
+
export * from "./class/PMAPlayer";
|
package/index.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
export * from "./PMA";
|
|
2
2
|
export * from "./types/Inventory";
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
3
|
+
export * from "./shared-server/CommonPMA";
|
|
4
|
+
export * from "./shared-server/utils/CooldownTracker";
|
|
5
|
+
export * from "./shared-server/utils/FrameworkName";
|
|
6
|
+
export * from "./shared-server/utils/GlobalOverrides";
|
|
7
|
+
export * from "./shared-server/utils/InfractionsWrapper";
|
|
8
|
+
export * from "./shared-server/types/CommonAbstractPMAPlayer";
|
|
9
|
+
export * from "./shared-server/types/CommonNotifications";
|
|
10
|
+
export * from "./shared-server/types/SharedTypes";
|
|
11
|
+
export * from "./shared-server/class/CommonPMAPlayer";
|
|
12
|
+
export * from "./decors/PMANetEvent";
|
|
5
13
|
export * from "./decors/RegisterUsableItems";
|
|
6
|
-
export * from "./class/
|
|
7
|
-
export * from "./class/
|
|
14
|
+
export * from "./class/AbstractPMAPlayer";
|
|
15
|
+
export * from "./class/PMAPlayer";
|
package/package.json
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CommonPMAPlayer } from "./class/CommonPMAPlayer";
|
|
2
|
+
import type { PlayerUID } from "./types/SharedTypes";
|
|
3
|
+
/**
|
|
4
|
+
* A wraper around common functions that canbe used both in FiveM and RedM
|
|
5
|
+
*/
|
|
6
|
+
export declare class CommonPMA {
|
|
7
|
+
/**
|
|
8
|
+
* Gets the player from the specified source
|
|
9
|
+
* @note the PMAPlayer is lazy initialized so we don't do un-needed scrt
|
|
10
|
+
* calls, this means that we *can* possibly end up in a state where the player
|
|
11
|
+
* isn't initialized, this won't break anything though.
|
|
12
|
+
* @returns the PMAPlayer wrapper, or `null` if the player doesn't exist
|
|
13
|
+
*/
|
|
14
|
+
static from_source(source: number): CommonPMAPlayer | null;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the player from the specified UID
|
|
17
|
+
* @returns the PMAPlayer wrapper, or `null` if there wasn't a player
|
|
18
|
+
*/
|
|
19
|
+
static from_uid(uid: PlayerUID): CommonPMAPlayer | null;
|
|
20
|
+
/**
|
|
21
|
+
* Gets all of the players that habe the specified job(s), and the specified {@param job_rank} if specified.
|
|
22
|
+
*/
|
|
23
|
+
static get_players_with_job(job_names: string | string[], job_rank?: number): CommonPMAPlayer[];
|
|
24
|
+
/**
|
|
25
|
+
* Generic logging
|
|
26
|
+
* TODO: Setup a clickhouse wrapper
|
|
27
|
+
*/
|
|
28
|
+
static log(log_message: string, additional_data?: {
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { CommonPMAPlayer } from "./class/CommonPMAPlayer";
|
|
4
|
+
import { framework_name } from "./utils/FrameworkName";
|
|
5
|
+
class CommonPMA {
|
|
6
|
+
static {
|
|
7
|
+
__name(this, "CommonPMA");
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Gets the player from the specified source
|
|
11
|
+
* @note the PMAPlayer is lazy initialized so we don't do un-needed scrt
|
|
12
|
+
* calls, this means that we *can* possibly end up in a state where the player
|
|
13
|
+
* isn't initialized, this won't break anything though.
|
|
14
|
+
* @returns the PMAPlayer wrapper, or `null` if the player doesn't exist
|
|
15
|
+
*/
|
|
16
|
+
static from_source(source) {
|
|
17
|
+
return CommonPMAPlayer.from_source(source);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Gets the player from the specified UID
|
|
21
|
+
* @returns the PMAPlayer wrapper, or `null` if there wasn't a player
|
|
22
|
+
*/
|
|
23
|
+
static from_uid(uid) {
|
|
24
|
+
const data = exports[framework_name].from_uid(uid);
|
|
25
|
+
return data ? CommonPMAPlayer.from_raw(data) : null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Gets all of the players that habe the specified job(s), and the specified {@param job_rank} if specified.
|
|
29
|
+
*/
|
|
30
|
+
static get_players_with_job(job_names, job_rank) {
|
|
31
|
+
const players = exports[framework_name].get_players_with_job(job_names, job_rank);
|
|
32
|
+
return players.map((v) => CommonPMAPlayer.from_raw(v));
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generic logging
|
|
36
|
+
* TODO: Setup a clickhouse wrapper
|
|
37
|
+
*/
|
|
38
|
+
static log(log_message, additional_data) {
|
|
39
|
+
console.log(log_message, additional_data);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
CommonPMA
|
|
44
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Player } from "@nativewrappers/server";
|
|
2
|
+
import type { CommonAbstractPMAPlayer } from "../types/CommonAbstractPMAPlayer";
|
|
3
|
+
import type { CommonNotificationVariant, CommonPMAPartialNotification } from "../types/CommonNotifications";
|
|
4
|
+
import type { CallSign, ItemName, PlayerJob, PlayerUID } from "../types/SharedTypes";
|
|
5
|
+
export declare class CommonPMAPlayer extends Player implements CommonAbstractPMAPlayer {
|
|
6
|
+
#private;
|
|
7
|
+
/**
|
|
8
|
+
* Creates the player from the ScRT msgpack'd class
|
|
9
|
+
*/
|
|
10
|
+
static from_raw(ply: CommonAbstractPMAPlayer): CommonPMAPlayer;
|
|
11
|
+
/**
|
|
12
|
+
* Does basic checks that the player exists before lazy initializing the player
|
|
13
|
+
*/
|
|
14
|
+
static from_source(source: number): CommonPMAPlayer | null;
|
|
15
|
+
/**
|
|
16
|
+
* Creates the player from the source without doing any validity checks
|
|
17
|
+
*/
|
|
18
|
+
static from_source_unchecked(source: number): CommonPMAPlayer;
|
|
19
|
+
constructor(source: number);
|
|
20
|
+
constructor(pma_player: CommonAbstractPMAPlayer);
|
|
21
|
+
ensure_init(): void;
|
|
22
|
+
send_notification(title?: string, description?: string, variant?: CommonNotificationVariant, duration?: number): void;
|
|
23
|
+
send_notification_object(partial: CommonPMAPartialNotification): void;
|
|
24
|
+
get_sex(): number;
|
|
25
|
+
get_height(): number;
|
|
26
|
+
get_dob(): string;
|
|
27
|
+
get_unique_id(): PlayerUID;
|
|
28
|
+
get_call_sign(): CallSign;
|
|
29
|
+
get_character_name(): string;
|
|
30
|
+
get_log_name(): string;
|
|
31
|
+
get_item(item_name: ItemName): unknown;
|
|
32
|
+
add_item(item_name: ItemName, quantity: number): unknown;
|
|
33
|
+
remove_item(item_name: ItemName, quantity: number): void;
|
|
34
|
+
has_enough_of_item(item_name: ItemName, quantity: number): boolean;
|
|
35
|
+
get_job(): PlayerJob;
|
|
36
|
+
set_job(job_name: string, rank: number): void;
|
|
37
|
+
get_bank(): number;
|
|
38
|
+
add_to_bank(positive_amount: number): void;
|
|
39
|
+
remove_from_bank(negative_amount: number): void;
|
|
40
|
+
save(): Promise<void>;
|
|
41
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import { Player } from "@nativewrappers/server";
|
|
4
|
-
|
|
4
|
+
import { framework_name } from "../utils/FrameworkName";
|
|
5
|
+
import { pma_get_player_from_id } from "../utils/GlobalOverrides";
|
|
6
|
+
class CommonPMAPlayer extends Player {
|
|
5
7
|
static {
|
|
6
|
-
__name(this, "
|
|
8
|
+
__name(this, "CommonPMAPlayer");
|
|
7
9
|
}
|
|
8
10
|
// This will get lazy-initialized whenever we actually call a function that needs it,
|
|
9
11
|
// this will make sure we don't pay the un-needed serialize cost if we're only using this for
|
|
@@ -13,7 +15,7 @@ class PMAPlayerWrapper extends Player {
|
|
|
13
15
|
* Creates the player from the ScRT msgpack'd class
|
|
14
16
|
*/
|
|
15
17
|
static from_raw(ply) {
|
|
16
|
-
return new
|
|
18
|
+
return new CommonPMAPlayer(ply);
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
21
|
* Does basic checks that the player exists before lazy initializing the player
|
|
@@ -22,7 +24,13 @@ class PMAPlayerWrapper extends Player {
|
|
|
22
24
|
if (!DoesPlayerExist(source)) {
|
|
23
25
|
return null;
|
|
24
26
|
}
|
|
25
|
-
return new
|
|
27
|
+
return new CommonPMAPlayer(source);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Creates the player from the source without doing any validity checks
|
|
31
|
+
*/
|
|
32
|
+
static from_source_unchecked(source) {
|
|
33
|
+
return new CommonPMAPlayer(source);
|
|
26
34
|
}
|
|
27
35
|
constructor(source) {
|
|
28
36
|
if (typeof source !== "number") {
|
|
@@ -36,18 +44,21 @@ class PMAPlayerWrapper extends Player {
|
|
|
36
44
|
// Ensure we initialize the player whenever we're doing something that needs it.
|
|
37
45
|
ensure_init() {
|
|
38
46
|
if (!this.#pma_player) {
|
|
39
|
-
this.#pma_player =
|
|
47
|
+
this.#pma_player = globalThis.pma_get_player_from_id ? (
|
|
48
|
+
// @ts-ignore: we override this in GlobalOverrides
|
|
49
|
+
globalThis.pma_get_player_from_id(this.Source)
|
|
50
|
+
) : pma_get_player_from_id(this.Source);
|
|
40
51
|
}
|
|
41
52
|
}
|
|
42
|
-
|
|
53
|
+
send_notification(title, description, variant = "default", duration = 5e3) {
|
|
43
54
|
const noti = {
|
|
44
|
-
title,
|
|
45
55
|
body: description,
|
|
56
|
+
duration,
|
|
46
57
|
variant
|
|
47
58
|
};
|
|
48
59
|
this.emit("pma:add_notifications", noti);
|
|
49
60
|
}
|
|
50
|
-
|
|
61
|
+
send_notification_object(partial) {
|
|
51
62
|
this.emit("pma:add_notification", partial);
|
|
52
63
|
}
|
|
53
64
|
get_sex() {
|
|
@@ -76,7 +87,7 @@ class PMAPlayerWrapper extends Player {
|
|
|
76
87
|
}
|
|
77
88
|
get_log_name() {
|
|
78
89
|
this.ensure_init();
|
|
79
|
-
return this.#pma_player.
|
|
90
|
+
return this.#pma_player.get_character_name();
|
|
80
91
|
}
|
|
81
92
|
get_item(item_name) {
|
|
82
93
|
this.ensure_init();
|
|
@@ -120,5 +131,5 @@ class PMAPlayerWrapper extends Player {
|
|
|
120
131
|
}
|
|
121
132
|
}
|
|
122
133
|
export {
|
|
123
|
-
|
|
134
|
+
CommonPMAPlayer
|
|
124
135
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { CallSign, ItemName, PlayerJob, PlayerUID } from "./SharedTypes";
|
|
2
|
+
export declare abstract class CommonAbstractPMAPlayer {
|
|
3
|
+
abstract get_sex(): number;
|
|
4
|
+
abstract get_height(): number;
|
|
5
|
+
abstract get_dob(): string;
|
|
6
|
+
abstract get_unique_id(): PlayerUID;
|
|
7
|
+
abstract get_call_sign(): CallSign;
|
|
8
|
+
abstract get_character_name(): string;
|
|
9
|
+
abstract get_log_name(): string;
|
|
10
|
+
abstract get_item(item_name: ItemName): unknown;
|
|
11
|
+
/**
|
|
12
|
+
* Adds the item with {@param item_name} to the players next free slot
|
|
13
|
+
*
|
|
14
|
+
* On RedM this will return `InventoryItem` on FiveM this will return `void`
|
|
15
|
+
*
|
|
16
|
+
* @throws This will throw an error if {@param item_name} is invalid, or if {@param quantity} is negative
|
|
17
|
+
* @returns the {@link InventoryItem} that was created, or undefined if there wasn't a free slot to put the item into.
|
|
18
|
+
*/
|
|
19
|
+
abstract add_item(item_name: ItemName, quantity: number): unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Removes the item with {@param item_name} from the players inventory
|
|
22
|
+
* @throws This will throw an error if there wasn't enough {@param quantity} in the players inventory, you should use use has_enough_of_item to check before calling
|
|
23
|
+
*/
|
|
24
|
+
abstract remove_item(item_name: ItemName, quantity: number): void;
|
|
25
|
+
/**
|
|
26
|
+
* Checks if the player has enough of {@param item_name}
|
|
27
|
+
* @returns `true` if they had enough {@param quantity}, `false` otherwise
|
|
28
|
+
*/
|
|
29
|
+
abstract has_enough_of_item(item_name: ItemName, quantity: number): boolean;
|
|
30
|
+
abstract get_job(): PlayerJob;
|
|
31
|
+
/**
|
|
32
|
+
* Sets the players job to the specified {@param job_name} and {@param rank}
|
|
33
|
+
* @throws This will throw if the players job is invalid
|
|
34
|
+
*/
|
|
35
|
+
abstract set_job(job_name: string, rank: number): void;
|
|
36
|
+
abstract get_bank(): number;
|
|
37
|
+
/**
|
|
38
|
+
* Adds the {@param positive_amount} to the players bank.
|
|
39
|
+
* @throws if {@param positive_amount} is negative this will throw an error.
|
|
40
|
+
*/
|
|
41
|
+
abstract add_to_bank(positive_amount: number): void;
|
|
42
|
+
/**
|
|
43
|
+
* Removes the {@param negative_amount} to the players bank.
|
|
44
|
+
* @throws if {@param negative_amount} is positive this will throw an error.
|
|
45
|
+
*/
|
|
46
|
+
abstract remove_from_bank(negative_amount: number): void;
|
|
47
|
+
abstract save(): Promise<void>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
class CommonAbstractPMAPlayer {
|
|
4
|
+
static {
|
|
5
|
+
__name(this, "CommonAbstractPMAPlayer");
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
CommonAbstractPMAPlayer
|
|
10
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type Position = "top-left" | "top-center" | "top-right" | "middle-left" | "middle" | "middle-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
2
|
+
export type CommonNotificationVariant = "default" | "error" | "success";
|
|
3
|
+
export type CommonPMAPartialNotification = Omit<CommonPMANotification, "id">;
|
|
4
|
+
export type CommonPMANotification = {
|
|
5
|
+
id: number;
|
|
6
|
+
title?: string;
|
|
7
|
+
body?: string;
|
|
8
|
+
variant: CommonNotificationVariant;
|
|
9
|
+
duration?: number;
|
|
10
|
+
position?: Position;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
};
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type CooldownTrackerCallback = (src: number, details: string) => void;
|
|
2
|
+
export declare class CooldownTracker {
|
|
3
|
+
#private;
|
|
4
|
+
constructor(cooldown: number, cb: CooldownTrackerCallback);
|
|
5
|
+
private player_dropped;
|
|
6
|
+
try_add_cooldown(src: number, additional_details: string): boolean;
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { Event } from "@nativewrappers/server";
|
|
4
|
+
class CooldownTracker {
|
|
5
|
+
static {
|
|
6
|
+
__name(this, "CooldownTracker");
|
|
7
|
+
}
|
|
8
|
+
#cooldown_map = /* @__PURE__ */ new Map();
|
|
9
|
+
#cooldown;
|
|
10
|
+
#cb;
|
|
11
|
+
constructor(cooldown, cb) {
|
|
12
|
+
this.#cooldown = cooldown;
|
|
13
|
+
this.#cb = cb;
|
|
14
|
+
}
|
|
15
|
+
@Event("playerDropped")
|
|
16
|
+
player_dropped() {
|
|
17
|
+
this.#cooldown_map.delete(source);
|
|
18
|
+
}
|
|
19
|
+
/*
|
|
20
|
+
* @returns This returns `true` if it was successful in adding the player, or `false` the user already existed on the list
|
|
21
|
+
*/
|
|
22
|
+
try_add_cooldown(src, additional_details) {
|
|
23
|
+
const gt = GetGameTimer();
|
|
24
|
+
const time = this.#cooldown_map.get(src);
|
|
25
|
+
if (!time || time < gt) {
|
|
26
|
+
this.#cooldown_map.set(src, gt + this.#cooldown);
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
this.#cb(src, additional_details);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
CooldownTracker
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const framework_name: string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { framework_name } from "./FrameworkName";
|
|
4
|
+
function pma_get_player_from_id(source) {
|
|
5
|
+
return exports[framework_name].from_source(source);
|
|
6
|
+
}
|
|
7
|
+
__name(pma_get_player_from_id, "pma_get_player_from_id");
|
|
8
|
+
globalThis.pma_get_player_from_id = pma_get_player_from_id;
|
|
9
|
+
export {
|
|
10
|
+
pma_get_player_from_id
|
|
11
|
+
};
|
|
File without changes
|
|
File without changes
|
package/types/Inventory.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { BaseInventory, InventoryItem } from "@
|
|
2
|
-
import type { AbstractPMAPlayer } from "
|
|
3
|
-
import type { PMAPlayerWrapper } from "../class/
|
|
1
|
+
import type { BaseInventory, InventoryItem } from "@pma-network/redm-types/Inventory";
|
|
2
|
+
import type { AbstractPMAPlayer } from "../class/AbstractPMAPlayer";
|
|
3
|
+
import type { PMAPlayerWrapper } from "../class/PMAPlayer";
|
|
4
4
|
export type UsableItemCall = (ply: PMAPlayerWrapper, inventory: BaseInventory, item: InventoryItem) => void;
|
|
5
5
|
export type UsableItemCallShared = (ply: AbstractPMAPlayer, inventory: BaseInventory, item: InventoryItem) => void;
|
|
6
6
|
export type UsableItems = {
|
|
@@ -1,37 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
};
|