@nativewrappers/server 0.0.165 → 0.0.167

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.
@@ -0,0 +1,13 @@
1
+ import { Player } from "./entities/Player";
2
+ export type PlayerMap = Map<number, Player>;
3
+ /**
4
+ * A static helper class that will automatically handle adding/removing players from
5
+ * a shared player map.
6
+ *
7
+ * This should be preferred over using constant calls to `getPlayers` since it will
8
+ * have marginally less overhead
9
+ */
10
+ export declare class PlayerList {
11
+ private static playerMap;
12
+ static get AllPlayers(): Readonly<PlayerMap>;
13
+ }
package/PlayerList.js ADDED
@@ -0,0 +1,27 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { Player } from "./entities/Player";
4
+ class PlayerList {
5
+ static {
6
+ __name(this, "PlayerList");
7
+ }
8
+ static playerMap = /* @__PURE__ */ new Map();
9
+ static {
10
+ for (const srcStr of getPlayers()) {
11
+ const src = parseInt(srcStr, 10);
12
+ PlayerList.playerMap.set(src, new Player(src));
13
+ }
14
+ on("playerJoining", () => {
15
+ PlayerList.playerMap.set(source, new Player(source));
16
+ });
17
+ on("playerDropped", () => {
18
+ PlayerList.playerMap.delete(source);
19
+ });
20
+ }
21
+ static get AllPlayers() {
22
+ return PlayerList.playerMap;
23
+ }
24
+ }
25
+ export {
26
+ PlayerList
27
+ };
@@ -4,10 +4,17 @@ import { Ped } from "./Ped";
4
4
  export declare class Player {
5
5
  private readonly source;
6
6
  protected type: ClassTypes;
7
+ protected ped: Ped | null;
7
8
  constructor(source: any);
8
9
  static fromServerId(serverId: number): Player | null;
9
10
  /**
10
11
  * Get an interable list of players currently on the server
12
+ *
13
+ * You should generally prefer to use {@see PlayerList} for this if you're
14
+ * frequently doing this call, since it has less overhead, as it doesn't have
15
+ * to iterate over the entire player list every time, and it doesn't have to
16
+ * create a new player object
17
+ *
11
18
  * @returns Iterable list of Players.
12
19
  */
13
20
  static AllPlayers(): IterableIterator<Player>;
@@ -23,6 +30,10 @@ export declare class Player {
23
30
  * Returns the player source casted as a string
24
31
  */
25
32
  get Src(): string;
33
+ /**
34
+ * Gets the players ped, this is only ever set once, so subsequent calls will be
35
+ * cached
36
+ */
26
37
  get Ped(): Ped;
27
38
  get Tokens(): string[];
28
39
  get Identifiers(): string[];
@@ -13,6 +13,7 @@ class Player {
13
13
  __name(this, "Player");
14
14
  }
15
15
  type = ClassTypes.Player;
16
+ ped = null;
16
17
  static fromServerId(serverId) {
17
18
  if (!DoesPlayerExist(serverId)) {
18
19
  return null;
@@ -21,6 +22,12 @@ class Player {
21
22
  }
22
23
  /**
23
24
  * Get an interable list of players currently on the server
25
+ *
26
+ * You should generally prefer to use {@see PlayerList} for this if you're
27
+ * frequently doing this call, since it has less overhead, as it doesn't have
28
+ * to iterate over the entire player list every time, and it doesn't have to
29
+ * create a new player object
30
+ *
24
31
  * @returns Iterable list of Players.
25
32
  */
26
33
  static *AllPlayers() {
@@ -51,9 +58,15 @@ class Player {
51
58
  get Src() {
52
59
  return this.source;
53
60
  }
61
+ /**
62
+ * Gets the players ped, this is only ever set once, so subsequent calls will be
63
+ * cached
64
+ */
54
65
  get Ped() {
55
- const ped = GetPlayerPed(this.source);
56
- return new Ped(ped);
66
+ if (!this.ped) {
67
+ this.ped = new Ped(GetPlayerPed(this.source));
68
+ }
69
+ return this.ped;
57
70
  }
58
71
  get Tokens() {
59
72
  return getPlayerTokens(this.source);
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @returns This will return an unsigned hash for the current string
3
+ */
4
+ export declare function generateHash(str: string): number;
@@ -0,0 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function generateHash(str) {
4
+ return GetHashKey(str) & 4294967295;
5
+ }
6
+ __name(generateHash, "generateHash");
7
+ export {
8
+ generateHash
9
+ };
package/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from "./Game";
2
+ export * from "./PlayerList";
2
3
  export * from "./utils/waitForEntityToExist";
3
4
  export * from "./type/Anticheat";
4
5
  export * from "./type/Hash";
6
+ export * from "./game/generateHash";
5
7
  export * from "./enum/OrphanMode";
6
8
  export * from "./enum/PopulationType";
7
9
  export * from "./enum/VehicleLockStatus";
package/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  export * from "./Game";
2
+ export * from "./PlayerList";
2
3
  export * from "./utils/waitForEntityToExist";
3
4
  export * from "./type/Anticheat";
4
5
  export * from "./type/Hash";
6
+ export * from "./game/generateHash";
5
7
  export * from "./enum/OrphanMode";
6
8
  export * from "./enum/PopulationType";
7
9
  export * from "./enum/VehicleLockStatus";
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.0.165",
11
+ "version": "0.0.167",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"