|
1 |
| -# Offline Player |
| 1 | +# Offline Player v0.2.0 |
2 | 2 |
|
3 | 3 | Represents a reference to a player identity and the data belonging to a player that is stored on the disk and can, thus, be retrieved without the player needing to be online.
|
4 | 4 |
|
5 |
| -## Summary |
6 |
| - |
7 |
| -Using either `index.js` or `index.ts` file: |
8 |
| - |
9 | 5 | ```js
|
10 |
| -import { OfflinePlayer } from "offline-player/index"; |
| 6 | +import { OfflinePlayer } from "offline-player/index.js"; |
11 | 7 |
|
12 | 8 | // Get data via player.id (Recommended)
|
13 | 9 | const player = OfflinePlayer.get('-68719476735');
|
14 | 10 | // Or get via player.name
|
15 | 11 | const player = OfflinePlayer.get('JaylyPlays');
|
16 | 12 | ```
|
17 | 13 |
|
18 |
| -## Properties |
19 |
| -- [level](#level) |
20 |
| -- [name](#name) |
21 |
| -- [totalXpNeededForNextLevel](#totalxpneededfornextlevel) |
22 |
| -- [xpEarnedAtCurrentLevel](#xpearnedatcurrentlevel) |
23 |
| -- [gameMode](#gamemode) |
24 |
| -- [lastPlayed](#lastplayed) |
25 |
| - |
26 |
| -### **level** |
27 |
| -`readonly level: number;` |
28 |
| - |
29 |
| -The current overall level for the player, based on their experience. |
30 |
| - |
31 |
| -Type: *number* |
32 |
| - |
33 |
| -### **name** |
34 |
| -`readonly name: string;` |
35 |
| - |
36 |
| -Name of the player. |
37 |
| - |
38 |
| -Type: *string* |
39 |
| - |
40 |
| -### **totalXpNeededForNextLevel** |
41 |
| -`readonly totalXpNeededForNextLevel: number;` |
42 |
| - |
43 |
| -The overall total set of experience needed to achieve the next level for a player. |
44 |
| - |
45 |
| -Type: *number* |
46 |
| - |
47 |
| -### **xpEarnedAtCurrentLevel** |
48 |
| -`readonly xpEarnedAtCurrentLevel: number;` |
49 |
| - |
50 |
| -The current set of experience achieved for the player. |
51 |
| - |
52 |
| -Type: *number* |
53 |
| - |
54 |
| -### **gameMode** |
55 |
| -`readonly gameMode: GameMode;` |
56 |
| - |
57 |
| -The current gamemode for the player. |
58 |
| - |
59 |
| -Type: *GameMode* |
60 |
| - |
61 |
| -### **lastPlayed** |
62 |
| -`readonly lastPlayed: number;` |
63 |
| - |
64 |
| -Gets the last date and time that this player was witnessed on this server. It will return Date of last log-in for this player in the amount of milliseconds since midnight, January 1, 1970 UTC. |
65 |
| - |
66 |
| -Type: *number* |
67 |
| - |
68 |
| -## Methods |
69 |
| -- [get](#get) |
70 |
| -- [get](#get-1) |
71 |
| -- [getSpawnPoint](#getspawnpoint) |
72 |
| -- [getTotalXp](#gettotalxp) |
73 |
| -- [isOp](#isop) |
74 |
| -- [getPlayer](#getplayer) |
75 |
| - |
76 |
| -### **get** |
77 |
| -` |
78 |
| -static get(id: string): OfflinePlayer; |
79 |
| -` |
80 |
| - |
81 |
| -Gets the player by the given ID, regardless if they are offline or online. This will return an object even if the player does not exist. To this method, all players will exist. |
82 |
| - |
83 |
| -#### **Parameters** |
84 |
| -- **id**: *string* |
85 |
| - |
86 |
| - the ID of the player to retrieve. |
87 |
| - |
88 |
| -#### **Returns** *OfflinePlayer* |
89 |
| - |
90 |
| -### **get** |
91 |
| - |
92 |
| -` |
93 |
| -static get(name: string): OfflinePlayer; |
94 |
| -` |
95 |
| - |
96 |
| -Gets the player by the given name, regardless if they are offline or online. This will return an object even if the player does not exist. To this method, all players will exist. |
97 |
| - |
98 |
| -> [!CAUTION] |
99 |
| -> Persistent storage of users should be by ID as names are no longer unique past a single session. |
100 |
| -
|
101 |
| -#### **Parameters** |
102 |
| -- **name**: *string* |
103 |
| - |
104 |
| - the name of the player to retrieve. |
105 |
| - |
106 |
| -#### **Returns** *OfflinePlayer* |
107 |
| - |
108 |
| -### **getSpawnPoint** |
109 |
| -` |
110 |
| -getSpawnPoint(): DimensionLocation | undefined |
111 |
| -` |
112 |
| - |
113 |
| -Gets the current spawn point of the player. |
114 |
| - |
115 |
| -#### **Returns** *DimensionLocation* | *undefined* |
116 |
| - |
117 |
| -### **getTotalXp** |
118 |
| -` |
119 |
| -getTotalXp(): number |
120 |
| -` |
121 |
| - |
122 |
| - Gets the total experience of the Player. |
123 |
| - |
124 |
| -#### **Returns** *number* |
125 |
| - |
126 |
| -### **isOp** |
127 |
| -` |
128 |
| -isOp(): boolean |
129 |
| -` |
130 |
| - |
131 |
| -Returns true if this player has operator-level permissions. |
| 14 | +## Summary |
132 | 15 |
|
133 |
| -#### **Returns** *boolean* |
| 16 | +Using either `index.js` with `index.d.ts` file, or `index.ts` file if you're working with TypeScript. |
134 | 17 |
|
135 |
| -> [!IMPORTANT] |
136 |
| -> This function can only be used within Beta APIs. |
| 18 | +### Basic Player Data |
137 | 19 |
|
138 |
| -### **getPlayer** |
139 |
| -` |
140 |
| -getPlayer(): Player | undefined |
141 |
| -` |
| 20 | +Following data are saved into dynamic properties: |
142 | 21 |
|
143 |
| -If the player is online, this will return that player corresponds to. |
| 22 | +- `dimension: Dimension;` |
| 23 | +- `id: string;` |
| 24 | +- `isSneaking: boolean;` |
| 25 | +- `location: Vector3;` |
| 26 | +- `typeId = "minecraft:player";` |
| 27 | +- `level: number;` |
| 28 | +- `name: string;` |
| 29 | +- `totalXpNeededForNextLevel: number;` |
| 30 | +- `xpEarnedAtCurrentLevel: number;` |
| 31 | +- `gameMode: GameMode;` |
| 32 | +- `lastPlayed: number;` |
| 33 | +- `scoreboardIdentity?: ScoreboardOfflineIdentity;` |
| 34 | +- `getSpawnPoint(): DimensionLocation | undefined;` |
| 35 | +- `getTotalXp(): number;` |
| 36 | +- `isOp(): boolean;` |
| 37 | +- `getPlayer(): Player | undefined;` Gets the player object if the player is online. |
144 | 38 |
|
145 |
| -#### **Returns** *Player | undefined* |
| 39 | +### Getting Player Scores from Scoreboard |
146 | 40 |
|
147 |
| -## Schema |
| 41 | +If `offlinePlayer.scoreboardIdentity` exists, it means player's scoreboard data can be accessed offline. |
148 | 42 |
|
| 43 | +Example: |
149 | 44 | ```ts
|
150 |
| -import { Dimension, DimensionLocation, GameMode, Player, Vector3 } from "@minecraft/server"; |
151 |
| -export class OfflinePlayer { |
152 |
| - private constructor(); |
153 |
| - static get(id: `${number}`): OfflinePlayer; |
154 |
| - static get(name: string): OfflinePlayer; |
155 |
| - readonly dimension: Dimension; |
156 |
| - readonly id: string; |
157 |
| - readonly isSneaking: boolean; |
158 |
| - readonly location: Vector3; |
159 |
| - readonly typeId = "minecraft:player"; |
160 |
| - readonly level: number; |
161 |
| - readonly name: string; |
162 |
| - readonly totalXpNeededForNextLevel: number; |
163 |
| - readonly xpEarnedAtCurrentLevel: number; |
164 |
| - readonly gameMode: GameMode; |
165 |
| - readonly lastPlayed: number; |
166 |
| - getSpawnPoint(): DimensionLocation | undefined; |
167 |
| - getTotalXp(): number; |
168 |
| - isOp(): boolean; |
169 |
| - getPlayer(): Player | undefined; |
170 |
| -} |
| 45 | +offlinePlayer.scoreboardIdentity.getScore('objective'); |
171 | 46 | ```
|
172 | 47 |
|
173 | 48 | ## License
|
|
0 commit comments