hypixel-api-reborn 11.1.0 → 11.2.0

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 (93) hide show
  1. package/.prettierrc +3 -3
  2. package/README.md +5 -3
  3. package/package.json +20 -18
  4. package/src/API/getAchievements.js +6 -0
  5. package/src/API/getChallenges.js +6 -0
  6. package/src/API/getGuild.js +1 -1
  7. package/src/API/getGuildAchievements.js +6 -0
  8. package/src/API/getLeaderboards.js +3 -1
  9. package/src/API/getPlayer.js +1 -1
  10. package/src/API/getQuests.js +6 -0
  11. package/src/API/getRecentGames.js +1 -1
  12. package/src/API/getServerInfo.js +3 -1
  13. package/src/API/getStatus.js +1 -1
  14. package/src/API/index.js +28 -17
  15. package/src/API/skyblock/getAuction.js +19 -0
  16. package/src/API/skyblock/{getSkyblockAuctions.js → getAuctions.js} +6 -2
  17. package/src/API/skyblock/{getSkyblockAuctionsByPlayer.js → getAuctionsByPlayer.js} +1 -1
  18. package/src/API/skyblock/getBingo.js +8 -0
  19. package/src/API/skyblock/getBingoByPlayer.js +14 -0
  20. package/src/API/skyblock/getFireSales.js +7 -0
  21. package/src/API/skyblock/getGovernment.js +8 -0
  22. package/src/API/skyblock/{getSkyblockMember.js → getMember.js} +9 -3
  23. package/src/API/skyblock/getMuseum.js +14 -0
  24. package/src/API/skyblock/{getSkyblockProfiles.js → getProfiles.js} +13 -7
  25. package/src/Client.js +88 -14
  26. package/src/Errors.js +38 -17
  27. package/src/Private/rateLimit.js +10 -2
  28. package/src/Private/requests.js +19 -7
  29. package/src/Private/updater.js +9 -5
  30. package/src/Private/uuidCache.js +23 -29
  31. package/src/Private/validate.js +20 -9
  32. package/src/index.js +9 -0
  33. package/src/structures/APIIncident.js +3 -9
  34. package/src/structures/Boosters/Booster.js +5 -5
  35. package/src/structures/Color.js +93 -48
  36. package/src/structures/Game.js +3 -1
  37. package/src/structures/Guild/Guild.js +21 -17
  38. package/src/structures/Guild/GuildMember.js +6 -6
  39. package/src/structures/Guild/GuildRank.js +2 -2
  40. package/src/structures/MiniGames/Arcade.js +22 -17
  41. package/src/structures/MiniGames/BedWars.js +152 -24
  42. package/src/structures/MiniGames/Duels.js +84 -23
  43. package/src/structures/MiniGames/MegaWalls.js +3 -1
  44. package/src/structures/MiniGames/MurderMystery.js +2 -2
  45. package/src/structures/MiniGames/Pit.js +231 -2
  46. package/src/structures/MiniGames/PitInventoryItem.js +43 -0
  47. package/src/structures/MiniGames/SkyWars.js +19 -14
  48. package/src/structures/MiniGames/SmashHeroes.js +1 -1
  49. package/src/structures/MiniGames/TNTGames.js +1 -1
  50. package/src/structures/MiniGames/UHC.js +21 -3
  51. package/src/structures/Player.js +16 -20
  52. package/src/structures/PlayerCosmetics.js +64 -10
  53. package/src/structures/ServerInfo.js +1 -1
  54. package/src/structures/SkyBlock/Auctions/Auction.js +3 -1
  55. package/src/structures/SkyBlock/Auctions/AuctionInfo.js +1 -0
  56. package/src/structures/SkyBlock/Auctions/BaseAuction.js +1 -0
  57. package/src/structures/SkyBlock/Auctions/Bid.js +1 -0
  58. package/src/structures/SkyBlock/Auctions/PartialAuction.js +1 -0
  59. package/src/structures/SkyBlock/PlayerBingo.js +56 -0
  60. package/src/structures/SkyBlock/SkyblockInventoryItem.js +86 -18
  61. package/src/structures/SkyBlock/SkyblockMember.js +252 -144
  62. package/src/structures/SkyBlock/SkyblockMuseum.js +60 -0
  63. package/src/structures/SkyBlock/SkyblockMuseumItem.js +54 -0
  64. package/src/structures/SkyBlock/SkyblockPet.js +1 -0
  65. package/src/structures/SkyBlock/SkyblockProfile.js +37 -23
  66. package/src/structures/SkyBlock/Static/Bingo.js +102 -0
  67. package/src/structures/SkyBlock/Static/BingoData.js +45 -0
  68. package/src/structures/SkyBlock/Static/Candidate.js +40 -0
  69. package/src/structures/SkyBlock/Static/FireSale.js +55 -0
  70. package/src/structures/SkyBlock/Static/Government.js +74 -0
  71. package/src/structures/SkyBlock/Static/Perk.js +24 -0
  72. package/src/structures/Static/Achievement.js +86 -0
  73. package/src/structures/Static/AchievementTier.js +33 -0
  74. package/src/structures/Static/Achievements.js +30 -0
  75. package/src/structures/Static/Challenges.js +29 -0
  76. package/src/structures/Static/GameAchievements.js +36 -0
  77. package/src/structures/Static/GameChallenges.js +40 -0
  78. package/src/structures/Static/GameQuests.js +24 -0
  79. package/src/structures/Static/GuildAchievements.js +34 -0
  80. package/src/structures/Static/Quest.js +66 -0
  81. package/src/structures/Static/Quests.js +31 -0
  82. package/src/structures/Status.js +2 -2
  83. package/src/utils/Constants.js +382 -41
  84. package/src/utils/SkyblockUtils.js +12 -7
  85. package/src/utils/guildExp.js +4 -1
  86. package/src/utils/removeSnakeCase.js +9 -2
  87. package/src/utils/romanize.js +32 -1
  88. package/src/utils/toIGN.js +6 -2
  89. package/src/utils/toUuid.js +10 -5
  90. package/typings/index.d.ts +985 -295
  91. /package/src/API/skyblock/{getSkyblockBazaar.js → getBazaar.js} +0 -0
  92. /package/src/API/skyblock/{getEndedSkyblockAuctions.js → getEndedAuctions.js} +0 -0
  93. /package/src/API/skyblock/{getSkyblockNews.js → getNews.js} +0 -0
