diff options
-rw-r--r-- | build/cleaners/skyblock/inventory.js | 26 | ||||
-rw-r--r-- | src/cleaners/skyblock/inventory.ts | 22 | ||||
-rw-r--r-- | src/cleaners/skyblock/member.ts | 117 |
3 files changed, 102 insertions, 63 deletions
diff --git a/build/cleaners/skyblock/inventory.js b/build/cleaners/skyblock/inventory.js index c2bb3f6..0131e1b 100644 --- a/build/cleaners/skyblock/inventory.js +++ b/build/cleaners/skyblock/inventory.js @@ -25,7 +25,7 @@ function base64decode(base64) { return Buffer.from(base64, 'base64'); } function cleanItem(rawItem) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; // if the item doesn't have an id, it isn't an item if (rawItem.id === undefined) return null; @@ -34,21 +34,35 @@ function cleanItem(rawItem) { const damageValue = rawItem.Damage; const itemTag = rawItem.tag; const extraAttributes = (_a = itemTag === null || itemTag === void 0 ? void 0 : itemTag.ExtraAttributes) !== null && _a !== void 0 ? _a : {}; + let headId; + if (vanillaId === 397) { + const headDataBase64 = (_e = (_d = (_c = (_b = itemTag === null || itemTag === void 0 ? void 0 : itemTag.SkullOwner) === null || _b === void 0 ? void 0 : _b.Properties) === null || _c === void 0 ? void 0 : _c.textures) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.Value; + if ((extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.id) === 'LARGE_MINING_SACK') + console.log(headDataBase64); + if (headDataBase64) { + const headData = JSON.parse(base64decode(headDataBase64).toString()); + const headDataUrl = (_g = (_f = headData === null || headData === void 0 ? void 0 : headData.textures) === null || _f === void 0 ? void 0 : _f.SKIN) === null || _g === void 0 ? void 0 : _g.url; + if (headDataUrl) { + const splitUrl = headDataUrl.split('/'); + headId = splitUrl[splitUrl.length - 1]; + } + } + } return { - id: (_b = extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.id) !== null && _b !== void 0 ? _b : null, + id: (_h = extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.id) !== null && _h !== void 0 ? _h : null, count: itemCount !== null && itemCount !== void 0 ? itemCount : 1, vanillaId: damageValue ? `${vanillaId}:${damageValue}` : vanillaId.toString(), display: { - name: (_d = (_c = itemTag === null || itemTag === void 0 ? void 0 : itemTag.display) === null || _c === void 0 ? void 0 : _c.Name) !== null && _d !== void 0 ? _d : 'null', - lore: (_f = (_e = itemTag === null || itemTag === void 0 ? void 0 : itemTag.display) === null || _e === void 0 ? void 0 : _e.Lore) !== null && _f !== void 0 ? _f : [], + name: (_k = (_j = itemTag === null || itemTag === void 0 ? void 0 : itemTag.display) === null || _j === void 0 ? void 0 : _j.Name) !== null && _k !== void 0 ? _k : 'null', + lore: (_m = (_l = itemTag === null || itemTag === void 0 ? void 0 : itemTag.display) === null || _l === void 0 ? void 0 : _l.Lore) !== null && _m !== void 0 ? _m : [], // if it has an ench value in the tag, then it should have an enchant glint effect - glint: ((_g = itemTag === null || itemTag === void 0 ? void 0 : itemTag.ench) !== null && _g !== void 0 ? _g : []).length > 0 + glint: ((_o = itemTag === null || itemTag === void 0 ? void 0 : itemTag.ench) !== null && _o !== void 0 ? _o : []).length > 0 }, reforge: extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.modifier, enchantments: extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.enchantments, anvil_uses: extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.anvil_uses, timestamp: extraAttributes === null || extraAttributes === void 0 ? void 0 : extraAttributes.timestamp, - skull_owner: (_m = (_l = (_k = (_j = (_h = itemTag === null || itemTag === void 0 ? void 0 : itemTag.SkullOwner) === null || _h === void 0 ? void 0 : _h.Properties) === null || _j === void 0 ? void 0 : _j.textures) === null || _k === void 0 ? void 0 : _k[0]) === null || _l === void 0 ? void 0 : _l.value) !== null && _m !== void 0 ? _m : undefined, + head_texture: headId, }; } function cleanItems(rawItems) { diff --git a/src/cleaners/skyblock/inventory.ts b/src/cleaners/skyblock/inventory.ts index 76acf60..5d72928 100644 --- a/src/cleaners/skyblock/inventory.ts +++ b/src/cleaners/skyblock/inventory.ts @@ -20,7 +20,7 @@ interface Item { timestamp?: string enchantments?: { [ name: string ]: number } - skull_owner?: string + head_texture?: string } export type Inventory = Item[] @@ -34,6 +34,21 @@ function cleanItem(rawItem): Item { const damageValue = rawItem.Damage const itemTag = rawItem.tag const extraAttributes = itemTag?.ExtraAttributes ?? {} + let headId: string + + if (vanillaId === 397) { + const headDataBase64 = itemTag?.SkullOwner?.Properties?.textures?.[0]?.Value + if (extraAttributes?.id === 'LARGE_MINING_SACK') console.log(headDataBase64) + if (headDataBase64) { + const headData = JSON.parse(base64decode(headDataBase64).toString()) + const headDataUrl = headData?.textures?.SKIN?.url + if (headDataUrl) { + const splitUrl = headDataUrl.split('/') + headId = splitUrl[splitUrl.length - 1] + } + } + } + return { id: extraAttributes?.id ?? null, count: itemCount ?? 1, @@ -51,8 +66,7 @@ function cleanItem(rawItem): Item { anvil_uses: extraAttributes?.anvil_uses, timestamp: extraAttributes?.timestamp, - skull_owner: itemTag?.SkullOwner?.Properties?.textures?.[0]?.value ?? undefined, - + head_texture: headId, } } @@ -83,7 +97,7 @@ export const INVENTORIES = { wardrobe: 'wardrobe_contents' } -export type Inventories = { [name in keyof typeof INVENTORIES ]: Inventories } +export type Inventories = { [name in keyof typeof INVENTORIES ]: Item[] } export async function cleanInventories(data: any): Promise<Inventories> { const cleanInventories: any = {} diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index fe86e2e..fb8132f 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -15,79 +15,90 @@ import { CleanRank } from '../rank' import { Bank } from './bank' export interface CleanBasicMember { - uuid: string - username: string - last_save: number - first_join: number - rank: CleanRank + uuid: string + username: string + last_save: number + first_join: number + rank: CleanRank } export interface CleanMember extends CleanBasicMember { - purse: number - stats: StatItem[] - rawHypixelStats?: { [ key: string ]: number } - minions: CleanMinion[] + purse: number + stats: StatItem[] + rawHypixelStats?: { [ key: string ]: number } + minions: CleanMinion[] fairy_souls: FairySouls - inventories: Inventories - objectives: Objective[] - skills: Skill[] - visited_zones: Zone[] - collections: Collection[] - slayers: SlayerData + inventories: Inventories + objectives: Objective[] + skills: Skill[] + visited_zones: Zone[] + collections: Collection[] + slayers: SlayerData } export async function cleanSkyBlockProfileMemberResponseBasic(member: any, included: Included[] = null): Promise<CleanBasicMember> { - const player = await cached.fetchPlayer(member.uuid) - return { - uuid: member.uuid, - username: player.username, - last_save: member.last_save / 1000, - first_join: member.first_join / 1000, - rank: player.rank - } + const player = await cached.fetchPlayer(member.uuid) + return { + uuid: member.uuid, + username: player.username, + last_save: member.last_save / 1000, + first_join: member.first_join / 1000, + rank: player.rank + } } /** Cleans up a member (from skyblock/profile) */ export async function cleanSkyBlockProfileMemberResponse(member, included: Included[] = null): Promise<CleanMember> { - // profiles.members[] - const inventoriesIncluded = included == null || included.includes('inventories') - const player = await cached.fetchPlayer(member.uuid) - if (!player) return - return { - uuid: member.uuid, - username: player.username, - last_save: member.last_save / 1000, - first_join: member.first_join / 1000, - rank: player.rank, + // profiles.members[] + const inventoriesIncluded = included == null || included.includes('inventories') + const player = await cached.fetchPlayer(member.uuid) + if (!player) return + return { + uuid: member.uuid, + username: player.username, + last_save: member.last_save / 1000, + first_join: member.first_join / 1000, + rank: player.rank, - purse: member.coin_purse, + purse: member.coin_purse, - stats: cleanProfileStats(member), + stats: cleanProfileStats(member), - // this is used for leaderboards - rawHypixelStats: member.stats ?? {}, + // this is used for leaderboards + rawHypixelStats: member.stats ?? {}, - minions: cleanMinions(member), - fairy_souls: cleanFairySouls(member), - inventories: inventoriesIncluded ? await cleanInventories(member) : undefined, - objectives: cleanObjectives(member), - skills: cleanSkills(member), - visited_zones: cleanVisitedZones(member), - collections: cleanCollections(member), - slayers: cleanSlayers(member) - } + minions: cleanMinions(member), + fairy_souls: cleanFairySouls(member), + inventories: inventoriesIncluded ? await cleanInventories(member) : undefined, + objectives: cleanObjectives(member), + skills: cleanSkills(member), + visited_zones: cleanVisitedZones(member), + collections: cleanCollections(member), + slayers: cleanSlayers(member) + } } export interface CleanMemberProfilePlayer extends CleanPlayer { - // The profile name may be different for each player, so we put it here - profileName: string - first_join: number - last_save: number - bank?: Bank + // The profile name may be different for each player, so we put it here + profileName: string + first_join: number + last_save: number + bank?: Bank + purse?: number + stats?: StatItem[] + rawHypixelStats?: { [ key: string ]: number } + minions?: CleanMinion[] + fairy_souls?: FairySouls + inventories?: Inventories + objectives?: Objective[] + skills?: Skill[] + visited_zones?: Zone[] + collections?: Collection[] + slayers?: SlayerData } export interface CleanMemberProfile { - member: CleanMemberProfilePlayer - profile: CleanFullProfileBasicMembers + member: CleanMemberProfilePlayer + profile: CleanFullProfileBasicMembers } |