@pma-network/shared-server 0.0.8 → 0.0.12

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.
@@ -1,8 +1,7 @@
1
1
  import { Player } from "@nativewrappers/server";
2
- import type { ItemName } from "@redm-types/Inventory";
3
- import type { NotificationVariant, PMAPartialNotification } from "@redm-types/Notifications";
4
2
  import type { CommonAbstractPMAPlayer } from "../types/CommonAbstractPMAPlayer";
5
- import type { CallSign, PlayerJob, PlayerUID } from "../types/SharedTypes";
3
+ import type { CommonNotificationVariant, CommonPMAPartialNotification } from "../types/CommonNotifications";
4
+ import type { CallSign, ItemName, PlayerJob, PlayerUID } from "../types/SharedTypes";
6
5
  export declare class CommonPMAPlayer extends Player implements CommonAbstractPMAPlayer {
7
6
  #private;
8
7
  /**
@@ -20,8 +19,9 @@ export declare class CommonPMAPlayer extends Player implements CommonAbstractPMA
20
19
  constructor(source: number);
21
20
  constructor(pma_player: CommonAbstractPMAPlayer);
22
21
  ensure_init(): void;
23
- send_notification(title?: string, description?: string, variant?: NotificationVariant, duration?: number): void;
24
- send_notification_object(partial: PMAPartialNotification): void;
22
+ is_player_valid(): boolean;
23
+ send_notification(title?: string, description?: string, variant?: CommonNotificationVariant, duration?: number): void;
24
+ send_notification_object(partial: CommonPMAPartialNotification): void;
25
25
  get_sex(): number;
26
26
  get_height(): number;
27
27
  get_dob(): string;
@@ -2,6 +2,7 @@ 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";
5
6
  class CommonPMAPlayer extends Player {
6
7
  static {
7
8
  __name(this, "CommonPMAPlayer");
@@ -9,7 +10,7 @@ class CommonPMAPlayer extends Player {
9
10
  // This will get lazy-initialized whenever we actually call a function that needs it,
10
11
  // this will make sure we don't pay the un-needed serialize cost if we're only using this for
11
12
  // basic nativewrappers types
12
- #pma_player;
13
+ #pma_player = null;
13
14
  /**
14
15
  * Creates the player from the ScRT msgpack'd class
15
16
  */
@@ -43,9 +44,20 @@ class CommonPMAPlayer extends Player {
43
44
  // Ensure we initialize the player whenever we're doing something that needs it.
44
45
  ensure_init() {
45
46
  if (!this.#pma_player) {
46
- this.#pma_player = exports[framework_name].from_source(this.Source);
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);
47
51
  }
48
52
  }
53
+ /*
54
+ * This will initialize the player and check that the player exists
55
+ * @returns `true` if the player is loaded in the framework or `false` otherwise
56
+ */
57
+ is_player_valid() {
58
+ this.ensure_init();
59
+ return this.#pma_player !== null;
60
+ }
49
61
  send_notification(title, description, variant = "default", duration = 5e3) {
50
62
  const noti = {
51
63
  body: description,
package/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from "./CommonPMA";
2
2
  export * from "./utils/CooldownTracker";
3
3
  export * from "./utils/FrameworkName";
4
+ export * from "./utils/GlobalOverrides";
4
5
  export * from "./utils/InfractionsWrapper";
5
6
  export * from "./types/CommonAbstractPMAPlayer";
7
+ export * from "./types/CommonNotifications";
6
8
  export * from "./types/SharedTypes";
7
9
  export * from "./class/CommonPMAPlayer";
package/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from "./CommonPMA";
2
2
  export * from "./utils/CooldownTracker";
3
3
  export * from "./utils/FrameworkName";
4
+ export * from "./utils/GlobalOverrides";
4
5
  export * from "./utils/InfractionsWrapper";
5
6
  export * from "./types/CommonAbstractPMAPlayer";
7
+ export * from "./types/CommonNotifications";
6
8
  export * from "./types/SharedTypes";
7
9
  export * from "./class/CommonPMAPlayer";
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Dillon Skaggs <AvarianKnight>"
6
6
  ],
7
7
  "type": "module",
8
- "version": "0.0.8",
8
+ "version": "0.0.12",
9
9
  "files": [
10
10
  "./**/*.js",
11
11
  "./**/*.d.ts"
@@ -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
@@ -0,0 +1,3 @@
1
+ import type { CommonPMAPlayer } from "../class/CommonPMAPlayer";
2
+ import type { Source } from "../types/SharedTypes";
3
+ export declare function pma_get_player_from_id(source: Source): CommonPMAPlayer;
@@ -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
+ };