@@ -66,7 +66,9 @@ class MegaWalls {
66
66
  * Final deaths
67
67
  * @type {number}
68
68
  */
69
- this.finalDeaths = isNaN((data.final_deaths || 0) + (data.finalDeaths || 0)) ? 0 : Math.floor((data.final_deaths || 0) + (data.finalDeaths || 0));
69
+ this.finalDeaths = isNaN((data.final_deaths || 0) + (data.finalDeaths || 0))
70
+ ? 0
71
+ : Math.floor((data.final_deaths || 0) + (data.finalDeaths || 0));
70
72
  /**
71
73
  * Final Kill Death ratio
72
74
  * @type {number}
@@ -8,10 +8,10 @@ class MurderMystery {
8
8
  */
9
9
  constructor(data) {
10
10
  /**
11
- * Coins
11
+ * Tokens
12
12
  * @type {number}
13
13
  */
14
- this.coins = data.coins || 0;
14
+ this.tokens = data.coins || 0;
15
15
  /**
16
16
  * Played games
17
17
  * @type {number}
@@ -1,4 +1,10 @@
1
- /* eslint-disable max-len */
1
+ const { decode } = require('../../utils/SkyblockUtils');
2
+ const PitInventoryItem = require('./PitInventoryItem');
3
+ const { divide } = require('../../utils');
4
+ const {
5
+ pit: { Levels, Prestiges }
6
+ } = require('../../utils/Constants');
7
+
2
8
  /**
3
9
  * Pit Class
4
10
  */
@@ -8,12 +14,235 @@ class Pit {
8
14
  * @param {Record<string,unknown>} data Data from API
9
15
  */
10
16
  constructor(data) {
17
+ const stats = data.pit_stats_ptl || {};
18
+ /**
19
+ * Prestige
20
+ * @type {number}
21
+ */
22
+ this.prestige = data.profile?.prestiges?.[data.profile?.prestiges?.length - 1].index || 0;
23
+ /**
24
+ * Xp
25
+ * @type {number}
26
+ */
27
+ this.xp = data.profile?.xp || 0;
28
+ /**
29
+ * Level
30
+ * @type {number}
31
+ */
32
+ this.level =
33
+ Pit.calcLevel(this.prestige, this.prestige > 0 ? this.xp - Prestiges[this.prestige - 1].SumXp : this.xp).level ??
34
+ 0;
11
35
  /**
12
36
  * Kills
13
37
  * @type {number}
14
38
  */
15
- this.kills = data.pit_stats_ptl.kills || 0;
39
+ this.kills = stats.kills || 0;
40
+ /**
41
+ * Deaths
42
+ * @type {number}
43
+ */
44
+ this.deaths = stats.deaths || 0;
45
+ /**
46
+ * KDR
47
+ * @type {number}
48
+ */
49
+ this.KDRatio = divide(this.kills, this.deaths);
50
+ /**
51
+ * Assists
52
+ * @type {number}
53
+ */
54
+ this.assists = stats.assists || 0;
55
+ /**
56
+ * Max kill streak
57
+ * @type {number}
58
+ */
59
+ this.maxKillStreak = stats.max_streak || 0;
60
+ /**
61
+ * Playtime in SECONDS
62
+ * @type {number}
63
+ */
64
+ this.playtime = (stats.playtime_minutes || 0) * 60;
65
+ /**
66
+ * Times the played joined Pit
67
+ * @type {number}
68
+ */
69
+ this.joins = stats.joins || 0;
70
+
71
+ // Damage section (overall)
72
+ /**
73
+ * Damage received overall
74
+ * @type {number}
75
+ */
76
+ this.damageReceived = stats.damage_received || 0;
77
+ /**
78
+ * Damage dealt overall
79
+ * @type {number}
80
+ */
81
+ this.damageDealt = stats.damage_dealt || 0;
82
+ /**
83
+ * Damage dealt to damage received ratio
84
+ * @type {number}
85
+ */
86
+ this.damageRatio = divide(this.damageDealt, this.damageReceived);
87
+ // Melee damage
88
+ /**
89
+ * Damage received in melee
90
+ * @type {number}
91
+ */
92
+ this.meleeDamageReceived = stats.melee_damage_received || 0;
93
+ /**
94
+ * Damage dealt in melee
95
+ * @type {number}
96
+ */
97
+ this.meleeDamageDealt = stats.melee_damage_dealt || 0;
98
+ /**
99
+ * Sword hits
100
+ * @type {number}
101
+ */
102
+ this.swordHits = stats.sword_hits || 0;
103
+ /**
104
+ * Left Clicks (sword clicks, hit or miss)
105
+ * @type {number}
106
+ */
107
+ this.leftClicks = stats.left_clicks || 0;
108
+ /**
109
+ * Hits divided by left clicks
110
+ * @type {number}
111
+ */
112
+ this.meleeAccuracy = divide(this.swordHits, this.leftClicks);
113
+ /**
114
+ * Damage dealt to damage received ratio in melee
115
+ * @type {number}
116
+ */
117
+ this.meleeDamageRatio = divide(this.meleeDamageDealt, this.meleeDamageReceived);
118
+ // Arrow damage
119
+ /**
120
+ * Damage received by arrow
121
+ * @type {number}
122
+ */
123
+ this.bowDamageReceived = stats.bow_damage_received || 0;
124
+ /**
125
+ * Damage dealt with bow
126
+ * @type {number}
127
+ */
128
+ this.bowDamageDealt = stats.bow_damage_dealt || 0;
129
+ /**
130
+ * Arrows hit
131
+ * @type {number}
132
+ */
133
+ this.arrowsHit = stats.arrow_hits || 0;
134
+ /**
135
+ * Arrows fired (hit + missed)
136
+ * @type {number}
137
+ */
138
+ this.arrowsFired = stats.arrows_fired || 0;
139
+ /**
140
+ * Hit divided by Fired
141
+ * @type {number}
142
+ */
143
+ this.bowAccuracy = divide(this.arrowsHit, this.arrowsFired);
144
+ /**
145
+ * Damage dealt to damage received ratio in ranged (bow/arrow)
146
+ * @type {number}
147
+ */
148
+ this.bowDamageRatio = divide(this.bowDamageDealt, this.bowDamageReceived);
149
+ /**
150
+ * Golden Heads eaten
151
+ * @type {number}
152
+ */
153
+ this.goldenHeadsEaten = stats.ghead_eaten || 0;
154
+ /**
155
+ * Pit Player Inv
156
+ * @return {Promise<PitInventoryItem[]>}
157
+ */
158
+ this.getInventory = async () => {
159
+ let inventory = data.profile.inv_contents;
160
+ if (!inventory) return [];
161
+
162
+ try {
163
+ inventory = await decode(inventory.data);
164
+ const edited = [];
165
+ for (let i = 1; i < inventory.length; i++) {
166
+ if (!inventory[i].id) {
167
+ continue;
168
+ }
169
+ edited.push(new PitInventoryItem(inventory[i]));
170
+ }
171
+ return edited;
172
+ } catch (e) {
173
+ return [];
174
+ }
175
+ };
176
+ /**
177
+ * Pit Player Ender Chest
178
+ * @return {Promise<PitInventoryItem[]>}
179
+ */
180
+ this.getEnterChest = async () => {
181
+ let chest = data.profile.inv_enderchest;
182
+ if (!chest) return [];
183
+
184
+ try {
185
+ chest = await decode(chest.data);
186
+ const edited = [];
187
+ for (let i = 1; i < chest.length; i++) {
188
+ if (!chest[i].id) {
189
+ continue;
190
+ }
191
+ edited.push(new PitInventoryItem(chest[i]));
192
+ }
193
+ return edited;
194
+ } catch (e) {
195
+ return [];
196
+ }
197
+ };
198
+ /**
199
+ * Pit Player Armor
200
+ * @return {Promise<PitArmor>}
201
+ */
202
+ this.getArmor = async () => {
203
+ const base64 = data.profile.inv_armor;
204
+ const decoded = await decode(base64.data);
205
+ const armor = {
206
+ helmet: decoded[3].id ? new PitInventoryItem(decoded[3]) : null,
207
+ chestplate: decoded[2].id ? new PitInventoryItem(decoded[2]) : null,
208
+ leggings: decoded[1].id ? new PitInventoryItem(decoded[1]) : null,
209
+ boots: decoded[0].id ? new PitInventoryItem(decoded[0]) : null
210
+ };
211
+ return armor;
212
+ };
213
+ }
214
+ // Credit https://github.com/PitPanda/PitPandaProduction/blob/b1971f56ea1aa8c829b722cbb33247c96591c0cb/structures/Pit.js
215
+ /**
216
+ * Converts XP to Level
217
+ * @param {number} prestige Prestige Level
218
+ * @param {number} xp Current xp into the prestige
219
+ * @return {number}
220
+ */
221
+ static calcLevel(prestige, xp) {
222
+ const multiplier = Prestiges[prestige].Multiplier;
223
+ let level = 0;
224
+ while (xp > 0 && level < 120) {
225
+ const levelXp = Levels[Math.floor(level / 10)].Xp * multiplier;
226
+ if (xp >= levelXp * 10) {
227
+ xp -= levelXp * 10;
228
+ level += 10;
229
+ } else {
230
+ const gain = Math.floor(xp / levelXp);
231
+ level += gain;
232
+ xp -= gain * levelXp;
233
+ xp = 0;
234
+ }
235
+ }
236
+ return level;
16
237
  }
17
238
  }
18
239
 
240
+ /**
241
+ * @typedef {object} PitArmor Equipped armor
242
+ * @property {PitInventoryItem|null} helmet Helmet
243
+ * @property {PitInventoryItem|null} chestplate Chestplate
244
+ * @property {PitInventoryItem|null} leggings Leggings
245
+ * @property {PitInventoryItem|null} boots Boots
246
+ */
247
+
19
248
  module.exports = Pit;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Item class
3
+ */
4
+ class PitInventoryItem {
5
+ /**
6
+ * @param {object} data Item data
7
+ */
8
+ constructor(data) {
9
+ /**
10
+ * Item ID
11
+ * @type {number}
12
+ */
13
+ this.itemId = data.id || 0;
14
+ /**
15
+ * Item count
16
+ * @type {number}
17
+ */
18
+ this.count = data.Count || 0;
19
+ /**
20
+ * Item name
21
+ * @type {string|null}
22
+ */
23
+ this.name = data?.tag?.display?.Name ? data.tag.display.Name.toString().replace(/§([1-9]|[a-f])|§/gm, '') : null;
24
+ /**
25
+ * Item lore
26
+ * @type {string|null}
27
+ */
28
+ this.lore = data?.tag?.display?.Lore ? data.tag.display.Lore.join('\n') : null;
29
+ /**
30
+ * Item lore
31
+ * @type {string[]}
32
+ */
33
+ this.loreArray = data?.tag?.display?.Lore ?? [];
34
+ /**
35
+ * Item Extra Attributes
36
+ * @type {object|null}
37
+ */
38
+
39
+ this.extraAttributes = data?.tag?.ExtraAttributes ?? null;
40
+ }
41
+ }
42
+
43
+ module.exports = PitInventoryItem;
@@ -59,16 +59,6 @@ class SkyWars {
59
59
  * @type {number}
60
60
  */
61
61
  this.wins = data.wins || 0;
62
- /**
63
- * Loot Chests
64
- * @type {number}
65
- */
66
- this.lootChests = data.skywars_chests || 0;
67
- /**
68
- * Opened Loot Chests
69
- * @type {number}
70
- */
71
- this.openedLootChests = data.SkyWars_openedChests || 0;
72
62
  /**
73
63
  * Heads
74
64
  * @type {number}
@@ -113,7 +103,12 @@ class SkyWars {
113
103
  * Games Played ( Total )
114
104
  * @type {number}
115
105
  */
116
- this.playedGames = (data.games_solo || 0) + (data.games_team || 0) + (data.games_mega || 0) + (data.games_mega_doubles || 0) + (data.games_lab || 0);
106
+ this.playedGames =
107
+ (data.games_solo || 0) +
108
+ (data.games_team || 0) +
109
+ (data.games_mega || 0) +
110
+ (data.games_mega_doubles || 0) +
111
+ (data.games_lab || 0);
117
112
  /**
118
113
  * Global Kill Death Ratio
119
114
  * @type {number}
@@ -207,8 +202,14 @@ class SkyWars {
207
202
  wins: (data.wins_mega || 0) + (data.wins_mega_doubles || 0),
208
203
  losses: (data.losses_mega || 0) + (data.losses_mega_doubles || 0),
209
204
  deaths: (data.deaths_mega || 0) + (data.deaths_mega_doubles || 0),
210
- KDRatio: divide((data.kills_mega || 0) + (data.kills_mega_doubles || 0), (data.deaths_mega || 0) + (data.deaths_mega_doubles || 0)),
211
- WLRatio: divide((data.wins_mega || 0) + (data.wins_mega_doubles || 0), (data.losses_mega || 0) + (data.losses_mega_doubles || 0))
205
+ KDRatio: divide(
206
+ (data.kills_mega || 0) + (data.kills_mega_doubles || 0),
207
+ (data.deaths_mega || 0) + (data.deaths_mega_doubles || 0)
208
+ ),
209
+ WLRatio: divide(
210
+ (data.wins_mega || 0) + (data.wins_mega_doubles || 0),
211
+ (data.losses_mega || 0) + (data.losses_mega_doubles || 0)
212
+ )
212
213
  },
213
214
  solo: {
214
215
  playedGames: data.games_mega || 0,
@@ -333,7 +334,11 @@ module.exports = SkyWars;
333
334
  // eslint-disable-next-line require-jsdoc
334
335
  function getSkyWarsPrestige(level) {
335
336
  if (level >= 60) return 'Mythic';
336
- return ['Iron', 'Iron', 'Gold', 'Diamond', 'Emerald', 'Sapphire', 'Ruby', 'Crystal', 'Opal', 'Amethyst', 'Rainbow'][Math.floor(level / 5)] || 'Iron';
337
+ return (
338
+ ['Iron', 'Iron', 'Gold', 'Diamond', 'Emerald', 'Sapphire', 'Ruby', 'Crystal', 'Opal', 'Amethyst', 'Rainbow'][
339
+ Math.floor(level / 5)
340
+ ] || 'Iron'
341
+ );
337
342
  }
338
343
  // eslint-disable-next-line require-jsdoc
339
344
  function getSkyWarsLevel(xp) {
@@ -70,7 +70,7 @@ class SmashHeroes {
70
70
  * Active class
71
71
  * @type {string}
72
72
  */
73
- this.activeClass = data.active_class ? data.active_class : null;
73
+ this.activeClass = data.active_class ?? null;
74
74
  /**
75
75
  * Stats for each class
76
76
  * @type {SmashHeroesClassStats[]|null}
@@ -67,7 +67,7 @@ class TNTGames {
67
67
  */
68
68
  this.wizards = {
69
69
  points: data.points_capture || 0,
70
- class: data.capture_class ? data.capture_class : null,
70
+ class: data.capture_class ?? null,
71
71
  kills: data.kills_capture || 0,
72
72
  assists: data.assists_capture || 0,
73
73
  wins: data.wins_capture || 0,
@@ -52,7 +52,13 @@ class UHC {
52
52
  * @type {number}
53
53
  */
54
54
  this.wins =
55
- (data.wins || 0) + (data.wins_solo || 0) + (data['wins_red vs blue'] || 0) + (data['wins_no diamonds'] || 0) + (data.wins_brawl || 0) + (data['wins_solo brawl'] || 0) + (data['wins_duo brawl'] || 0);
55
+ (data.wins || 0) +
56
+ (data.wins_solo || 0) +
57
+ (data['wins_red vs blue'] || 0) +
58
+ (data['wins_no diamonds'] || 0) +
59
+ (data.wins_brawl || 0) +
60
+ (data['wins_solo brawl'] || 0) +
61
+ (data['wins_duo brawl'] || 0);
56
62
  /**
57
63
  * Heads eaten
58
64
  * @type {number}
@@ -145,9 +151,21 @@ class UHC {
145
151
  // eslint-disable-next-line require-jsdoc
146
152
  function getStarLevel(data) {
147
153
  const kills =
148
- (data.kills || 0) + (data.kills_solo || 0) + (data['kills_red vs blue'] || 0) + (data['kills_no diamonds'] || 0) + (data.kills_brawl || 0) + (data['kills_solo brawl'] || 0) + (data['kills_duo brawl'] || 0);
154
+ (data.kills || 0) +
155
+ (data.kills_solo || 0) +
156
+ (data['kills_red vs blue'] || 0) +
157
+ (data['kills_no diamonds'] || 0) +
158
+ (data.kills_brawl || 0) +
159
+ (data['kills_solo brawl'] || 0) +
160
+ (data['kills_duo brawl'] || 0);
149
161
  const wins =
150
- (data.wins || 0) + (data.wins_solo || 0) + (data['wins_red vs blue'] || 0) + (data['wins_no diamonds'] || 0) + (data.wins_brawl || 0) + (data['wins_solo brawl'] || 0) + (data['wins_duo brawl'] || 0);
162
+ (data.wins || 0) +
163
+ (data.wins_solo || 0) +
164
+ (data['wins_red vs blue'] || 0) +
165
+ (data['wins_no diamonds'] || 0) +
166
+ (data.wins_brawl || 0) +
167
+ (data['wins_solo brawl'] || 0) +
168
+ (data['wins_duo brawl'] || 0);
151
169
  const sum = kills * 1 + wins * 10;
152
170
  let starLevel = 1;
153
171
  const sums = [0, 1, 6, 21, 46, 96, 171, 271, 521, 1021, 1321, 1621, 1921, 2221, 2521, Infinity];
@@ -13,8 +13,6 @@ const VampireZ = require('./MiniGames/VampireZ');
13
13
  const BlitzSurvivalGames = require('./MiniGames/BlitzSurvivalGames');
14
14
  const ArenaBrawl = require('./MiniGames/ArenaBrawl');
15
15
  const Arcade = require('./MiniGames/Arcade');
16
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
17
- const Pit = require('./MiniGames/Pit');
18
16
  const Color = require('./Color');
19
17
  const Game = require('./Game');
20
18
  const PlayerCosmetics = require('./PlayerCosmetics');
@@ -25,6 +23,7 @@ const Quakecraft = require('./MiniGames/Quakecraft');
25
23
  const Walls = require('./MiniGames/Walls');
26
24
  const Warlords = require('./MiniGames/Warlords');
27
25
  const WoolWars = require('./MiniGames/WoolWars');
26
+ const Pit = require('./MiniGames/Pit');
28
27
  /**
29
28
  * Player class
30
29
  */
@@ -44,21 +43,11 @@ class Player {
44
43
  * @type {string}
45
44
  */
46
45
  this.uuid = data.uuid;
47
- /**
48
- * Player nickname history known to Hypixel
49
- * @type {Array<string>}
50
- */
51
- this.history = data.knownAliases;
52
46
  /**
53
47
  * Player rank
54
48
  * @type {PlayerRank}
55
49
  */
56
50
  this.rank = getRank(data);
57
- /**
58
- * Player minecraft version
59
- * @type {string|null}
60
- */
61
- this.mcVersion = data.mcVersionRp || null;
62
51
  /**
63
52
  * Current chat channel, usually ALL, PARTY, or GUILD
64
53
  * @type {string|null}
@@ -75,12 +64,12 @@ class Player {
75
64
  */
76
65
  this.firstLogin = data.firstLogin ? new Date(data.firstLogin) : null;
77
66
  /**
78
- * Player's recently played game
67
+ * Timestamp when player last logged in as Date
79
68
  * @type {Game|null}
80
69
  */
81
70
  this.lastLoginTimestamp = data.lastLogin || null;
82
71
  /**
83
- * Timestamp when player first logged in
72
+ * Timestamp when player first logged in unix
84
73
  * @type {number|null}
85
74
  */
86
75
  this.lastLogin = data.lastLogin ? new Date(data.lastLogin) : null;
@@ -90,8 +79,8 @@ class Player {
90
79
  */
91
80
  this.lastLogoutTimestamp = data.lastLogout || null;
92
81
  /**
93
- * Timestamp when player first logged in as Date
94
- * @type {Date|null}
82
+ * Timestamp when player first logged in unix
83
+ * @type {number|null}
95
84
  */
96
85
  this.lastLogout = data.lastLogout ? new Date(data.lastLogout) : null;
97
86
  /**
@@ -103,12 +92,18 @@ class Player {
103
92
  * Player's plus color (must be a MVP+ rank)
104
93
  * @type {Color|null}
105
94
  */
106
- this.plusColor = this.rank === 'MVP+' || this.rank === 'MVP++' ? (data.rankPlusColor ? new Color(data.rankPlusColor) : new Color('RED')) : null;
95
+ this.plusColor =
96
+ this.rank === 'MVP+' || this.rank === 'MVP++'
97
+ ? data.rankPlusColor
98
+ ? new Color(data.rankPlusColor)
99
+ : new Color('RED')
100
+ : null;
107
101
  /**
108
102
  * MVP++ prefix color
109
103
  * @type {Color|null}
110
104
  */
111
- this.prefixColor = this.rank === 'MVP++' ? (data.monthlyRankColor ? new Color(data.monthlyRankColor) : new Color('GOLD')) : null;
105
+ this.prefixColor =
106
+ this.rank === 'MVP++' ? (data.monthlyRankColor ? new Color(data.monthlyRankColor) : new Color('GOLD')) : null;
112
107
  /**
113
108
  * Player karma
114
109
  * @type {number}
@@ -236,7 +231,7 @@ class Player {
236
231
  walls: data.stats.Walls ? new Walls(data.stats.Walls) : null,
237
232
  warlords: data.stats.Battleground ? new Warlords(data.stats.Battleground) : null,
238
233
  woolwars: data.stats.WoolGames ? new WoolWars(data.stats.WoolGames) : null,
239
- pit: null
234
+ pit: data.stats.Pit ? new Pit(data.stats.Pit) : null
240
235
  }
241
236
  : null;
242
237
  /**
@@ -348,8 +343,8 @@ function playerLevelProgress(player) {
348
343
  const percentRemaining = Math.round((100 - percent) * 100) / 100;
349
344
  return {
350
345
  xpToNext,
351
- currentXP,
352
346
  remainingXP,
347
+ currentXP,
353
348
  percent,
354
349
  percentRemaining
355
350
  };
@@ -413,6 +408,7 @@ function parseClaimedRewards(data) {
413
408
  * @property {BlitzSurvivalGames|null} blitzsg Blitz Survival Games
414
409
  * @property {ArenaBrawl|null} arena Arena Brawl
415
410
  * @property {Arcade|null} arcade Arcade
411
+ * @property {WoolWars|null} woolwars Wool Wars
416
412
  */
417
413
  /**
418
414
  * @typedef {Object} RanksPurchaseTime
@@ -12,7 +12,7 @@ class PlayerCosmetics {
12
12
  * All cosmetics
13
13
  * @type {string[]}
14
14
  */
15
- this.allCosmetics = data.vanityMeta ? data.vanityMeta.packages : undefined;
15
+ this.allCosmetics = data?.vanityMeta?.packages || undefined;
16
16
  /**
17
17
  * Pets
18
18
  * @type {Pets|null}
@@ -29,7 +29,13 @@ class PlayerCosmetics {
29
29
  * @type {string[]}
30
30
  */
31
31
  get suits() {
32
- if (!this._suits) this._suits = this.allCosmetics ? this.allCosmetics.filter((x) => x.startsWith('suit_')).map((x) => removeSnakeCaseString(x.replace('suit_', ''))) || [] : [];
32
+ if (!this._suits) {
33
+ this._suits = this.allCosmetics
34
+ ? this.allCosmetics
35
+ .filter((x) => x.startsWith('suit_'))
36
+ .map((x) => removeSnakeCaseString(x.replace('suit_', ''))) || []
37
+ : [];
38
+ }
33
39
  return this._suits;
34
40
  }
35
41
  /**
@@ -37,7 +43,13 @@ class PlayerCosmetics {
37
43
  * @type {string[]}
38
44
  */
39
45
  get hats() {
40
- if (!this._hats) this._hats = this.allCosmetics ? this.allCosmetics.filter((x) => x.startsWith('hat_')).map((x) => removeSnakeCaseString(x.replace('hat_', ''))) || [] : [];
46
+ if (!this._hats) {
47
+ this._hats = this.allCosmetics
48
+ ? this.allCosmetics
49
+ .filter((x) => x.startsWith('hat_'))
50
+ .map((x) => removeSnakeCaseString(x.replace('hat_', ''))) || []
51
+ : [];
52
+ }
41
53
  return this._hats;
42
54
  }
43
55
  /**
@@ -45,7 +57,13 @@ class PlayerCosmetics {
45
57
  * @type {string[]}
46
58
  */
47
59
  get gadgets() {
48
- if (!this._gadgets) this._gadgets = this.allCosmetics ? this.allCosmetics.filter((x) => x.startsWith('gadget_')).map((x) => removeSnakeCaseString(x.replace('gadget_', ''))) || [] : [];
60
+ if (!this._gadgets) {
61
+ this._gadgets = this.allCosmetics
62
+ ? this.allCosmetics
63
+ .filter((x) => x.startsWith('gadget_'))
64
+ .map((x) => removeSnakeCaseString(x.replace('gadget_', ''))) || []
65
+ : [];
66
+ }
49
67
  return this._gadgets;
50
68
  }
51
69
  /**
@@ -53,7 +71,13 @@ class PlayerCosmetics {
53
71
  * @type {string[]}
54
72
  */
55
73
  get morphs() {
56
- if (!this._morphs) this._morphs = this.allCosmetics ? this.allCosmetics.filter((x) => x.startsWith('morph_')).map((x) => removeSnakeCaseString(x.replace('morph_', ''))) || [] : [];
74
+ if (!this._morphs) {
75
+ this._morphs = this.allCosmetics
76
+ ? this.allCosmetics
77
+ .filter((x) => x.startsWith('morph_'))
78
+ .map((x) => removeSnakeCaseString(x.replace('morph_', ''))) || []
79
+ : [];
80
+ }
57
81
  return this._morphs;
58
82
  }
59
83
  /**
@@ -61,7 +85,13 @@ class PlayerCosmetics {
61
85
  * @type {string[]}
62
86
  */
63
87
  get cloaks() {
64
- if (!this._cloaks) this._cloaks = this.allCosmetics ? this.allCosmetics.filter((x) => x.startsWith('cloak_')).map((x) => removeSnakeCaseString(x.replace('cloak_', ''))) || [] : [];
88
+ if (!this._cloaks) {
89
+ this._cloaks = this.allCosmetics
90
+ ? this.allCosmetics
91
+ .filter((x) => x.startsWith('cloak_'))
92
+ .map((x) => removeSnakeCaseString(x.replace('cloak_', ''))) || []
93
+ : [];
94
+ }
65
95
  return this._cloaks;
66
96
  }
67
97
  /**
@@ -69,7 +99,13 @@ class PlayerCosmetics {
69
99
  * @type {string[]}
70
100
  */
71
101
  get taunts() {
72
- if (!this._taunts) this._taunts = this.allCosmetics ? this.allCosmetics.filter((x) => x.startsWith('taunt_')).map((x) => removeSnakeCaseString(x.replace('taunt_', ''))) || [] : [];
102
+ if (!this._taunts) {
103
+ this._taunts = this.allCosmetics
104
+ ? this.allCosmetics
105
+ .filter((x) => x.startsWith('taunt_'))
106
+ .map((x) => removeSnakeCaseString(x.replace('taunt_', ''))) || []
107
+ : [];
108
+ }
73
109
  return this._taunts;
74
110
  }
75
111
  /**
@@ -77,7 +113,13 @@ class PlayerCosmetics {
77
113
  * @type {string[]}
78
114
  */
79
115
  get rankColors() {
80
- if (!this._rankcolors) this._rankcolors = this.allCosmetics ? this.allCosmetics.filter((x) => x.startsWith('rankcolor_')).map((x) => removeSnakeCaseString(x.replace('rankcolor_', ''))) || [] : [];
116
+ if (!this._rankcolors) {
117
+ this._rankcolors = this.allCosmetics
118
+ ? this.allCosmetics
119
+ .filter((x) => x.startsWith('rankcolor_'))
120
+ .map((x) => removeSnakeCaseString(x.replace('rankcolor_', ''))) || []
121
+ : [];
122
+ }
81
123
  return this._rankcolors;
82
124
  }
83
125
  /**
@@ -85,7 +127,13 @@ class PlayerCosmetics {
85
127
  * @type {string[]}
86
128
  */
87
129
  get particlePacks() {
88
- if (!this._particle) this._particle = this.allCosmetics ? this.allCosmetics.filter((x) => x.startsWith('particlepack_')).map((x) => removeSnakeCaseString(x.replace('particlepack_', ''))) || [] : [];
130
+ if (!this._particle) {
131
+ this._particle = this.allCosmetics
132
+ ? this.allCosmetics
133
+ .filter((x) => x.startsWith('particlepack_'))
134
+ .map((x) => removeSnakeCaseString(x.replace('particlepack_', ''))) || []
135
+ : [];
136
+ }
89
137
  return this._particlepacks;
90
138
  }
91
139
  /**
@@ -93,7 +141,13 @@ class PlayerCosmetics {
93
141
  * @type {string[]}
94
142
  */
95
143
  get clickEffects() {
96
- if (!this._clickfx) this._clickfx = this.allCosmetics ? this.allCosmetics.filter((x) => x.startsWith('clickeffects_')).map((x) => removeSnakeCaseString(x.replace('clickeffects_', ''))) || [] : [];
144
+ if (!this._clickfx) {
145
+ this._clickfx = this.allCosmetics
146
+ ? this.allCosmetics
147
+ .filter((x) => x.startsWith('clickeffects_'))
148
+ .map((x) => removeSnakeCaseString(x.replace('clickeffects_', ''))) || []
149
+ : [];
150
+ }
97
151
  return this._clickfx;
98
152
  }
99
153
  }