hive-bedrock-api 3.0.0-alpha.3 → 3.0.0-alpha.31

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.
Files changed (83) hide show
  1. package/README.md +2 -2
  2. package/lib/index.d.ts +24 -4
  3. package/lib/index.js +80 -2
  4. package/lib/processors/game.d.ts +17 -31
  5. package/lib/processors/game.js +64 -61
  6. package/lib/processors/player.d.ts +41 -18
  7. package/lib/processors/player.js +11 -0
  8. package/lib/utils.d.ts +0 -1
  9. package/package.json +2 -2
  10. package/lib/helpers/fetchEndpoint.d.ts +0 -3
  11. package/lib/helpers/fetchEndpoint.js +0 -88
  12. package/lib/helpers/isGame.d.ts +0 -2
  13. package/lib/helpers/isGame.js +0 -7
  14. package/lib/helpers/toPoint.d.ts +0 -1
  15. package/lib/helpers/toPoint.js +0 -10
  16. package/lib/methods/getAllTimeLeaderboard.d.ts +0 -4
  17. package/lib/methods/getAllTimeLeaderboard.js +0 -85
  18. package/lib/methods/getAllTimeStatistics.d.ts +0 -10
  19. package/lib/methods/getAllTimeStatistics.js +0 -126
  20. package/lib/methods/getGlobalStatistics.d.ts +0 -3
  21. package/lib/methods/getGlobalStatistics.js +0 -56
  22. package/lib/methods/getMaps.d.ts +0 -3
  23. package/lib/methods/getMaps.js +0 -81
  24. package/lib/methods/getMetadata.d.ts +0 -3
  25. package/lib/methods/getMetadata.js +0 -81
  26. package/lib/methods/getMonthlyLeaderboard.d.ts +0 -11
  27. package/lib/methods/getMonthlyLeaderboard.js +0 -88
  28. package/lib/methods/getMonthlyStatistics.d.ts +0 -10
  29. package/lib/methods/getMonthlyStatistics.js +0 -132
  30. package/lib/methods/getPlayerInfomation.d.ts +0 -3
  31. package/lib/methods/getPlayerInfomation.js +0 -72
  32. package/lib/methods/getSeasonLeaderboard.d.ts +0 -10
  33. package/lib/methods/getSeasonLeaderboard.js +0 -87
  34. package/lib/methods/getSeasonStatistics.d.ts +0 -10
  35. package/lib/methods/getSeasonStatistics.js +0 -87
  36. package/lib/processors/bed.d.ts +0 -19
  37. package/lib/processors/bed.js +0 -35
  38. package/lib/processors/bridge.d.ts +0 -24
  39. package/lib/processors/bridge.js +0 -40
  40. package/lib/processors/build.d.ts +0 -19
  41. package/lib/processors/build.js +0 -35
  42. package/lib/processors/ctf.d.ts +0 -19
  43. package/lib/processors/ctf.js +0 -35
  44. package/lib/processors/dr.d.ts +0 -19
  45. package/lib/processors/dr.js +0 -35
  46. package/lib/processors/drop.d.ts +0 -17
  47. package/lib/processors/drop.js +0 -34
  48. package/lib/processors/grav.d.ts +0 -17
  49. package/lib/processors/grav.js +0 -34
  50. package/lib/processors/ground.d.ts +0 -19
  51. package/lib/processors/ground.js +0 -35
  52. package/lib/processors/helpers/processBuildRatings.d.ts +0 -8
  53. package/lib/processors/helpers/processBuildRatings.js +0 -23
  54. package/lib/processors/helpers/processGameAndXP.d.ts +0 -6
  55. package/lib/processors/helpers/processGameAndXP.js +0 -10
  56. package/lib/processors/helpers/processHiderKillsAndDeaths.d.ts +0 -5
  57. package/lib/processors/helpers/processHiderKillsAndDeaths.js +0 -13
  58. package/lib/processors/helpers/processKillsAndDeaths.d.ts +0 -5
  59. package/lib/processors/helpers/processKillsAndDeaths.js +0 -13
  60. package/lib/processors/helpers/processMurdersAndDeaths.d.ts +0 -5
  61. package/lib/processors/helpers/processMurdersAndDeaths.js +0 -13
  62. package/lib/processors/helpers/processPlayedAndVictories.d.ts +0 -6
  63. package/lib/processors/helpers/processPlayedAndVictories.js +0 -12
  64. package/lib/processors/hide.d.ts +0 -19
  65. package/lib/processors/hide.js +0 -35
  66. package/lib/processors/index.d.ts +0 -12
  67. package/lib/processors/index.js +0 -73
  68. package/lib/processors/murder.d.ts +0 -19
  69. package/lib/processors/murder.js +0 -35
  70. package/lib/processors/parkour.d.ts +0 -5
  71. package/lib/processors/parkour.js +0 -99
  72. package/lib/processors/party.d.ts +0 -17
  73. package/lib/processors/party.js +0 -34
  74. package/lib/processors/sg.d.ts +0 -19
  75. package/lib/processors/sg.js +0 -35
  76. package/lib/processors/sky.d.ts +0 -19
  77. package/lib/processors/sky.js +0 -35
  78. package/lib/processors/wars.d.ts +0 -19
  79. package/lib/processors/wars.js +0 -35
  80. package/lib/types/output.d.ts +0 -62
  81. package/lib/types/output.js +0 -3
  82. package/lib/types/types.d.ts +0 -24
  83. package/lib/types/types.js +0 -2
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  An API wrapper for the Hive Minecraft Bedrock Edition server. Which allows you to get stats for leaderboards, players, cosmetics, unique player counts, maps and metadata.
4
4
 
5
5
  > [!NOTE]
6
- > This API responses returnded from this package will differ from the responses returned by the offical Hive API. This due to our preference and needs when using this package on [Hive Backpack](https://hivebackpack.com).
6
+ > This API responses returned from this package will differ from the responses returned by the official Hive API. This due to our preference and needs when using this package on [Hive Backpack](https://hivebackpack.com).
7
7
 
8
8
  ## Getting started
9
9
 
@@ -16,7 +16,7 @@ You should also include `hive-bedrock-data` as it includes useful functions and
16
16
 
17
17
  ## Usage
18
18
 
19
- To start using this API wrapper you may construct the main class `HiveAPI`. This class can take in seperate options that will be used in every http request.
19
+ To start using the API, construct the main class `HiveAPI`. This class takes in options that will be used in every HTTP request.
20
20
 
21
21
  ```ts
22
22
  const api = new HiveAPI({
package/lib/index.d.ts CHANGED
@@ -5,12 +5,19 @@ import { ProcessedGlobalStatisticsResponse } from "./processors/global_statistic
5
5
  import { ProcessedMapResponse } from "./processors/map";
6
6
  import { ProcessedGameMetadata } from "./processors/meta";
7
7
  import { ProcessedPlayerSearchResponse } from "./processors/player_search";
8
- import { ProcessedAllGamesResponse, ProcessedGame } from "./processors/game";
8
+ import { AvailableLeaderboardResponse, ProcessedAllGamesResponse, ProcessedGame, ProcessedMonthlyGamesResponse } from "./processors/game";
9
9
  interface Options {
10
10
  resolveDynamicTitles?: boolean;
11
+ useModernLeaderboardSource?: boolean;
11
12
  apiBaseEndpoint?: string;
12
13
  requestInit?: RequestInit;
13
14
  }
15
+ export * from "./processors/game";
16
+ export * from "./processors/global_statistics";
17
+ export * from "./processors/map";
18
+ export * from "./processors/meta";
19
+ export * from "./processors/player";
20
+ export * from "./processors/player_search";
14
21
  export default class HiveAPI {
15
22
  options: Options;
16
23
  constructor(options?: Options);
@@ -41,14 +48,20 @@ export default class HiveAPI {
41
48
  getStatistics(identifier: string, timeframe: Timeframe.Monthly, options?: {
42
49
  month?: number;
43
50
  year?: number;
44
- }): Promise<MethodResponse<ProcessedAllGamesResponse>>;
51
+ }): Promise<MethodResponse<ProcessedMonthlyGamesResponse>>;
45
52
  getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.Monthly, options: {
46
53
  game: G;
47
54
  month?: number;
48
55
  year?: number;
49
56
  }): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, false>[G]>>;
57
+ getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.Seasonal, options: {
58
+ game: G;
59
+ season: number;
60
+ }): Promise<MethodResponse<ProcessedMonthlyGamesResponse>>;
50
61
  private _getStatisticsAllTime;
51
62
  private _getStatisticsMonthly;
63
+ private _getStatisticsSeasonal;
64
+ getAvailableMonthlyLeaderboards<G extends Game>(game: G): Promise<MethodResponse<AvailableLeaderboardResponse>>;
52
65
  /**
53
66
  * `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
54
67
  * @param identifier Username or UUID of the player
@@ -56,7 +69,7 @@ export default class HiveAPI {
56
69
  * @param season The season to get the statistics for
57
70
  * @returns The player's seasonal statistics
58
71
  */
59
- getSeasonalStatistics<G extends Game>(identifier: string, game: G, season?: number): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G] | null>>;
72
+ getSeasonalStatistics<G extends Game>(identifier: string, game: G, season?: number): Promise<MethodResponse<ProcessedMonthlyGamesResponse["statistics"][G] | null>>;
60
73
  /**
61
74
  * `/game/all/{game}` Gets statistics for a game
62
75
  * @param timeframe The timeframe to get the statistics for
@@ -65,8 +78,16 @@ export default class HiveAPI {
65
78
  */
66
79
  getLeaderboard<G extends Game>(timeframe: Timeframe.AllTime, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.AllTime, true>[G][] | null>>;
67
80
  getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
81
+ getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G, options: {
82
+ month?: number;
83
+ year?: number;
84
+ }): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
85
+ getLeaderboard<G extends Game>(timeframe: Timeframe.Seasonal, game: G, options: {
86
+ season: number;
87
+ }): Promise<MethodResponse<ProcessedGame<Timeframe.Seasonal, true>[G][] | null>>;
68
88
  private _getLeaderboardAllTime;
69
89
  private _getLeaderboardMonthly;
90
+ private _getLeaderboardSeasonal;
70
91
  /**
71
92
  * `/game/season/{game}/{season}` Gets seasonal statistics for a game
72
93
  * @param game The game to get the statistics for
@@ -92,4 +113,3 @@ export default class HiveAPI {
92
113
  */
93
114
  getGameMetadata(game: Game): Promise<MethodResponse<ProcessedGameMetadata>>;
94
115
  }
95
- export {};
package/lib/index.js CHANGED
@@ -10,6 +10,20 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
25
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
26
+ };
13
27
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
28
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
29
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -70,10 +84,19 @@ var hive_bedrock_data_1 = require("hive-bedrock-data");
70
84
  var player_1 = __importDefault(require("./processors/player"));
