hive-bedrock-api 3.0.0-alpha.3 → 3.0.0-alpha.30
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.
- package/README.md +2 -2
- package/lib/index.d.ts +18 -3
- package/lib/index.js +60 -2
- package/lib/processors/game.d.ts +19 -7
- package/lib/processors/game.js +63 -52
- package/lib/processors/player.d.ts +41 -18
- package/lib/processors/player.js +11 -0
- package/lib/utils.d.ts +0 -1
- package/package.json +2 -2
- package/lib/helpers/fetchEndpoint.d.ts +0 -3
- package/lib/helpers/fetchEndpoint.js +0 -88
- package/lib/helpers/isGame.d.ts +0 -2
- package/lib/helpers/isGame.js +0 -7
- package/lib/helpers/toPoint.d.ts +0 -1
- package/lib/helpers/toPoint.js +0 -10
- package/lib/methods/getAllTimeLeaderboard.d.ts +0 -4
- package/lib/methods/getAllTimeLeaderboard.js +0 -85
- package/lib/methods/getAllTimeStatistics.d.ts +0 -10
- package/lib/methods/getAllTimeStatistics.js +0 -126
- package/lib/methods/getGlobalStatistics.d.ts +0 -3
- package/lib/methods/getGlobalStatistics.js +0 -56
- package/lib/methods/getMaps.d.ts +0 -3
- package/lib/methods/getMaps.js +0 -81
- package/lib/methods/getMetadata.d.ts +0 -3
- package/lib/methods/getMetadata.js +0 -81
- package/lib/methods/getMonthlyLeaderboard.d.ts +0 -11
- package/lib/methods/getMonthlyLeaderboard.js +0 -88
- package/lib/methods/getMonthlyStatistics.d.ts +0 -10
- package/lib/methods/getMonthlyStatistics.js +0 -132
- package/lib/methods/getPlayerInfomation.d.ts +0 -3
- package/lib/methods/getPlayerInfomation.js +0 -72
- package/lib/methods/getSeasonLeaderboard.d.ts +0 -10
- package/lib/methods/getSeasonLeaderboard.js +0 -87
- package/lib/methods/getSeasonStatistics.d.ts +0 -10
- package/lib/methods/getSeasonStatistics.js +0 -87
- package/lib/processors/bed.d.ts +0 -19
- package/lib/processors/bed.js +0 -35
- package/lib/processors/bridge.d.ts +0 -24
- package/lib/processors/bridge.js +0 -40
- package/lib/processors/build.d.ts +0 -19
- package/lib/processors/build.js +0 -35
- package/lib/processors/ctf.d.ts +0 -19
- package/lib/processors/ctf.js +0 -35
- package/lib/processors/dr.d.ts +0 -19
- package/lib/processors/dr.js +0 -35
- package/lib/processors/drop.d.ts +0 -17
- package/lib/processors/drop.js +0 -34
- package/lib/processors/grav.d.ts +0 -17
- package/lib/processors/grav.js +0 -34
- package/lib/processors/ground.d.ts +0 -19
- package/lib/processors/ground.js +0 -35
- package/lib/processors/helpers/processBuildRatings.d.ts +0 -8
- package/lib/processors/helpers/processBuildRatings.js +0 -23
- package/lib/processors/helpers/processGameAndXP.d.ts +0 -6
- package/lib/processors/helpers/processGameAndXP.js +0 -10
- package/lib/processors/helpers/processHiderKillsAndDeaths.d.ts +0 -5
- package/lib/processors/helpers/processHiderKillsAndDeaths.js +0 -13
- package/lib/processors/helpers/processKillsAndDeaths.d.ts +0 -5
- package/lib/processors/helpers/processKillsAndDeaths.js +0 -13
- package/lib/processors/helpers/processMurdersAndDeaths.d.ts +0 -5
- package/lib/processors/helpers/processMurdersAndDeaths.js +0 -13
- package/lib/processors/helpers/processPlayedAndVictories.d.ts +0 -6
- package/lib/processors/helpers/processPlayedAndVictories.js +0 -12
- package/lib/processors/hide.d.ts +0 -19
- package/lib/processors/hide.js +0 -35
- package/lib/processors/index.d.ts +0 -12
- package/lib/processors/index.js +0 -73
- package/lib/processors/murder.d.ts +0 -19
- package/lib/processors/murder.js +0 -35
- package/lib/processors/parkour.d.ts +0 -5
- package/lib/processors/parkour.js +0 -99
- package/lib/processors/party.d.ts +0 -17
- package/lib/processors/party.js +0 -34
- package/lib/processors/sg.d.ts +0 -19
- package/lib/processors/sg.js +0 -35
- package/lib/processors/sky.d.ts +0 -19
- package/lib/processors/sky.js +0 -35
- package/lib/processors/wars.d.ts +0 -19
- package/lib/processors/wars.js +0 -35
- package/lib/types/output.d.ts +0 -62
- package/lib/types/output.js +0 -3
- package/lib/types/types.d.ts +0 -24
- 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
|
|
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
|
|
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,9 +5,10 @@ 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
|
}
|
|
@@ -41,14 +42,20 @@ export default class HiveAPI {
|
|
|
41
42
|
getStatistics(identifier: string, timeframe: Timeframe.Monthly, options?: {
|
|
42
43
|
month?: number;
|
|
43
44
|
year?: number;
|
|
44
|
-
}): Promise<MethodResponse<
|
|
45
|
+
}): Promise<MethodResponse<ProcessedMonthlyGamesResponse>>;
|
|
45
46
|
getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.Monthly, options: {
|
|
46
47
|
game: G;
|
|
47
48
|
month?: number;
|
|
48
49
|
year?: number;
|
|
49
50
|
}): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, false>[G]>>;
|
|
51
|
+
getStatistics<G extends Game>(identifier: string, timeframe: Timeframe.Seasonal, options: {
|
|
52
|
+
game: G;
|
|
53
|
+
season: number;
|
|
54
|
+
}): Promise<MethodResponse<ProcessedMonthlyGamesResponse>>;
|
|
50
55
|
private _getStatisticsAllTime;
|
|
51
56
|
private _getStatisticsMonthly;
|
|
57
|
+
private _getStatisticsSeasonal;
|
|
58
|
+
getAvailableMonthlyLeaderboards<G extends Game>(game: G): Promise<MethodResponse<AvailableLeaderboardResponse>>;
|
|
52
59
|
/**
|
|
53
60
|
* `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
|
|
54
61
|
* @param identifier Username or UUID of the player
|
|
@@ -56,7 +63,7 @@ export default class HiveAPI {
|
|
|
56
63
|
* @param season The season to get the statistics for
|
|
57
64
|
* @returns The player's seasonal statistics
|
|
58
65
|
*/
|
|
59
|
-
getSeasonalStatistics<G extends Game>(identifier: string, game: G, season?: number): Promise<MethodResponse<
|
|
66
|
+
getSeasonalStatistics<G extends Game>(identifier: string, game: G, season?: number): Promise<MethodResponse<ProcessedMonthlyGamesResponse["statistics"][G] | null>>;
|
|
60
67
|
/**
|
|
61
68
|
* `/game/all/{game}` Gets statistics for a game
|
|
62
69
|
* @param timeframe The timeframe to get the statistics for
|
|
@@ -65,8 +72,16 @@ export default class HiveAPI {
|
|
|
65
72
|
*/
|
|
66
73
|
getLeaderboard<G extends Game>(timeframe: Timeframe.AllTime, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.AllTime, true>[G][] | null>>;
|
|
67
74
|
getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
|
|
75
|
+
getLeaderboard<G extends Game>(timeframe: Timeframe.Monthly, game: G, options: {
|
|
76
|
+
month?: number;
|
|
77
|
+
year?: number;
|
|
78
|
+
}): Promise<MethodResponse<ProcessedGame<Timeframe.Monthly, true>[G][] | null>>;
|
|
79
|
+
getLeaderboard<G extends Game>(timeframe: Timeframe.Seasonal, game: G, options: {
|
|
80
|
+
season: number;
|
|
81
|
+
}): Promise<MethodResponse<ProcessedGame<Timeframe.Seasonal, true>[G][] | null>>;
|
|
68
82
|
private _getLeaderboardAllTime;
|
|
69
83
|
private _getLeaderboardMonthly;
|
|
84
|
+
private _getLeaderboardSeasonal;
|
|
70
85
|
/**
|
|
71
86
|
* `/game/season/{game}/{season}` Gets seasonal statistics for a game
|
|
72
87
|
* @param game The game to get the statistics for
|
package/lib/index.js
CHANGED
|
@@ -72,8 +72,11 @@ var player_search_1 = __importDefault(require("./processors/player_search"));
|
|
|
72
72
|
var game_1 = __importDefault(require("./processors/game"));
|
|
73
73
|
var HiveAPI = /** @class */ (function () {
|
|
74
74
|
function HiveAPI(options) {
|
|
75
|
-
if (options === void 0) { options = {
|
|
75
|
+
if (options === void 0) { options = {}; }
|
|
76
|
+
var _a;
|
|
76
77
|
this.options = options;
|
|
78
|
+
this.options = options;
|
|
79
|
+
this.options.apiBaseEndpoint = (_a = this.options.apiBaseEndpoint) !== null && _a !== void 0 ? _a : hive_bedrock_data_1.API_BASE_ENDPOINT;
|
|
77
80
|
}
|
|
78
81
|
HiveAPI.prototype._fetchAPI = function (endpoint) {
|
|
79
82
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -87,7 +90,7 @@ var HiveAPI = /** @class */ (function () {
|
|
|
87
90
|
case 1:
|
|
88
91
|
_c.trys.push([1, 4, , 5]);
|
|
89
92
|
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) }))];
|
|
93
|
+
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
94
|
case 2:
|
|
92
95
|
request = _c.sent();
|
|
93
96
|
if (!request.ok)
|
|
@@ -167,6 +170,11 @@ var HiveAPI = /** @class */ (function () {
|
|
|
167
170
|
return [2 /*return*/, this._getStatisticsAllTime(identifier, options.game)];
|
|
168
171
|
return [2 /*return*/, this._getStatisticsAllTime(identifier)];
|
|
169
172
|
}
|
|
173
|
+
else if (timeframe === hive_bedrock_data_1.Timeframe.Seasonal) {
|
|
174
|
+
if (!(options === null || options === void 0 ? void 0 : options.game))
|
|
175
|
+
throw new Error("Game must be specified for seasonal statistics");
|
|
176
|
+
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)];
|
|
177
|
+
}
|
|
170
178
|
if (options === null || options === void 0 ? void 0 : options.game)
|
|
171
179
|
return [2 /*return*/, this._getStatisticsMonthly(identifier, options.game, options.month, options.year)];
|
|
172
180
|
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 +240,36 @@ var HiveAPI = /** @class */ (function () {
|
|
|
232
240
|
});
|
|
233
241
|
});
|
|
234
242
|
};
|
|
243
|
+
HiveAPI.prototype._getStatisticsSeasonal = function (identifier, game, season) {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
245
|
+
var _a, response, error, meta;
|
|
246
|
+
return __generator(this, function (_b) {
|
|
247
|
+
switch (_b.label) {
|
|
248
|
+
case 0: return [4 /*yield*/, this._fetchAPI("/game/season/player/".concat(game, "/").concat(identifier, "/").concat(season !== null && season !== void 0 ? season : 1))];
|
|
249
|
+
case 1:
|
|
250
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
251
|
+
if (error)
|
|
252
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
253
|
+
return [2 /*return*/, { data: (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Seasonal, false, response), error: null, meta: meta }];
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
};
|
|
258
|
+
HiveAPI.prototype.getAvailableMonthlyLeaderboards = function (game) {
|
|
259
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
260
|
+
var _a, response, error, meta;
|
|
261
|
+
return __generator(this, function (_b) {
|
|
262
|
+
switch (_b.label) {
|
|
263
|
+
case 0: return [4 /*yield*/, this._fetchAPI("/game/monthly/".concat(game, "/available"))];
|
|
264
|
+
case 1:
|
|
265
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
266
|
+
if (error)
|
|
267
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
268
|
+
return [2 /*return*/, { data: response, error: null, meta: meta }];
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
};
|
|
235
273
|
/**
|
|
236
274
|
* `/game/season/player/{game}/{player}/{season}` Gets seasonal statistics for a player
|
|
237
275
|
* @param identifier Username or UUID of the player
|
|
@@ -261,6 +299,8 @@ var HiveAPI = /** @class */ (function () {
|
|
|
261
299
|
return __generator(this, function (_a) {
|
|
262
300
|
if (timeframe === hive_bedrock_data_1.Timeframe.Monthly)
|
|
263
301
|
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())];
|
|
302
|
+
if (timeframe === hive_bedrock_data_1.Timeframe.Seasonal)
|
|
303
|
+
return [2 /*return*/, this._getLeaderboardSeasonal(game, (options === null || options === void 0 ? void 0 : options.season) || 1)];
|
|
264
304
|
return [2 /*return*/, this._getLeaderboardAllTime(game)];
|
|
265
305
|
});
|
|
266
306
|
});
|
|
@@ -299,6 +339,24 @@ var HiveAPI = /** @class */ (function () {
|
|
|
299
339
|
});
|
|
300
340
|
});
|
|
301
341
|
};
|
|
342
|
+
// /game/season/{game}/season
|
|
343
|
+
HiveAPI.prototype._getLeaderboardSeasonal = function (game_2) {
|
|
344
|
+
return __awaiter(this, arguments, void 0, function (game, season) {
|
|
345
|
+
var _a, response, error, meta, data;
|
|
346
|
+
if (season === void 0) { season = 1; }
|
|
347
|
+
return __generator(this, function (_b) {
|
|
348
|
+
switch (_b.label) {
|
|
349
|
+
case 0: return [4 /*yield*/, this._fetchAPI("/game/season/".concat(game, "/").concat(season))];
|
|
350
|
+
case 1:
|
|
351
|
+
_a = _b.sent(), response = _a.data, error = _a.error, meta = _a.meta;
|
|
352
|
+
if (error)
|
|
353
|
+
return [2 /*return*/, { data: null, error: error, meta: meta }];
|
|
354
|
+
data = response.map(function (res) { return (0, game_1.default)(game, hive_bedrock_data_1.Timeframe.Seasonal, true, res); });
|
|
355
|
+
return [2 /*return*/, { data: data, error: null, meta: meta }];
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
};
|
|
302
360
|
/**
|
|
303
361
|
* `/game/season/{game}/{season}` Gets seasonal statistics for a game
|
|
304
362
|
* @param game The game to get the statistics for
|
package/lib/processors/game.d.ts
CHANGED
|
@@ -88,7 +88,7 @@ export interface ProcessedGameGROUND {
|
|
|
88
88
|
projectiles_fired: number;
|
|
89
89
|
}
|
|
90
90
|
export interface ProcessedGameBUILD {
|
|
91
|
-
id: Game.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
}) : {
|
|
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.
|
|
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,7 +267,7 @@ 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.
|
|
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
273
|
export declare const processors: {
|
|
@@ -283,13 +287,14 @@ export declare const processors: {
|
|
|
283
287
|
sg: (response: any) => ProcessedGameSG;
|
|
284
288
|
bridge: (response: any) => ProcessedGameBRIDGE;
|
|
285
289
|
wars: (response: any) => ProcessedGameWARS;
|
|
286
|
-
parkour: (response: any) => ProcessedGamePARKOUR;
|
|
290
|
+
parkour: (response: any) => ProcessedGamePARKOUR | null;
|
|
287
291
|
};
|
|
288
292
|
export declare function validateNumber(value: number, def?: number): number;
|
|
289
293
|
export declare function calculateKDR(kills: number, deaths: number): number;
|
|
290
294
|
export declare function calculateWinPercentage(victories: number, played: number): number;
|
|
291
295
|
export declare function calculateLosses(played: number, victories: number): number;
|
|
292
296
|
export declare function calculateTotal(values: number[]): number;
|
|
297
|
+
export declare function calculateKPG(kills: number, games: number): number;
|
|
293
298
|
export declare function roundTo(value: number, places?: number): number;
|
|
294
299
|
export interface ProcessedAllGamesResponse {
|
|
295
300
|
player: ProcessedPlayerResponse;
|
|
@@ -302,3 +307,10 @@ export interface ProcessedMonthlyGamesResponse {
|
|
|
302
307
|
[G in Game]: ProcessedGame<Timeframe.Monthly, false>[G] | null;
|
|
303
308
|
};
|
|
304
309
|
}
|
|
310
|
+
export interface AvailableLeaderboard {
|
|
311
|
+
month: string;
|
|
312
|
+
year: string;
|
|
313
|
+
month_number: number;
|
|
314
|
+
resource: string;
|
|
315
|
+
}
|
|
316
|
+
export type AvailableLeaderboardResponse = AvailableLeaderboard[];
|
package/lib/processors/game.js
CHANGED
|
@@ -24,6 +24,7 @@ exports.calculateKDR = calculateKDR;
|
|
|
24
24
|
exports.calculateWinPercentage = calculateWinPercentage;
|
|
25
25
|
exports.calculateLosses = calculateLosses;
|
|
26
26
|
exports.calculateTotal = calculateTotal;
|
|
27
|
+
exports.calculateKPG = calculateKPG;
|
|
27
28
|
exports.roundTo = roundTo;
|
|
28
29
|
var hive_bedrock_data_1 = require("hive-bedrock-data");
|
|
29
30
|
function processGame(game, timeframe, isLeaderboard, response) {
|
|
@@ -35,15 +36,17 @@ function processGame(game, timeframe, isLeaderboard, response) {
|
|
|
35
36
|
if (Array.isArray(response))
|
|
36
37
|
return null;
|
|
37
38
|
var data = exports.processors[game](response);
|
|
38
|
-
if (
|
|
39
|
+
if (!data)
|
|
40
|
+
return null;
|
|
41
|
+
if ("played" in data && data.played === 0 && "xp" in data && data.xp === 0)
|
|
39
42
|
return null;
|
|
40
43
|
if (timeframe === hive_bedrock_data_1.Timeframe.AllTime && "xp" in data)
|
|
41
44
|
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
|
|
45
|
+
if (timeframe === hive_bedrock_data_1.Timeframe.AllTime && "first_played" in response)
|
|
43
46
|
data.first_played = response.first_played;
|
|
44
|
-
if (isLeaderboard && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
|
|
47
|
+
if ((isLeaderboard || timeframe !== hive_bedrock_data_1.Timeframe.AllTime) && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
|
|
45
48
|
data.position = response.human_index;
|
|
46
|
-
if (isLeaderboard && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
|
|
49
|
+
if ((isLeaderboard || timeframe !== hive_bedrock_data_1.Timeframe.AllTime) && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
|
|
47
50
|
data.username = response.username;
|
|
48
51
|
if (isLeaderboard && data.id !== hive_bedrock_data_1.Game.ParkourWorlds)
|
|
49
52
|
data.UUID = response.UUID;
|
|
@@ -158,10 +161,10 @@ exports.processors = (_a = {},
|
|
|
158
161
|
projectiles_fired: (_h = response.projectiles_fired) !== null && _h !== void 0 ? _h : 0,
|
|
159
162
|
});
|
|
160
163
|
},
|
|
161
|
-
_a[hive_bedrock_data_1.Game.
|
|
164
|
+
_a[hive_bedrock_data_1.Game.BuildBattle] = function (response) {
|
|
162
165
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
163
166
|
return ({
|
|
164
|
-
id: hive_bedrock_data_1.Game.
|
|
167
|
+
id: hive_bedrock_data_1.Game.BuildBattle,
|
|
165
168
|
xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
|
|
166
169
|
played: (_b = response.played) !== null && _b !== void 0 ? _b : 0,
|
|
167
170
|
victories: (_c = response.victories) !== null && _c !== void 0 ? _c : 0,
|
|
@@ -192,7 +195,7 @@ exports.processors = (_a = {},
|
|
|
192
195
|
win_percentage: calculateWinPercentage(response.victories, response.played),
|
|
193
196
|
deaths: (_d = response.deaths) !== null && _d !== void 0 ? _d : 0,
|
|
194
197
|
hider_kills: (_e = response.hider_kills) !== null && _e !== void 0 ? _e : 0,
|
|
195
|
-
|
|
198
|
+
kpg: calculateKPG(response.hider_kills, response.played),
|
|
196
199
|
seeker_kills: (_f = response.seeker_kills) !== null && _f !== void 0 ? _f : 0,
|
|
197
200
|
});
|
|
198
201
|
},
|
|
@@ -207,14 +210,14 @@ exports.processors = (_a = {},
|
|
|
207
210
|
win_percentage: calculateWinPercentage(response.victories, response.played),
|
|
208
211
|
murders: (_d = response.murders) !== null && _d !== void 0 ? _d : 0,
|
|
209
212
|
deaths: (_e = response.deaths) !== null && _e !== void 0 ? _e : 0,
|
|
210
|
-
|
|
213
|
+
edr: calculateKDR(response.murderer_eliminations, response.deaths),
|
|
211
214
|
coins: (_f = response.coins) !== null && _f !== void 0 ? _f : 0,
|
|
212
215
|
murderer_eliminations: (_g = response.murderer_eliminations) !== null && _g !== void 0 ? _g : 0,
|
|
213
216
|
prestige: (_h = response.prestige) !== null && _h !== void 0 ? _h : 0,
|
|
214
217
|
});
|
|
215
218
|
},
|
|
216
219
|
_a[hive_bedrock_data_1.Game.SkyWars] = function (response) {
|
|
217
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
220
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
218
221
|
return ({
|
|
219
222
|
id: hive_bedrock_data_1.Game.SkyWars,
|
|
220
223
|
xp: (_a = response.xp) !== null && _a !== void 0 ? _a : 0,
|
|
@@ -228,6 +231,7 @@ exports.processors = (_a = {},
|
|
|
228
231
|
mystery_chests_destroyed: (_f = response.mystery_chests_destroyed) !== null && _f !== void 0 ? _f : 0,
|
|
229
232
|
ores_mined: (_g = response.ores_mined) !== null && _g !== void 0 ? _g : 0,
|
|
230
233
|
spells_used: (_h = response.spells_used) !== null && _h !== void 0 ? _h : 0,
|
|
234
|
+
prestige: (_j = response.prestige) !== null && _j !== void 0 ? _j : 0,
|
|
231
235
|
});
|
|
232
236
|
},
|
|
233
237
|
_a[hive_bedrock_data_1.Game.SkyWarsKits] = function (response) {
|
|
@@ -317,49 +321,51 @@ exports.processors = (_a = {},
|
|
|
317
321
|
},
|
|
318
322
|
_a[hive_bedrock_data_1.Game.ParkourWorlds] = function (response) {
|
|
319
323
|
var _a;
|
|
320
|
-
return
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
.
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
.
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
324
|
+
return response.parkours
|
|
325
|
+
? {
|
|
326
|
+
id: hive_bedrock_data_1.Game.ParkourWorlds,
|
|
327
|
+
worlds: Object.entries(response.parkours)
|
|
328
|
+
.filter(function (_a) {
|
|
329
|
+
var _b = __read(_a, 2), _ = _b[0], value = _b[1];
|
|
330
|
+
return typeof value === "object";
|
|
331
|
+
})
|
|
332
|
+
.map(function (_a) {
|
|
333
|
+
var _b;
|
|
334
|
+
var _c = __read(_a, 2), key = _c[0], value = _c[1];
|
|
335
|
+
return ({
|
|
336
|
+
name: key,
|
|
337
|
+
parkour_stars: (_b = value.parkour_stars) !== null && _b !== void 0 ? _b : 0,
|
|
338
|
+
courses: Object.entries(value)
|
|
339
|
+
.filter(function (_a) {
|
|
340
|
+
var _b = __read(_a, 2), _ = _b[0], value = _b[1];
|
|
341
|
+
return typeof value === "object";
|
|
342
|
+
})
|
|
343
|
+
.map(function (_a) {
|
|
344
|
+
var _b;
|
|
345
|
+
var _c = __read(_a, 2), key = _c[0], value = _c[1];
|
|
346
|
+
return ({
|
|
347
|
+
name: key,
|
|
348
|
+
best_run_time: value.best_run_time,
|
|
349
|
+
best_checkpoint_times: Object.entries(value.best_checkpoint_times).map(function (_a) {
|
|
350
|
+
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
351
|
+
return ({
|
|
352
|
+
position: { x: Number(key.split(",")[0]), y: Number(key.split(",")[1]), z: Number(key.split(",")[2]) },
|
|
353
|
+
time: value,
|
|
354
|
+
});
|
|
355
|
+
}),
|
|
356
|
+
collected_stars: value.collected_stars.map(function (value) { return ({
|
|
357
|
+
x: Number(value.split(",")[0]),
|
|
358
|
+
y: Number(value.split(",")[1]),
|
|
359
|
+
z: Number(value.split(",")[2]),
|
|
360
|
+
}); }),
|
|
361
|
+
course_stars: (_b = value.course_stars) !== null && _b !== void 0 ? _b : 0,
|
|
362
|
+
});
|
|
363
|
+
}),
|
|
364
|
+
});
|
|
365
|
+
}),
|
|
366
|
+
total_stars: (_a = response.parkours.total_stars) !== null && _a !== void 0 ? _a : 0,
|
|
367
|
+
}
|
|
368
|
+
: null;
|
|
363
369
|
},
|
|
364
370
|
_a);
|
|
365
371
|
function validateNumber(value, def) {
|
|
@@ -384,6 +390,11 @@ function calculateLosses(played, victories) {
|
|
|
384
390
|
function calculateTotal(values) {
|
|
385
391
|
return validateNumber(values.reduce(function (a, b) { return (a !== null && a !== void 0 ? a : 0) + (b !== null && b !== void 0 ? b : 0); }, 0));
|
|
386
392
|
}
|
|
393
|
+
function calculateKPG(kills, games) {
|
|
394
|
+
if (games === 0)
|
|
395
|
+
return validateNumber(kills !== null && kills !== void 0 ? kills : 0);
|
|
396
|
+
return roundTo(validateNumber((kills !== null && kills !== void 0 ? kills : 0) / (games !== null && games !== void 0 ? games : 0)), 2);
|
|
397
|
+
}
|
|
387
398
|
function roundTo(value, places) {
|
|
388
399
|
if (places === void 0) { places = 2; }
|
|
389
400
|
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:
|
|
17
|
-
avatar:
|
|
18
|
-
|
|
19
|
-
|
|
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:
|
|
27
|
-
avatar:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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;
|
package/lib/processors/player.js
CHANGED
|
@@ -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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hive-bedrock-api",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.30",
|
|
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.
|
|
14
|
+
"hive-bedrock-data": "^2.0.0-alpha.17"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsc"
|