hive-bedrock-api 2.1.10 → 3.0.0-alpha.1

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,390 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var _a;
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.processors = void 0;
21
+ exports.default = processGame;
22
+ exports.validateNumber = validateNumber;
23
+ exports.calculateKDR = calculateKDR;
24
+ exports.calculateWinPercentage = calculateWinPercentage;
25
+ exports.calculateLosses = calculateLosses;
26
+ exports.calculateTotal = calculateTotal;
27
+ exports.roundTo = roundTo;
28
+ var hive_bedrock_data_1 = require("hive-bedrock-data");
29
+ function processGame(game, timeframe, isLeaderboard, response) {
30
+ var _a;
31
+ if (!response)
32
+ return null;
33
+ if ("index" in response && response.human_index === 2147483647)
34
+ return null;
35
+ if (Array.isArray(response))
36
+ return null;
37
+ var data = exports.processors[game](response);
38
+ if ("played" in data && data.played === 0)
39
+ return null;
40
+ if (timeframe === hive_bedrock_data_1.Timeframe.AllTime && "xp" in data)
41
+ data.level = (_a = (0, hive_bedrock_data_1.calculateLevelFromXP)(data.xp, game)) !== null && _a !== void 0 ? _a : 1;
42
+ if (timeframe === hive_bedrock_data_1.Timeframe.AllTime && "first_played" in data)
43
+ data.first_played = response.first_played;
44
+ if (isLeaderboard && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
45
+ data.position = response.human_index;
46
+ if (isLeaderboard && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
47
+ data.username = response.username;
48
+ if (isLeaderboard && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
49
+ data.UUID = response.UUID;
50
+ return data;
51
+ }
52
+ exports.processors = (_a = {},
53
+ _a[hive_bedrock_data_1.Game.BedWars] = function (response) {
54
+ var _a, _b, _c, _d, _e, _f, _g;
55
+ return ({
56
+ id: hive_bedrock_data_1.Game.BedWars,
57
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
58
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
59
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
60
+ losses: calculateLosses(response.played, response.victories),
61
+ win_percentage: calculateWinPercentage(response.victories, response.played),
62
+ kills: (_d = response.kills) !== null && _d !== void 0 ? _d : 0,
63
+ deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
64
+ kdr: calculateKDR(response.kills, response.deaths),
65
+ final_kills: (_f = response.final_kills) !== null && _f !== void 0 ? _f : 0,
66
+ beds_destroyed: (_g = response.beds_destroyed) !== null && _g !== void 0 ? _g : 0,
67
+ });
68
+ },
69
+ _a[hive_bedrock_data_1.Game.BlockDrop] = function (response) {
70
+ var _a, _b, _c, _d, _e, _f, _g;
71
+ return ({
72
+ id: hive_bedrock_data_1.Game.BlockDrop,
73
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
74
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
75
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
76
+ losses: calculateLosses(response.played, response.victories),
77
+ win_percentage: calculateWinPercentage(response.victories, response.played),
78
+ deaths: (_d = response.deaths) !== null && _d !== void 0 ? _d : 0,
79
+ blocks_destroyed: (_e = response.blocks_destroyed) !== null && _e !== void 0 ? _e : 0,
80
+ powerups_collected: (_f = response.powerups_collected) !== null && _f !== void 0 ? _f : 0,
81
+ vaults_used: (_g = response.vaults_used) !== null && _g !== void 0 ? _g : 0,
82
+ });
83
+ },
84
+ _a[hive_bedrock_data_1.Game.BlockParty] = function (response) {
85
+ var _a, _b, _c, _d, _e;
86
+ return ({
87
+ id: hive_bedrock_data_1.Game.BlockParty,
88
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
89
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
90
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
91
+ losses: calculateLosses(response.played, response.victories),
92
+ win_percentage: calculateWinPercentage(response.victories, response.played),
93
+ powerups_collected: (_d = response.powerups_collected) !== null && _d !== void 0 ? _d : 0,
94
+ rounds_survived: (_e = response.rounds_survived) !== null && _e !== void 0 ? _e : 0,
95
+ });
96
+ },
97
+ _a[hive_bedrock_data_1.Game.CaptureTheFlag] = function (response) {
98
+ var _a, _b, _c, _d, _e, _f, _g, _h;
99
+ return ({
100
+ id: hive_bedrock_data_1.Game.CaptureTheFlag,
101
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
102
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
103
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
104
+ losses: calculateLosses(response.played, response.victories),
105
+ win_percentage: calculateWinPercentage(response.victories, response.played),
106
+ kills: (_d = response.kills) !== null && _d !== void 0 ? _d : 0,
107
+ deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
108
+ kdr: calculateKDR(response.kills, response.deaths),
109
+ assists: (_f = response.assists) !== null && _f !== void 0 ? _f : 0,
110
+ flags_captured: (_g = response.flags_captured) !== null && _g !== void 0 ? _g : 0,
111
+ flags_returned: (_h = response.flags_returned) !== null && _h !== void 0 ? _h : 0,
112
+ });
113
+ },
114
+ _a[hive_bedrock_data_1.Game.DeathRun] = function (response) {
115
+ var _a, _b, _c, _d, _e, _f, _g;
116
+ return ({
117
+ id: hive_bedrock_data_1.Game.DeathRun,
118
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
119
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
120
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
121
+ losses: calculateLosses(response.played, response.victories),
122
+ win_percentage: calculateWinPercentage(response.victories, response.played),
123
+ kills: (_d = response.kills) !== null && _d !== void 0 ? _d : 0,
124
+ deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
125
+ kdr: calculateKDR(response.kills, response.deaths),
126
+ checkpoints: (_f = response.checkpoints) !== null && _f !== void 0 ? _f : 0,
127
+ activated: (_g = response.activated) !== null && _g !== void 0 ? _g : 0,
128
+ });
129
+ },
130
+ _a[hive_bedrock_data_1.Game.Gravity] = function (response) {
131
+ var _a, _b, _c, _d, _e, _f;
132
+ return ({
133
+ id: hive_bedrock_data_1.Game.Gravity,
134
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
135
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
136
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
137
+ losses: calculateLosses(response.played, response.victories),
138
+ win_percentage: calculateWinPercentage(response.victories, response.played),
139
+ deaths: (_d = response.deaths) !== null && _d !== void 0 ? _d : 0,
140
+ maps_completed: (_e = response.maps_completed) !== null && _e !== void 0 ? _e : 0,
141
+ maps_completed_without_dying: (_f = response.maps_completed_without_dying) !== null && _f !== void 0 ? _f : 0,
142
+ });
143
+ },
144
+ _a[hive_bedrock_data_1.Game.GroundWars] = function (response) {
145
+ var _a, _b, _c, _d, _e, _f, _g, _h;
146
+ return ({
147
+ id: hive_bedrock_data_1.Game.GroundWars,
148
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
149
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
150
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
151
+ losses: calculateLosses(response.played, response.victories),
152
+ win_percentage: calculateWinPercentage(response.victories, response.played),
153
+ kills: (_d = response.kills) !== null && _d !== void 0 ? _d : 0,
154
+ deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
155
+ kdr: calculateKDR(response.kills, response.deaths),
156
+ blocks_destroyed: (_f = response.blocks_destroyed) !== null && _f !== void 0 ? _f : 0,
157
+ blocks_placed: (_g = response.blocks_placed) !== null && _g !== void 0 ? _g : 0,
158
+ projectiles_fired: (_h = response.projectiles_fired) !== null && _h !== void 0 ? _h : 0,
159
+ });
160
+ },
161
+ _a[hive_bedrock_data_1.Game.JustBuild] = function (response) {
162
+ var _a, _b, _c, _d, _e, _f, _g, _h;
163
+ return ({
164
+ id: hive_bedrock_data_1.Game.JustBuild,
165
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
166
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
167
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
168
+ losses: calculateLosses(response.played, response.victories),
169
+ win_percentage: calculateWinPercentage(response.victories, response.played),
170
+ rating_meh_received: (_d = response.rating_meh_received) !== null && _d !== void 0 ? _d : 0,
171
+ rating_okay_received: (_e = response.rating_okay_received) !== null && _e !== void 0 ? _e : 0,
172
+ rating_good_received: (_f = response.rating_good_received) !== null && _f !== void 0 ? _f : 0,
173
+ rating_great_received: (_g = response.rating_great_received) !== null && _g !== void 0 ? _g : 0,
174
+ rating_love_received: (_h = response.rating_love_received) !== null && _h !== void 0 ? _h : 0,
175
+ total_ratings: calculateTotal([
176
+ response.rating_meh_received,
177
+ response.rating_okay_received,
178
+ response.rating_good_received,
179
+ response.rating_great_received,
180
+ response.rating_love_received,
181
+ ]),
182
+ });
183
+ },
184
+ _a[hive_bedrock_data_1.Game.HideAndSeek] = function (response) {
185
+ var _a, _b, _c, _d, _e, _f;
186
+ return ({
187
+ id: hive_bedrock_data_1.Game.HideAndSeek,
188
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
189
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
190
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
191
+ losses: calculateLosses(response.played, response.victories),
192
+ win_percentage: calculateWinPercentage(response.victories, response.played),
193
+ deaths: (_d = response.deaths) !== null && _d !== void 0 ? _d : 0,
194
+ hider_kills: (_e = response.hider_kills) !== null && _e !== void 0 ? _e : 0,
195
+ kdr: calculateKDR(response.hider_kills, response.deaths),
196
+ seeker_kills: (_f = response.seeker_kills) !== null && _f !== void 0 ? _f : 0,
197
+ });
198
+ },
199
+ _a[hive_bedrock_data_1.Game.MurderMystery] = function (response) {
200
+ var _a, _b, _c, _d, _e, _f, _g, _h;
201
+ return ({
202
+ id: hive_bedrock_data_1.Game.MurderMystery,
203
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
204
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
205
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
206
+ losses: calculateLosses(response.played, response.victories),
207
+ win_percentage: calculateWinPercentage(response.victories, response.played),
208
+ murders: (_d = response.murders) !== null && _d !== void 0 ? _d : 0,
209
+ deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
210
+ kdr: calculateKDR(response.murders, response.deaths),
211
+ coins: (_f = response.coins) !== null && _f !== void 0 ? _f : 0,
212
+ murderer_eliminations: (_g = response.murderer_eliminations) !== null && _g !== void 0 ? _g : 0,
213
+ prestige: (_h = response.prestige) !== null && _h !== void 0 ? _h : 0,
214
+ });
215
+ },
216
+ _a[hive_bedrock_data_1.Game.Skywars] = function (response) {
217
+ var _a, _b, _c, _d, _e, _f, _g, _h;
218
+ return ({
219
+ id: hive_bedrock_data_1.Game.Skywars,
220
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
221
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
222
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
223
+ losses: calculateLosses(response.played, response.victories),
224
+ win_percentage: calculateWinPercentage(response.victories, response.played),
225
+ kills: (_d = response.kills) !== null && _d !== void 0 ? _d : 0,
226
+ deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
227
+ kdr: calculateKDR(response.kills, response.deaths),
228
+ mystery_chests_destroyed: (_f = response.mystery_chests_destroyed) !== null && _f !== void 0 ? _f : 0,
229
+ ores_mined: (_g = response.ores_mined) !== null && _g !== void 0 ? _g : 0,
230
+ spells_used: (_h = response.spells_used) !== null && _h !== void 0 ? _h : 0,
231
+ });
232
+ },
233
+ _a[hive_bedrock_data_1.Game.SkywarsKits] = function (response) {
234
+ var _a, _b, _c, _d, _e, _f, _g, _h;
235
+ return ({
236
+ id: hive_bedrock_data_1.Game.SkywarsKits,
237
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
238
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
239
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
240
+ losses: calculateLosses(response.played, response.victories),
241
+ win_percentage: calculateWinPercentage(response.victories, response.played),
242
+ kills: (_d = response.kills) !== null && _d !== void 0 ? _d : 0,
243
+ deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
244
+ kdr: calculateKDR(response.kills, response.deaths),
245
+ mystery_chests_destroyed: (_f = response.mystery_chests_destroyed) !== null && _f !== void 0 ? _f : 0,
246
+ ores_mined: (_g = response.ores_mined) !== null && _g !== void 0 ? _g : 0,
247
+ spells_used: (_h = response.spells_used) !== null && _h !== void 0 ? _h : 0,
248
+ selected_kit: response.selected_kit,
249
+ });
250
+ },
251
+ _a[hive_bedrock_data_1.Game.SkywarsClassic] = function (response) {
252
+ var _a, _b, _c, _d, _e;
253
+ return ({
254
+ id: hive_bedrock_data_1.Game.SkywarsClassic,
255
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
256
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
257
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
258
+ losses: calculateLosses(response.played, response.victories),
259
+ win_percentage: calculateWinPercentage(response.victories, response.played),
260
+ kills: (_d = response.kills) !== null && _d !== void 0 ? _d : 0,
261
+ deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
262
+ kdr: calculateKDR(response.kills, response.deaths),
263
+ selected_kit: response.selected_kit,
264
+ });
265
+ },
266
+ _a[hive_bedrock_data_1.Game.SurvivalGames] = function (response) {
267
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
268
+ return ({
269
+ id: hive_bedrock_data_1.Game.SurvivalGames,
270
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
271
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
272
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
273
+ losses: calculateLosses(response.played, response.victories),
274
+ win_percentage: calculateWinPercentage(response.victories, response.played),
275
+ kills: (_d = response.kills) !== null && _d !== void 0 ? _d : 0,
276
+ deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
277
+ kdr: calculateKDR(response.kills, response.deaths),
278
+ cows: (_f = response.cows) !== null && _f !== void 0 ? _f : 0,
279
+ deathmatches: (_g = response.deathmatches) !== null && _g !== void 0 ? _g : 0,
280
+ crates: (_h = response.crates) !== null && _h !== void 0 ? _h : 0,
281
+ teleporters_used: (_j = response.teleporters_used) !== null && _j !== void 0 ? _j : 0,
282
+ launchpads_used: (_k = response.launchpads_used) !== null && _k !== void 0 ? _k : 0,
283
+ flares_used: (_l = response.flares_used) !== null && _l !== void 0 ? _l : 0,
284
+ });
285
+ },
286
+ _a[hive_bedrock_data_1.Game.TheBridge] = function (response) {
287
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
288
+ return ({
289
+ id: hive_bedrock_data_1.Game.TheBridge,
290
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
291
+ played: (_c = (_b = response.played) !== null && _b !== void 0 ? _b : response.m_solo_played) !== null && _c !== void 0 ? _c : 0,
292
+ victories: (_e = (_d = response.victories) !== null && _d !== void 0 ? _d : response.m_solo_victories) !== null && _e !== void 0 ? _e : 0,
293
+ losses: calculateLosses((_f = response.played) !== null && _f !== void 0 ? _f : response.m_solo_played, (_g = response.victories) !== null && _g !== void 0 ? _g : response.m_solo_victories),
294
+ win_percentage: calculateWinPercentage((_h = response.victories) !== null && _h !== void 0 ? _h : response.m_solo_victories, (_j = response.played) !== null && _j !== void 0 ? _j : response.m_solo_played),
295
+ kills: (_l = (_k = response.kills) !== null && _k !== void 0 ? _k : response.m_solo_kills) !== null && _l !== void 0 ? _l : 0,
296
+ deaths: (_o = (_m = response.deaths) !== null && _m !== void 0 ? _m : response.m_solo_deaths) !== null && _o !== void 0 ? _o : 0,
297
+ kdr: calculateKDR((_p = response.kills) !== null && _p !== void 0 ? _p : response.m_solo_kills, (_q = response.deaths) !== null && _q !== void 0 ? _q : response.m_solo_deaths),
298
+ goals: (_s = (_r = response.goals) !== null && _r !== void 0 ? _r : response.m_solo_goals) !== null && _s !== void 0 ? _s : 0,
299
+ });
300
+ },
301
+ _a[hive_bedrock_data_1.Game.TreasureWars] = function (response) {
302
+ var _a, _b, _c, _d, _e, _f, _g, _h;
303
+ return ({
304
+ id: hive_bedrock_data_1.Game.TreasureWars,
305
+ xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
306
+ played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
307
+ victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
308
+ losses: calculateLosses(response.played, response.victories),
309
+ win_percentage: calculateWinPercentage(response.victories, response.played),
310
+ kills: (_d = response.kills) !== null && _d !== void 0 ? _d : 0,
311
+ deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
312
+ kdr: calculateKDR(response.kills, response.deaths),
313
+ final_kills: (_f = response.final_kills) !== null && _f !== void 0 ? _f : 0,
314
+ treasure_destroyed: (_g = response.treasure_destroyed) !== null && _g !== void 0 ? _g : 0,
315
+ prestige: (_h = response.prestige) !== null && _h !== void 0 ? _h : 0,
316
+ });
317
+ },
318
+ _a[hive_bedrock_data_1.Game.ParkourWorlds] = function (response) {
319
+ var _a;
320
+ return ({
321
+ id: hive_bedrock_data_1.Game.ParkourWorlds,
322
+ worlds: Object.entries(response.parkours)
323
+ .filter(function (_a) {
324
+ var _b = __read(_a, 2), _ = _b[0], value = _b[1];
325
+ return typeof value === "object";
326
+ })
327
+ .map(function (_a) {
328
+ var _b;
329
+ var _c = __read(_a, 2), key = _c[0], value = _c[1];
330
+ return ({
331
+ name: key,
332
+ parkour_stars: (_b = value.parkour_stars) !== null && _b !== void 0 ? _b : 0,
333
+ courses: Object.entries(value)
334
+ .filter(function (_a) {
335
+ var _b = __read(_a, 2), _ = _b[0], value = _b[1];
336
+ return typeof value === "object";
337
+ })
338
+ .map(function (_a) {
339
+ var _b;
340
+ var _c = __read(_a, 2), key = _c[0], value = _c[1];
341
+ return ({
342
+ name: key,
343
+ best_run_time: value.best_run_time,
344
+ best_checkpoint_times: Object.entries(value.best_checkpoint_times).map(function (_a) {
345
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
346
+ return ({
347
+ position: { x: Number(key.split(",")[0]), y: Number(key.split(",")[1]), z: Number(key.split(",")[2]) },
348
+ time: value,
349
+ });
350
+ }),
351
+ collected_stars: value.collected_stars.map(function (value) { return ({
352
+ x: Number(value.split(",")[0]),
353
+ y: Number(value.split(",")[1]),
354
+ z: Number(value.split(",")[2]),
355
+ }); }),
356
+ course_stars: (_b = value.course_stars) !== null && _b !== void 0 ? _b : 0,
357
+ });
358
+ }),
359
+ });
360
+ }),
361
+ total_stars: (_a = response.parkours.total_stars) !== null && _a !== void 0 ? _a : 0,
362
+ });
363
+ },
364
+ _a);
365
+ function validateNumber(value, def) {
366
+ if (def === void 0) { def = 0; }
367
+ if (isNaN(value) || !isFinite(value))
368
+ return def;
369
+ return value !== null && value !== void 0 ? value : def;
370
+ }
371
+ function calculateKDR(kills, deaths) {
372
+ if (deaths === 0)
373
+ return validateNumber(kills !== null && kills !== void 0 ? kills : 0);
374
+ return roundTo(validateNumber((kills !== null && kills !== void 0 ? kills : 0) / (deaths !== null && deaths !== void 0 ? deaths : 0)), 2);
375
+ }
376
+ function calculateWinPercentage(victories, played) {
377
+ if (victories === 0 && played === 0)
378
+ return 0;
379
+ return validateNumber((victories !== null && victories !== void 0 ? victories : 0) / (played !== null && played !== void 0 ? played : 0));
380
+ }
381
+ function calculateLosses(played, victories) {
382
+ return validateNumber((played !== null && played !== void 0 ? played : 0) - (victories !== null && victories !== void 0 ? victories : 0));
383
+ }
384
+ function calculateTotal(values) {
385
+ return validateNumber(values.reduce(function (a, b) { return (a !== null && a !== void 0 ? a : 0) + (b !== null && b !== void 0 ? b : 0); }, 0));
386
+ }
387
+ function roundTo(value, places) {
388
+ if (places === void 0) { places = 2; }
389
+ return validateNumber(Number(value.toFixed(places)));
390
+ }
@@ -0,0 +1,9 @@
1
+ import { Game } from "hive-bedrock-data";
2
+ export interface ProcessedGlobalStatisticsResponse {
3
+ unique_players: {
4
+ [key in Game]: number;
5
+ } & {
6
+ global: number;
7
+ main: number;
8
+ };
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { MapSeason, MapVariant } from "hive-bedrock-data";
2
+ export interface ProcessedMap {
3
+ name: string;
4
+ season: MapSeason;
5
+ variant: MapVariant;
6
+ image: string;
7
+ }
8
+ export type ProcessedMapResponse = ProcessedMap[];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,45 @@
1
+ export interface ProcessedGameMetadata {
2
+ name: string;
3
+ shortName: string;
4
+ maxLevel: number;
5
+ allowPrestiging: boolean;
6
+ maxPrestige: number;
7
+ experienceToLevel: {
8
+ [xp: number]: number;
9
+ };
10
+ levelUnlocks: {
11
+ [level: number]: LevelUnlock[];
12
+ };
13
+ levelUnlockTypes: {
14
+ [type: string]: {
15
+ name: string;
16
+ icon: string | null;
17
+ default: string | null;
18
+ };
19
+ };
20
+ }
21
+ export type LevelUnlock = {
22
+ name: string;
23
+ icon: string | null;
24
+ type: string;
25
+ global: false;
26
+ } & ({
27
+ global: false;
28
+ } | {
29
+ global: true;
30
+ globalCosmetic: GlobalUnlock;
31
+ });
32
+ export type GlobalUnlock = GlobalTitleUnlock | GlobalAvatarUnlock | GlobalCostumeUnlock;
33
+ export interface GlobalTitleUnlock {
34
+ type: "hub_title";
35
+ display: string;
36
+ }
37
+ export interface GlobalAvatarUnlock {
38
+ type: "avatar";
39
+ name: string;
40
+ url: string;
41
+ }
42
+ export interface GlobalCostumeUnlock {
43
+ type: "costume";
44
+ name: string;
45
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +1,38 @@
1
- import { PlayerMetadata, PlayerMetadata_Avatar, PlayerMetadata_Backbling } from "hive-bedrock-data";
2
- export interface Processed_Player_Statistics extends Omit<PlayerMetadata, "first_played" | "cosmetics.backbling" | "equipped_hub_title" | "equipped_avatar" | "equipped_costume"> {
3
- first_played: number | null;
4
- backbling_unlocked: PlayerMetadata_Backbling[];
5
- equipped_hub_title: string | null;
6
- equipped_avatar: PlayerMetadata_Avatar | null;
7
- equipped_costume: string | null;
1
+ export interface ProcessedPlayerResponse {
2
+ info: {
3
+ uuid: string;
4
+ xuid: string;
5
+ username: string;
6
+ rank: string;
7
+ first_played: number;
8
+ login_streak: {
9
+ current: number;
10
+ longest: number;
11
+ };
12
+ friend_count: number;
13
+ quest_count: number;
14
+ };
15
+ equipped_cosmetics: {
16
+ costume: string;
17
+ avatar: {
18
+ name: string;
19
+ url: string;
20
+ };
21
+ hub_title: string;
22
+ hat: string;
23
+ backbling: string;
24
+ };
25
+ owned_cosmetics: {
26
+ costume: string[];
27
+ avatar: {
28
+ name: string;
29
+ url: string;
30
+ }[];
31
+ hub_title: string[];
32
+ hat: string[];
33
+ pet: string[];
34
+ mount: string[];
35
+ backbling: string[];
36
+ };
8
37
  }
9
- export declare function process_PLAYER(statistics: Partial<PlayerMetadata>): Processed_Player_Statistics | null;
38
+ export default function processPlayerInfo(playerResponse: any): ProcessedPlayerResponse | null;
@@ -1,36 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.process_PLAYER = process_PLAYER;
4
- var hive_bedrock_data_1 = require("hive-bedrock-data");
5
- function process_PLAYER(statistics) {
6
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
7
- if (!statistics || Array.isArray(statistics))
3
+ exports.default = processPlayerInfo;
4
+ function processPlayerInfo(playerResponse) {
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
6
+ if (!playerResponse)
8
7
  return null;
8
+ var player = playerResponse.main;
9
+ var info = {
10
+ uuid: player.UUID,
11
+ xuid: player.xuid.toString(),
12
+ username: player.username_cc,
13
+ rank: player.rank,
14
+ first_played: player.first_played,
15
+ login_streak: {
16
+ current: (_a = player.daily_login_streak) !== null && _a !== void 0 ? _a : 0,
17
+ longest: (_b = player.longest_daily_login_streak) !== null && _b !== void 0 ? _b : 0,
18
+ },
19
+ friend_count: (_c = player.friend_count) !== null && _c !== void 0 ? _c : 0,
20
+ quest_count: (_d = player.quest_count) !== null && _d !== void 0 ? _d : 0,
21
+ };
22
+ var equipped_cosmetics = {
23
+ costume: (_e = player.equipped_costume) !== null && _e !== void 0 ? _e : null,
24
+ avatar: (_f = player.equipped_avatar) !== null && _f !== void 0 ? _f : null,
25
+ hub_title: (_g = player.equipped_hub_title) !== null && _g !== void 0 ? _g : null,
26
+ hat: (_h = player.equipped_hat) !== null && _h !== void 0 ? _h : null,
27
+ backbling: (_j = player.equipped_backbling) !== null && _j !== void 0 ? _j : null,
28
+ };
29
+ var owned_cosmetics = {
30
+ costume: (_k = player.costume_unlocked) !== null && _k !== void 0 ? _k : [],
31
+ avatar: (_l = player.avatar_unlocked) !== null && _l !== void 0 ? _l : [],
32
+ hub_title: (_m = player.hub_title_unlocked) !== null && _m !== void 0 ? _m : [],
33
+ hat: (_o = player.hat_unlocked) !== null && _o !== void 0 ? _o : [],
34
+ pet: (_p = player.pets) !== null && _p !== void 0 ? _p : [],
35
+ mount: (_q = player.mounts) !== null && _q !== void 0 ? _q : [],
36
+ backbling: (_r = player["cosmetics.backbling"]) !== null && _r !== void 0 ? _r : [],
37
+ };
9
38
  return {
10
- UUID: statistics.UUID,
11
- xuid: statistics.xuid,
12
- username: statistics.username,
13
- username_cc: statistics.username_cc,
14
- rank: (_a = statistics.rank) !== null && _a !== void 0 ? _a : hive_bedrock_data_1.PlayerRank.Regular,
15
- first_played: (_b = statistics.first_played) !== null && _b !== void 0 ? _b : null,
16
- quest_count: (_c = statistics.quest_count) !== null && _c !== void 0 ? _c : 0,
17
- friend_count: (_d = statistics.friend_count) !== null && _d !== void 0 ? _d : 0,
18
- daily_login_streak: (_e = statistics.daily_login_streak) !== null && _e !== void 0 ? _e : 0,
19
- longest_daily_login_streak: (_f = statistics.longest_daily_login_streak) !== null && _f !== void 0 ? _f : 0,
20
- avatar_count: (_h = (_g = statistics.avatar_unlocked) === null || _g === void 0 ? void 0 : _g.length) !== null && _h !== void 0 ? _h : 0,
21
- avatar_unlocked: (_j = statistics.avatar_unlocked) !== null && _j !== void 0 ? _j : [],
22
- equipped_avatar: (_k = statistics.equipped_avatar) !== null && _k !== void 0 ? _k : null,
23
- hub_title_count: (_m = (_l = statistics.hub_title_unlocked) === null || _l === void 0 ? void 0 : _l.length) !== null && _m !== void 0 ? _m : 0,
24
- hub_title_unlocked: (_o = statistics.hub_title_unlocked) !== null && _o !== void 0 ? _o : [],
25
- equipped_hub_title: (_p = statistics.equipped_hub_title) !== null && _p !== void 0 ? _p : null,
26
- costume_count: (_r = (_q = statistics.costume_unlocked) === null || _q === void 0 ? void 0 : _q.length) !== null && _r !== void 0 ? _r : 0,
27
- costume_unlocked: (_s = statistics.costume_unlocked) !== null && _s !== void 0 ? _s : [],
28
- equipped_costume: (_t = statistics.equipped_costume) !== null && _t !== void 0 ? _t : null,
29
- backbling_count: (_v = (_u = statistics["cosmetics.backbling"]) === null || _u === void 0 ? void 0 : _u.length) !== null && _v !== void 0 ? _v : 0,
30
- backbling_unlocked: (_w = statistics["cosmetics.backbling"]) !== null && _w !== void 0 ? _w : [],
31
- hat_count: (_y = (_x = statistics.hat_unlocked) === null || _x === void 0 ? void 0 : _x.length) !== null && _y !== void 0 ? _y : 0,
32
- hat_unlocked: (_z = statistics.hat_unlocked) !== null && _z !== void 0 ? _z : [],
33
- pets: (_0 = statistics.pets) !== null && _0 !== void 0 ? _0 : [],
34
- mounts: (_1 = statistics.mounts) !== null && _1 !== void 0 ? _1 : [],
39
+ info: info,
40
+ equipped_cosmetics: equipped_cosmetics,
41
+ owned_cosmetics: owned_cosmetics,
35
42
  };
36
43
  }
@@ -0,0 +1,6 @@
1
+ export interface PartialPlayer {
2
+ uuid: string;
3
+ username: string;
4
+ }
5
+ export type ProcessedPlayerSearchResponse = PartialPlayer[];
6
+ export default function processPlayerSearch(playerSearchResponse: any): ProcessedPlayerSearchResponse | null;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = processPlayerSearch;
4
+ function processPlayerSearch(playerSearchResponse) {
5
+ if (!playerSearchResponse)
6
+ return null;
7
+ return playerSearchResponse.map(function (player) { return ({
8
+ uuid: player.UUID,
9
+ username: player.username_cc,
10
+ }); });
11
+ }
package/lib/utils.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ export interface MethodResponseError {
2
+ status?: number;
3
+ message?: string;
4
+ }
5
+ export type MethodResponse<D extends any> = {
6
+ meta?: {
7
+ /** sss */
8
+ duration: number;
9
+ ratelimit?: {
10
+ limit: number;
11
+ remaining: number;
12
+ reset: number;
13
+ };
14
+ retryAfter?: number;
15
+ };
16
+ } & ({
17
+ data: D;
18
+ error: null;
19
+ } | {
20
+ data: null;
21
+ error: MethodResponseError;
22
+ });
package/lib/utils.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });