@pma-network/fivem-server 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 +42 -0
- package/PMA.js +61 -0
- package/class/PMAPlayer.d.ts +26 -0
- package/class/PMAPlayer.js +64 -0
- package/decors/PMANetEvent.d.ts +10 -0
- package/decors/PMANetEvent.js +46 -0
- package/decors/RegisterUsableItems.d.ts +10 -0
- package/decors/RegisterUsableItems.js +33 -0
- package/index.d.ts +14 -0
- package/index.js +14 -0
- package/package.json +18 -0
- 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/shared-server/class/CommonPMAPlayer.js +135 -0
- 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 +12 -0
- package/types/Inventory.js +0 -0
package/PMA.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { ItemName } from "@pma-network/fivem-types/Inventory";
|
|
2
|
+
import type { PlayerUID } from "./shared-server/types/SharedTypes";
|
|
3
|
+
import { PMAPlayerWrapper } from "./class/PMAPlayer";
|
|
4
|
+
import type { UsableItemCall } from "./types/Inventory";
|
|
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<unknown | 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, consume_amount: number): 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/PMAPlayer";
|
|
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-framework"].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, consume_amount) {
|
|
20
|
+
const usable_item_wrapper = /* @__PURE__ */ __name((abstract_ply, item_name2, item, item_index) => {
|
|
21
|
+
const ply = PMAPlayerWrapper.from_raw(abstract_ply);
|
|
22
|
+
fn(ply, item_name2, item);
|
|
23
|
+
}, "usable_item_wrapper");
|
|
24
|
+
exports["pma-framework"].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-framework"].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-framework"].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
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { InventoryItem } from "@pma-network/fivem-types/Inventory";
|
|
2
|
+
import type { NotificationVariant, PMAPartialNotification } from "@pma-network/fivem-types/Notifications";
|
|
3
|
+
import { CommonPMAPlayer } from "../shared-server/class/CommonPMAPlayer";
|
|
4
|
+
import type { CommonAbstractPMAPlayer } from "../shared-server/types/CommonAbstractPMAPlayer";
|
|
5
|
+
import type { ItemName } from "../shared-server/types/SharedTypes";
|
|
6
|
+
export declare class PMAPlayerWrapper extends CommonPMAPlayer {
|
|
7
|
+
#private;
|
|
8
|
+
/**
|
|
9
|
+
* Creates the player from the ScRT msgpack'd class
|
|
10
|
+
*/
|
|
11
|
+
static from_raw(ply: CommonAbstractPMAPlayer): PMAPlayerWrapper;
|
|
12
|
+
/**
|
|
13
|
+
* Does basic checks that the player exists before lazy initializing the player
|
|
14
|
+
*/
|
|
15
|
+
static from_source(source: number): PMAPlayerWrapper | null;
|
|
16
|
+
/**
|
|
17
|
+
* Creates the player from the source without doing any validity checks
|
|
18
|
+
*/
|
|
19
|
+
static from_source_unchecked(source: number): CommonPMAPlayer;
|
|
20
|
+
constructor(source: number);
|
|
21
|
+
constructor(pma_player: CommonAbstractPMAPlayer);
|
|
22
|
+
send_notification(title?: string, description?: string, variant?: NotificationVariant, duration?: number): void;
|
|
23
|
+
send_notification_object(partial: PMAPartialNotification): void;
|
|
24
|
+
get_item(item_name: ItemName): InventoryItem | null;
|
|
25
|
+
add_item(item_name: ItemName, quantity: number): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { CommonPMAPlayer } from "../shared-server/class/CommonPMAPlayer";
|
|
4
|
+
class PMAPlayerWrapper extends CommonPMAPlayer {
|
|
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
|
+
/**
|
|
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
|
+
}
|
|
33
|
+
constructor(source) {
|
|
34
|
+
if (typeof source !== "number") {
|
|
35
|
+
const ply = source;
|
|
36
|
+
super(ply.source);
|
|
37
|
+
this.#pma_player = ply;
|
|
38
|
+
} else {
|
|
39
|
+
super(source);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
send_notification(title, description, variant = "default", duration = 5e3) {
|
|
43
|
+
const noti = {
|
|
44
|
+
body: description,
|
|
45
|
+
duration,
|
|
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_item(item_name) {
|
|
54
|
+
this.ensure_init();
|
|
55
|
+
return this.#pma_player.get_item(item_name);
|
|
56
|
+
}
|
|
57
|
+
add_item(item_name, quantity) {
|
|
58
|
+
this.ensure_init();
|
|
59
|
+
return this.#pma_player.add_item(item_name, quantity);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export {
|
|
63
|
+
PMAPlayerWrapper
|
|
64
|
+
};
|
|
@@ -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 OnPMANetEvent(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 OnPMANetEvent(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(OnPMANetEvent, "OnPMANetEvent");
|
|
44
|
+
export {
|
|
45
|
+
OnPMANetEvent
|
|
46
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { UsableItemCall } from "../types/Inventory";
|
|
2
|
+
import type { ItemName } from "../shared-server/types/SharedTypes";
|
|
3
|
+
/**
|
|
4
|
+
* Registers the {@link item_name} to be usable
|
|
5
|
+
*
|
|
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
|
|
9
|
+
*/
|
|
10
|
+
export declare function RegisterUsableItem(item_name: ItemName, consume_amount?: number): (originalMethod: UsableItemCall, context: ClassMethodDecoratorContext) => void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { PMA } from "../PMA";
|
|
4
|
+
function RegisterUsableItem(item_name, consume_amount = 0) {
|
|
5
|
+
return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
|
|
6
|
+
if (context.private) {
|
|
7
|
+
throw new Error("RegisterUsableItem does not work on private methods, please mark the method as public");
|
|
8
|
+
}
|
|
9
|
+
context.addInitializer(function() {
|
|
10
|
+
const t = this;
|
|
11
|
+
PMA.register_usable_item(
|
|
12
|
+
item_name,
|
|
13
|
+
(ply, ...args) => {
|
|
14
|
+
try {
|
|
15
|
+
originalMethod.call(t, ply, ...args);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.error("------- USABLE ITEM ERROR --------");
|
|
18
|
+
console.error(`Call for ${item_name} errored`);
|
|
19
|
+
console.error(`Caller: ${ply.Source}`);
|
|
20
|
+
console.error(`Data: ${JSON.stringify(args)}`);
|
|
21
|
+
console.error(`Error: ${e}`);
|
|
22
|
+
console.error("------- END USABLE ITEM ERROR --------");
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
consume_amount
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
}, "actualDecorator");
|
|
29
|
+
}
|
|
30
|
+
__name(RegisterUsableItem, "RegisterUsableItem");
|
|
31
|
+
export {
|
|
32
|
+
RegisterUsableItem
|
|
33
|
+
};
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./PMA";
|
|
2
|
+
export * from "./types/Inventory";
|
|
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";
|
|
13
|
+
export * from "./decors/RegisterUsableItems";
|
|
14
|
+
export * from "./class/PMAPlayer";
|
package/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./PMA";
|
|
2
|
+
export * from "./types/Inventory";
|
|
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";
|
|
13
|
+
export * from "./decors/RegisterUsableItems";
|
|
14
|
+
export * from "./class/PMAPlayer";
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pma-network/fivem-server",
|
|
3
|
+
"description": "Native wrappers and utilities for use with PMA FiveM Server.",
|
|
4
|
+
"contributors": [
|
|
5
|
+
"Dillon Skaggs <AvarianKnight>"
|
|
6
|
+
],
|
|
7
|
+
"type": "module",
|
|
8
|
+
"version": "0.0.11",
|
|
9
|
+
"files": [
|
|
10
|
+
"./**/*.js",
|
|
11
|
+
"./**/*.d.ts"
|
|
12
|
+
],
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"exports": {
|
|
15
|
+
".": "./index.js",
|
|
16
|
+
"./*": "./*"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -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
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PMAPlayerWrapper } from "../class/PMAPlayer";
|
|
2
|
+
import type { InventoryItem } from "@pma-network/fivem-types/Inventory";
|
|
3
|
+
/**
|
|
4
|
+
* @param ply the player to call the callback for
|
|
5
|
+
* @param itemName the item name that the callback will be fore
|
|
6
|
+
* @param consume_item the amount of the item to consume on the callback
|
|
7
|
+
*/
|
|
8
|
+
export type UsableItemCall = (ply: PMAPlayerWrapper, itemName: string, item: InventoryItem) => void;
|
|
9
|
+
export type UsableItems = {
|
|
10
|
+
fn: UsableItemCall;
|
|
11
|
+
resource: string;
|
|
12
|
+
};
|
|
File without changes
|