71
85
  var player_search_1 = __importDefault(require("./processors/player_search"));
72
86
  var game_1 = __importDefault(require("./processors/game"));
87
+ __exportStar(require("./processors/game"), exports);
88
+ __exportStar(require("./processors/global_statistics"), exports);
89
+ __exportStar(require("./processors/map"), exports);
90
+ __exportStar(require("./processors/meta"), exports);
91
+ __exportStar(require("./processors/player"), exports);
92
+ __exportStar(require("./processors/player_search"), exports);
73
93
  var HiveAPI = /** @class */ (function () {
74
94
  function HiveAPI(options) {
75
- if (options === void 0) { options = { resolveDynamicTitles: true, apiBaseEndpoint: hive_bedrock_data_1.API_BASE_ENDPOINT }; }
95
+ if (options === void 0) { options = {}; }
96
+ var _a;
97
+ this.options = options;
76
98
  this.options = options;
99
+ this.options.apiBaseEndpoint = (_a = this.options.apiBaseEndpoint) !== null && _a !== void 0 ? _a : hive_bedrock_data_1.API_BASE_ENDPOINT;
77
100
  }
78
101
  HiveAPI.prototype._fetchAPI = function (endpoint) {
79
102
  return __awaiter(this, void 0, void 0, function () {
@@ -87,7 +110,7 @@ var HiveAPI = /** @class */ (function () {
87
110
  case 1:
88
111
  _c.trys.push([1, 4, , 5]);
89
112
  start = performance.now();
90
- return [4 /*yield*/, fetch(url, __assign(__assign({}, this.options.requestInit), { headers: __assign({ "X-Hive-Resolve-Stat-Track": ((_a = this.options.resolveDynamicTitles) !== null && _a !== void 0 ? _a : true).toString() }, (_b = this.options.requestInit) === null || _b === void 0 ? void 0 : _b.headers) }))];
113
+ return [4 /*yield*/, fetch(url, __assign(__assign({}, this.options.requestInit), { headers: __assign({ "X-Hive-Resolve-Stat-Track": ((_a = this.options.resolveDynamicTitles) !== null && _a !== void 0 ? _a : true).toString(), "X-Hive-Leaderboard-Source": this.options.useModernLeaderboardSource ? "modern" : "legacy" }, (_b = this.options.requestInit) === null || _b === void 0 ? void 0 : _b.headers) }))];
91
114
  case 2:
92
115
  request = _c.sent();
93
116
  if (!request.ok)
@@ -167,6 +190,11 @@ var HiveAPI = /** @class */ (function () {
167
190
  return [2 /*return*/, this._getStatisticsAllTime(identifier, options.game)];
168
191
  return [2 /*return*/, this._getStatisticsAllTime(identifier)];
169
192
  }
193
+ else if (timeframe === hive_bedrock_data_1.Timeframe.Seasonal) {
194
+ if (!(options === null || options === void 0 ? void 0 : options.game))
195
+ throw new Error("Game must be specified for seasonal statistics");
196
+ return [2 /*return*/, this._getStatisticsSeasonal(identifier, options === null || options === void 0 ? void 0 : options.game, (options === null || options === void 0 ? void 0 : options.season) || 1)];
197
+ }
170
198
  if (options === null || options === void 0 ? void 0 : options.game)
171
199
  return [2 /*return*/, this._getStatisticsMonthly(identifier, options.game, options.month, options.year)];
172
200
  return [2 /*return*/, this._getStatisticsMonthly(identifier, undefined, options === null || options === void 0 ? void 0 : options.month, options === null || options === void 0 ? void 0 : options.year)];
@@ -232,6 +260,36 @@ var HiveAPI = /** @class */ (function () {
232
260
  });
233
261
  });
234
262
  };
263
+ HiveAPI.prototype._getStatisticsSeasonal = function (identifier, game, season) {
264
+ return __awaiter(this, void 0, void 0, function () {
265
+ var _a, response, error, meta;
266
+ return __generator(this, function (_b) {
267
+ switch (_b.label) {
268
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/season/player/".concat(game, "/").concat(identifier, "/").concat(season !== null && season !== void 0 ? season : 1))];
269
+ case 1:
270
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
271
+ if (error)
272
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
273
+ return [2 /*return*/, { data: (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Seasonal, false, response), error: null, meta: meta }];
274
+ }
275
+ });
276
+ });
277
+ };
278
+ HiveAPI.prototype.getAvailableMonthlyLeaderboards = function (game) {
279
+ return __awaiter(this, void 0, void 0, function () {
280
+ var _a, response, error, meta;
281
+ return __generator(this, function (_b) {
282
+ switch (_b.label) {
283
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/monthly/".concat(game, "/available"))];
284
+ case 1:
285
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
286
+ if (error)
287
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
288
+ return [2 /*return*/, { data: response, error: null, meta: meta }];
289
+ }
290
+ });
291
+ });
292
+ };
235
293
  /**
236
294
  * `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
237
295
  * @param identifier Username or UUID of the player
@@ -261,6 +319,8 @@ var HiveAPI = /** @class */ (function () {
261
319
  return __generator(this, function (_a) {
262
320
  if (timeframe === hive_bedrock_data_1.Timeframe.Monthly)
263
321
  return [2 /*return*/, this._getLeaderboardMonthly(game, (options === null || options === void 0 ? void 0 : options.month) || new Date().getMonth() + 1, (options === null || options === void 0 ? void 0 : options.year) || new Date().getFullYear())];
322
+ if (timeframe === hive_bedrock_data_1.Timeframe.Seasonal)
323
+ return [2 /*return*/, this._getLeaderboardSeasonal(game, (options === null || options === void 0 ? void 0 : options.season) || 1)];
264
324
  return [2 /*return*/, this._getLeaderboardAllTime(game)];
265
325
  });
266
326
  });
@@ -299,6 +359,24 @@ var HiveAPI = /** @class */ (function () {
299
359
  });
300
360
  });
301
361
  };
362
+ // /game/season/{game}/season
363
+ HiveAPI.prototype._getLeaderboardSeasonal = function (game_2) {
364
+ return __awaiter(this, arguments, void 0, function (game, season) {
365
+ var _a, response, error, meta, data;
366
+ if (season === void 0) { season = 1; }
367
+ return __generator(this, function (_b) {
368
+ switch (_b.label) {
369
+ case 0: return [4 /*yield*/, this._fetchAPI("/game/season/".concat(game, "/").concat(season))];
370
+ case 1:
371
+ _a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
372
+ if (error)
373
+ return [2 /*return*/, { data: null, error: error, meta: meta }];
374
+ data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Seasonal, true, res); });
375
+ return [2 /*return*/, { data: data, error: null, meta: meta }];
376
+ }
377
+ });
378
+ });
379
+ };
302
380
  /**
303
381
  * `/game/season/{game}/{season}` Gets seasonal statistics for a game
304
382
  * @param game The game to get the statistics for
@@ -88,7 +88,7 @@ export interface ProcessedGameGROUND {
88
88
  projectiles_fired: number;
89
89
  }
90
90
  export interface ProcessedGameBUILD {
91
- id: Game.JustBuild;
91
+ id: Game.BuildBattle;
92
92
  xp: number;
93
93
  played: number;
94
94
  victories: number;
@@ -111,7 +111,7 @@ export interface ProcessedGameHIDE {
111
111
  deaths: number;
112
112
  hider_kills: number;
113
113
  seeker_kills: number;
114
- kdr: number;
114
+ kpg: number;
115
115
  }
116
116
  export interface ProcessedGameMURDER {
117
117
  id: Game.MurderMystery;
@@ -122,7 +122,7 @@ export interface ProcessedGameMURDER {
122
122
  win_percentage: number;
123
123
  murders: number;
124
124
  deaths: number;
125
- kdr: number;
125
+ edr: number;
126
126
  coins: number;
127
127
  murderer_eliminations: number;
128
128
  prestige: number;
@@ -140,6 +140,7 @@ export interface ProcessedGameSKY {
140
140
  mystery_chests_destroyed: number;
141
141
  ores_mined: number;
142
142
  spells_used: number;
143
+ prestige: number;
143
144
  }
144
145
  export interface ProcessedGameSKYKITS {
145
146
  id: Game.SkyWarsKits;
@@ -241,7 +242,10 @@ export type AdditionalStatistics<T extends Timeframe, L extends boolean> = (T ex
241
242
  level: number;
242
243
  } & (L extends true ? {} : {
243
244
  first_played: number;
244
- }) : {}) & (L extends true ? {
245
+ }) : {
246
+ position: number;
247
+ username: string;
248
+ }) & (L extends true ? {
245
249
  position: number;
246
250
  username: string;
247
251
  UUID: string;
@@ -254,7 +258,7 @@ export interface ProcessedGame<T extends Timeframe, L extends boolean> {
254
258
  [Game.DeathRun]: ProcessedGameDR & AdditionalStatistics<T, L>;
255
259
  [Game.Gravity]: ProcessedGameGRAV & AdditionalStatistics<T, L>;
256
260
  [Game.GroundWars]: ProcessedGameGROUND & AdditionalStatistics<T, L>;
257
- [Game.JustBuild]: ProcessedGameBUILD & AdditionalStatistics<T, L>;
261
+ [Game.BuildBattle]: ProcessedGameBUILD & AdditionalStatistics<T, L>;
258
262
  [Game.HideAndSeek]: ProcessedGameHIDE & AdditionalStatistics<T, L>;
259
263
  [Game.MurderMystery]: ProcessedGameMURDER & AdditionalStatistics<T, L>;
260
264
  [Game.SkyWars]: ProcessedGameSKY & AdditionalStatistics<T, L>;
@@ -263,34 +267,9 @@ export interface ProcessedGame<T extends Timeframe, L extends boolean> {
263
267
  [Game.SurvivalGames]: ProcessedGameSG & AdditionalStatistics<T, L>;
264
268
  [Game.TheBridge]: ProcessedGameBRIDGE & AdditionalStatistics<T, L>;
265
269
  [Game.TreasureWars]: ProcessedGameWARS & AdditionalStatistics<T, L>;
266
- [Game.ParkourWorlds]: L extends true ? never : T extends Timeframe.Monthly ? never : ProcessedGamePARKOUR;
270
+ [Game.ParkourWorlds]: L extends true ? never : T extends Timeframe.AllTime ? ProcessedGamePARKOUR : never;
267
271
  }
268
272
  export default function processGame<G extends Game, T extends Timeframe, L extends boolean>(game: G, timeframe: T, isLeaderboard: L, response: any): ProcessedGame<T, L>[G] | null;
269
- export declare const processors: {
270
- bed: (response: any) => ProcessedGameBED;
271
- drop: (response: any) => ProcessedGameDROP;
272
- party: (response: any) => ProcessedGamePARTY;
273
- ctf: (response: any) => ProcessedGameCTF;
274
- dr: (response: any) => ProcessedGameDR;
275
- grav: (response: any) => ProcessedGameGRAV;
276
- ground: (response: any) => ProcessedGameGROUND;
277
- build: (response: any) => ProcessedGameBUILD;
278
- hide: (response: any) => ProcessedGameHIDE;
279
- murder: (response: any) => ProcessedGameMURDER;
280
- sky: (response: any) => ProcessedGameSKY;
281
- "sky-kits": (response: any) => ProcessedGameSKYKITS;
282
- "sky-classic": (response: any) => ProcessedGameSKYCLASSIC;
283
- sg: (response: any) => ProcessedGameSG;
284
- bridge: (response: any) => ProcessedGameBRIDGE;
285
- wars: (response: any) => ProcessedGameWARS;
286
- parkour: (response: any) => ProcessedGamePARKOUR;
287
- };
288
- export declare function validateNumber(value: number, def?: number): number;
289
- export declare function calculateKDR(kills: number, deaths: number): number;
290
- export declare function calculateWinPercentage(victories: number, played: number): number;
291
- export declare function calculateLosses(played: number, victories: number): number;
292
- export declare function calculateTotal(values: number[]): number;
293
- export declare function roundTo(value: number, places?: number): number;
294
273
  export interface ProcessedAllGamesResponse {
295
274
  player: ProcessedPlayerResponse;
296
275
  statistics: {
@@ -302,3 +281,10 @@ export interface ProcessedMonthlyGamesResponse {
302
281
  [G in Game]: ProcessedGame<Timeframe.Monthly, false>[G] | null;
303
282
  };
304
283
  }
284
+ export interface AvailableLeaderboard {
285
+ month: string;
286
+ year: string;
287
+ month_number: number;
288
+ resource: string;
289
+ }
290
+ export type AvailableLeaderboardResponse = AvailableLeaderboard[];
@@ -17,14 +17,7 @@ var __read = (this && this.__read) || function (o, n) {
17
17
  };
18
18
  var _a;
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.processors = void 0;
21
20
  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
21
  var hive_bedrock_data_1 = require("hive-bedrock-data");
29
22
  function processGame(game, timeframe, isLeaderboard, response) {
30
23
  var _a;
@@ -34,22 +27,24 @@ function processGame(game, timeframe, isLeaderboard, response) {
34
27
  return null;
35
28
  if (Array.isArray(response))
36
29
  return null;
37
- var data = exports.processors[game](response);
38
- if ("played" in data && data.played === 0)
30
+ var data = processors[game](response);
31
+ if (!data)
32
+ return null;
33
+ if ("played" in data && data.played === 0 && "xp" in data && data.xp === 0)
39
34
  return null;
40
35
  if (timeframe === hive_bedrock_data_1.Timeframe.AllTime && "xp" in data)
41
36
  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)
37
+ if (timeframe === hive_bedrock_data_1.Timeframe.AllTime && "first_played" in response)
43
38
  data.first_played = response.first_played;
44
- if (isLeaderboard && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
39
+ if ((isLeaderboard || timeframe !== hive_bedrock_data_1.Timeframe.AllTime) && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
45
40
  data.position = response.human_index;
46
- if (isLeaderboard && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
41
+ if ((isLeaderboard || timeframe !== hive_bedrock_data_1.Timeframe.AllTime) && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
47
42
  data.username = response.username;
48
43
  if (isLeaderboard && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
49
44
  data.UUID = response.UUID;
50
45
  return data;
51
46
  }
52
- exports.processors = (_a = {},
47
+ var processors = (_a = {},
53
48
  _a[hive_bedrock_data_1.Game.BedWars] = function (response) {
54
49
  var _a, _b, _c, _d, _e, _f, _g;
55
50
  return ({
@@ -158,10 +153,10 @@ exports.processors = (_a = {},
158
153
  projectiles_fired: (_h = response.projectiles_fired) !== null && _h !== void 0 ? _h : 0,
159
154
  });
160
155
  },
161
- _a[hive_bedrock_data_1.Game.JustBuild] = function (response) {
156
+ _a[hive_bedrock_data_1.Game.BuildBattle] = function (response) {
162
157
  var _a, _b, _c, _d, _e, _f, _g, _h;
163
158
  return ({
164
- id: hive_bedrock_data_1.Game.JustBuild,
159
+ id: hive_bedrock_data_1.Game.BuildBattle,
165
160
  xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
166
161
  played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
167
162
  victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
@@ -192,7 +187,7 @@ exports.processors = (_a = {},
192
187
  win_percentage: calculateWinPercentage(response.victories, response.played),
193
188
  deaths: (_d = response.deaths) !== null && _d !== void 0 ? _d : 0,
194
189
  hider_kills: (_e = response.hider_kills) !== null && _e !== void 0 ? _e : 0,
195
- kdr: calculateKDR(response.hider_kills, response.deaths),
190
+ kpg: calculateKPG(response.hider_kills, response.played),
196
191
  seeker_kills: (_f = response.seeker_kills) !== null && _f !== void 0 ? _f : 0,
197
192
  });
198
193
  },
@@ -207,14 +202,14 @@ exports.processors = (_a = {},
207
202
  win_percentage: calculateWinPercentage(response.victories, response.played),
208
203
  murders: (_d = response.murders) !== null && _d !== void 0 ? _d : 0,
209
204
  deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
210
- kdr: calculateKDR(response.murders, response.deaths),
205
+ edr: calculateKDR(response.murderer_eliminations, response.deaths),
211
206
  coins: (_f = response.coins) !== null && _f !== void 0 ? _f : 0,
212
207
  murderer_eliminations: (_g = response.murderer_eliminations) !== null && _g !== void 0 ? _g : 0,
213
208
  prestige: (_h = response.prestige) !== null && _h !== void 0 ? _h : 0,
214
209
  });
215
210
  },
216
211
  _a[hive_bedrock_data_1.Game.SkyWars] = function (response) {
217
- var _a, _b, _c, _d, _e, _f, _g, _h;
212
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
218
213
  return ({
219
214
  id: hive_bedrock_data_1.Game.SkyWars,
220
215
  xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
@@ -228,6 +223,7 @@ exports.processors = (_a = {},
228
223
  mystery_chests_destroyed: (_f = response.mystery_chests_destroyed) !== null && _f !== void 0 ? _f : 0,
229
224
  ores_mined: (_g = response.ores_mined) !== null && _g !== void 0 ? _g : 0,
230
225
  spells_used: (_h = response.spells_used) !== null && _h !== void 0 ? _h : 0,
226
+ prestige: (_j = response.prestige) !== null && _j !== void 0 ? _j : 0,
231
227
  });
232
228
  },
233
229
  _a[hive_bedrock_data_1.Game.SkyWarsKits] = function (response) {
@@ -317,49 +313,51 @@ exports.processors = (_a = {},
317
313
  },
318
314
  _a[hive_bedrock_data_1.Game.ParkourWorlds] = function (response) {
319
315
  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
- });
316
+ return response.parkours
317
+ ? {
318
+ id: hive_bedrock_data_1.Game.ParkourWorlds,
319
+ worlds: Object.entries(response.parkours)
320
+ .filter(function (_a) {
321
+ var _b = __read(_a, 2), _ = _b[0], value = _b[1];
322
+ return typeof value === "object";
323
+ })
324
+ .map(function (_a) {
325
+ var _b;
326
+ var _c = __read(_a, 2), key = _c[0], value = _c[1];
327
+ return ({
328
+ name: key,
329
+ parkour_stars: (_b = value.parkour_stars) !== null && _b !== void 0 ? _b : 0,
330
+ courses: Object.entries(value)
331
+ .filter(function (_a) {
332
+ var _b = __read(_a, 2), _ = _b[0], value = _b[1];
333
+ return typeof value === "object";
334
+ })
335
+ .map(function (_a) {
336
+ var _b;
337
+ var _c = __read(_a, 2), key = _c[0], value = _c[1];
338
+ return ({
339
+ name: key,
340
+ best_run_time: value.best_run_time,
341
+ best_checkpoint_times: Object.entries(value.best_checkpoint_times).map(function (_a) {
342
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
343
+ return ({
344
+ position: { x: Number(key.split(",")[0]), y: Number(key.split(",")[1]), z: Number(key.split(",")[2]) },
345
+ time: value,
346
+ });
347
+ }),
348
+ collected_stars: value.collected_stars.map(function (value) { return ({
349
+ x: Number(value.split(",")[0]),
350
+ y: Number(value.split(",")[1]),
351
+ z: Number(value.split(",")[2]),
352
+ }); }),
353
+ course_stars: (_b = value.course_stars) !== null && _b !== void 0 ? _b : 0,
354
+ });
355
+ }),
356
+ });
357
+ }),
358
+ total_stars: (_a = response.parkours.total_stars) !== null && _a !== void 0 ? _a : 0,
359
+ }
360
+ : null;
363
361
  },
364
362
  _a);
365
363
  function validateNumber(value, def) {
@@ -384,6 +382,11 @@ function calculateLosses(played, victories) {
384
382
  function calculateTotal(values) {
385
383
  return validateNumber(values.reduce(function (a, b) { return (a !== null && a !== void 0 ? a : 0) + (b !== null && b !== void 0 ? b : 0); }, 0));
386
384
  }
385
+ function calculateKPG(kills, games) {
386
+ if (games === 0)
387
+ return validateNumber(kills !== null && kills !== void 0 ? kills : 0);
388
+ return roundTo(validateNumber((kills !== null && kills !== void 0 ? kills : 0) / (games !== null && games !== void 0 ? games : 0)), 2);
389
+ }
387
390
  function roundTo(value, places) {
388
391
  if (places === void 0) { places = 2; }
389
392
  return validateNumber(Number(value.toFixed(places)));
@@ -13,26 +13,49 @@ export interface ProcessedPlayerResponse {
13
13
  quest_count: number;
14
14
  };
15
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;
16
+ costume: CosmeticResponseTypes[CosmeticType.Costume];
17
+ avatar: CosmeticResponseTypes[CosmeticType.Avatar];
18
+ hub_title: CosmeticResponseTypes[CosmeticType.HubTitle];
19
+ hat: CosmeticResponseTypes[CosmeticType.Hat];
20
+ backbling: CosmeticResponseTypes[CosmeticType.Backbling];
24
21
  };
25
22
  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[];
23
+ costume: CosmeticResponseTypes[CosmeticType.Costume][];
24
+ avatar: CosmeticResponseTypes[CosmeticType.Avatar][];
25
+ hub_title: CosmeticResponseTypes[CosmeticType.HubTitle][];
26
+ hat: CosmeticResponseTypes[CosmeticType.Hat][];
27
+ pet: CosmeticResponseTypes[CosmeticType.Pet][];
28
+ mount: CosmeticResponseTypes[CosmeticType.Mount][];
29
+ backbling: CosmeticResponseTypes[CosmeticType.Backbling][];
30
+ };
31
+ }
32
+ export declare enum CosmeticType {
33
+ Costume = "costume",
34
+ Avatar = "avatar",
35
+ HubTitle = "hub_title",
36
+ Hat = "hat",
37
+ Pet = "pet",
38
+ Mount = "mount",
39
+ Backbling = "backbling"
40
+ }
41
+ export interface CosmeticResponseTypes {
42
+ [CosmeticType.Costume]: string;
43
+ [CosmeticType.Avatar]: {
44
+ name: string;
45
+ url: string;
46
+ };
47
+ [CosmeticType.HubTitle]: string;
48
+ [CosmeticType.Hat]: {
49
+ name: string;
50
+ icon: string;
51
+ rarity: string;
52
+ };
53
+ [CosmeticType.Pet]: string;
54
+ [CosmeticType.Mount]: string;
55
+ [CosmeticType.Backbling]: {
56
+ name: string;
57
+ icon: string;
58
+ rarity: string;
36
59
  };
37
60
  }
38
61
  export default function processPlayerInfo(playerResponse: any): ProcessedPlayerResponse | null;
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CosmeticType = void 0;
3
4
  exports.default = processPlayerInfo;
5
+ var CosmeticType;
6
+ (function (CosmeticType) {
7
+ CosmeticType["Costume"] = "costume";
8
+ CosmeticType["Avatar"] = "avatar";
9
+ CosmeticType["HubTitle"] = "hub_title";
10
+ CosmeticType["Hat"] = "hat";
11
+ CosmeticType["Pet"] = "pet";
12
+ CosmeticType["Mount"] = "mount";
13
+ CosmeticType["Backbling"] = "backbling";
14
+ })(CosmeticType || (exports.CosmeticType = CosmeticType = {}));
4
15
  function processPlayerInfo(playerResponse) {
5
16
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
6
17
  if (!playerResponse)
package/lib/utils.d.ts CHANGED
@@ -4,7 +4,6 @@ export interface MethodResponseError {
4
4
  }
5
5
  export type MethodResponse<D extends any> = {
6
6
  meta?: {
7
- /** sss */
8
7
  duration: number;
9
8
  ratelimit?: {
10
9
  limit: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hive-bedrock-api",
3
- "version": "3.0.0-alpha.3",
3
+ "version": "3.0.0-alpha.31",
4
4
  "description": "An API wrapper for the Hive Minecraft Bedrock Edition server.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "license": "MIT",
12
12
  "author": "Cubeedge Studios",
13
13
  "dependencies": {
14
- "hive-bedrock-data": "^2.0.0-alpha.0"
14
+ "hive-bedrock-data": "^2.0.0-alpha.17"
15
15
  },
16
16
  "scripts": {
17
17
  "build": "tsc"
@@ -1,3 +0,0 @@
1
- import { APIResponse } from "../types/types";
2
- import { Routes } from "hive-bedrock-data";
3
- export default function fetchEndpoint<T extends string>(endpoint: T, init?: RequestInit): Promise<APIResponse<Routes<T>>>;