@pma-network/shared-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/CommonPMA.d.ts +31 -0
- package/CommonPMA.js +44 -0
- package/class/CommonPMAPlayer.d.ts +41 -0
- package/class/CommonPMAPlayer.js +135 -0
- package/index.d.ts +9 -2
- package/index.js +9 -2
- package/package.json +1 -1
- package/types/CommonAbstractPMAPlayer.d.ts +48 -0
- package/types/CommonAbstractPMAPlayer.js +10 -0
- package/types/CommonNotifications.d.ts +12 -0
- package/types/SharedTypes.d.ts +8 -0
- package/{CooldownTracker.d.ts → utils/CooldownTracker.d.ts} +1 -1
- package/utils/FrameworkName.d.ts +1 -0
- package/utils/FrameworkName.js +4 -0
- package/utils/GlobalOverrides.d.ts +3 -0
- package/utils/GlobalOverrides.js +11 -0
- package/utils/InfractionsWrapper.d.ts +0 -0
- package/utils/InfractionsWrapper.js +0 -0
- /package/{InfractionsWrapper.d.ts → types/CommonNotifications.js} +0 -0
- /package/{InfractionsWrapper.js → types/SharedTypes.js} +0 -0
- /package/{CooldownTracker.js → utils/CooldownTracker.js} +0 -0
package/CommonPMA.d.ts
ADDED
|
@@ -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
|
+
}
|
package/CommonPMA.js
ADDED
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { Player } from "@nativewrappers/server";
|
|
4
|
+
import { framework_name } from "../utils/FrameworkName";
|
|
5
|
+
import { pma_get_player_from_id } from "../utils/GlobalOverrides";
|
|
6
|
+
class CommonPMAPlayer extends Player {
|
|
7
|
+
static {
|
|
8
|
+
__name(this, "CommonPMAPlayer");
|
|
9
|
+
}
|
|
10
|
+
// This will get lazy-initialized whenever we actually call a function that needs it,
|
|
11
|
+
// this will make sure we don't pay the un-needed serialize cost if we're only using this for
|
|
12
|
+
// basic nativewrappers types
|
|
13
|
+
#pma_player;
|
|
14
|
+
/**
|
|
15
|
+
* Creates the player from the ScRT msgpack'd class
|
|
16
|
+
*/
|
|
17
|
+
static from_raw(ply) {
|
|
18
|
+
return new CommonPMAPlayer(ply);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Does basic checks that the player exists before lazy initializing the player
|
|
22
|
+
*/
|
|
23
|
+
static from_source(source) {
|
|
24
|
+
if (!DoesPlayerExist(source)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
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);
|
|
34
|
+
}
|
|
35
|
+
constructor(source) {
|
|
36
|
+
if (typeof source !== "number") {
|
|
37
|
+
const ply = source;
|
|
38
|
+
super(ply.source);
|
|
39
|
+
this.#pma_player = ply;
|
|
40
|
+
} else {
|
|
41
|
+
super(source);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// Ensure we initialize the player whenever we're doing something that needs it.
|
|
45
|
+
ensure_init() {
|
|
46
|
+
if (!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);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
send_notification(title, description, variant = "default", duration = 5e3) {
|
|
54
|
+
const noti = {
|
|
55
|
+
body: description,
|
|
56
|
+
duration,
|
|
57
|
+
variant
|
|
58
|
+
};
|
|
59
|
+
this.emit("pma:add_notifications", noti);
|
|
60
|
+
}
|
|
61
|
+
send_notification_object(partial) {
|
|
62
|
+
this.emit("pma:add_notification", partial);
|
|
63
|
+
}
|
|
64
|
+
get_sex() {
|
|
65
|
+
this.ensure_init();
|
|
66
|
+
return this.#pma_player.get_sex();
|
|
67
|
+
}
|
|
68
|
+
get_height() {
|
|
69
|
+
this.ensure_init();
|
|
70
|
+
return this.#pma_player.get_height();
|
|
71
|
+
}
|
|
72
|
+
get_dob() {
|
|
73
|
+
this.ensure_init();
|
|
74
|
+
return this.#pma_player.get_dob();
|
|
75
|
+
}
|
|
76
|
+
get_unique_id() {
|
|
77
|
+
this.ensure_init();
|
|
78
|
+
return this.#pma_player.get_unique_id();
|
|
79
|
+
}
|
|
80
|
+
get_call_sign() {
|
|
81
|
+
this.ensure_init();
|
|
82
|
+
return this.#pma_player.get_call_sign();
|
|
83
|
+
}
|
|
84
|
+
get_character_name() {
|
|
85
|
+
this.ensure_init();
|
|
86
|
+
return this.#pma_player.get_character_name();
|
|
87
|
+
}
|
|
88
|
+
get_log_name() {
|
|
89
|
+
this.ensure_init();
|
|
90
|
+
return this.#pma_player.get_character_name();
|
|
91
|
+
}
|
|
92
|
+
get_item(item_name) {
|
|
93
|
+
this.ensure_init();
|
|
94
|
+
return this.#pma_player.get_item(item_name);
|
|
95
|
+
}
|
|
96
|
+
add_item(item_name, quantity) {
|
|
97
|
+
this.ensure_init();
|
|
98
|
+
return this.#pma_player.add_item(item_name, quantity);
|
|
99
|
+
}
|
|
100
|
+
remove_item(item_name, quantity) {
|
|
101
|
+
this.ensure_init();
|
|
102
|
+
return this.#pma_player.remove_item(item_name, quantity);
|
|
103
|
+
}
|
|
104
|
+
has_enough_of_item(item_name, quantity) {
|
|
105
|
+
this.ensure_init();
|
|
106
|
+
return this.#pma_player.has_enough_of_item(item_name, quantity);
|
|
107
|
+
}
|
|
108
|
+
get_job() {
|
|
109
|
+
this.ensure_init();
|
|
110
|
+
return this.#pma_player.get_job();
|
|
111
|
+
}
|
|
112
|
+
set_job(job_name, rank) {
|
|
113
|
+
this.ensure_init();
|
|
114
|
+
return this.#pma_player.set_job(job_name, rank);
|
|
115
|
+
}
|
|
116
|
+
get_bank() {
|
|
117
|
+
this.ensure_init();
|
|
118
|
+
return this.#pma_player.get_bank();
|
|
119
|
+
}
|
|
120
|
+
add_to_bank(positive_amount) {
|
|
121
|
+
this.ensure_init();
|
|
122
|
+
return this.#pma_player.add_to_bank(positive_amount);
|
|
123
|
+
}
|
|
124
|
+
remove_from_bank(negative_amount) {
|
|
125
|
+
this.ensure_init();
|
|
126
|
+
return this.#pma_player.remove_from_bank(negative_amount);
|
|
127
|
+
}
|
|
128
|
+
save() {
|
|
129
|
+
this.ensure_init();
|
|
130
|
+
return this.#pma_player.save();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
export {
|
|
134
|
+
CommonPMAPlayer
|
|
135
|
+
};
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./CommonPMA";
|
|
2
|
+
export * from "./utils/CooldownTracker";
|
|
3
|
+
export * from "./utils/FrameworkName";
|
|
4
|
+
export * from "./utils/GlobalOverrides";
|
|
5
|
+
export * from "./utils/InfractionsWrapper";
|
|
6
|
+
export * from "./types/CommonAbstractPMAPlayer";
|
|
7
|
+
export * from "./types/CommonNotifications";
|
|
8
|
+
export * from "./types/SharedTypes";
|
|
9
|
+
export * from "./class/CommonPMAPlayer";
|
package/index.js
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./CommonPMA";
|
|
2
|
+
export * from "./utils/CooldownTracker";
|
|
3
|
+
export * from "./utils/FrameworkName";
|
|
4
|
+
export * from "./utils/GlobalOverrides";
|
|
5
|
+
export * from "./utils/InfractionsWrapper";
|
|
6
|
+
export * from "./types/CommonAbstractPMAPlayer";
|
|
7
|
+
export * from "./types/CommonNotifications";
|
|
8
|
+
export * from "./types/SharedTypes";
|
|
9
|
+
export * from "./class/CommonPMAPlayer";
|
package/package.json
CHANGED
|
@@ -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
|
+
};
|
|
@@ -2,7 +2,7 @@ type CooldownTrackerCallback = (src: number, details: string) => void;
|
|
|
2
2
|
export declare class CooldownTracker {
|
|
3
3
|
#private;
|
|
4
4
|
constructor(cooldown: number, cb: CooldownTrackerCallback);
|
|
5
|
-
player_dropped
|
|
5
|
+
private player_dropped;
|
|
6
6
|
try_add_cooldown(src: number, additional_details: string): boolean;
|
|
7
7
|
}
|
|
8
8
|
export {};
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|