From 796239fd10070612c2bd8f2231cb199b78f74820 Mon Sep 17 00:00:00 2001 From: Jacob Date: Sat, 26 Oct 2024 01:57:40 +0800 Subject: [PATCH] Garden Command --- API/constants/xp_tables.js | 72 +++++++++++++++++++++++++ API/functions/getGarden.js | 21 ++++++++ API/functions/getLatestProfile.js | 4 +- API/stats/garden.js | 19 +++++++ src/minecraft/commands/gardenCommand.js | 40 ++++++++++++++ src/minecraft/commands/jacobCommand.js | 2 +- 6 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 API/functions/getGarden.js create mode 100644 API/stats/garden.js create mode 100644 src/minecraft/commands/gardenCommand.js diff --git a/API/constants/xp_tables.js b/API/constants/xp_tables.js index be538c74..9d65dc68 100644 --- a/API/constants/xp_tables.js +++ b/API/constants/xp_tables.js @@ -13,6 +13,17 @@ module.exports = { social: 25, dungeoneering: 50, hotm: 10, + gardenXp: 15, + wheat: 46, + carrot: 46, + potato: 46, + melon: 46, + pumpkin: 46, + sugarCane: 46, + cocoaBeans: 46, + cactus: 46, + mushroom: 46, + netherWart: 46, }, normal: [ 50, 125, 200, 300, 500, 750, 1000, 1500, 2000, 3500, 5000, 7500, 10000, 15000, 20000, 30000, 50000, 75000, 100000, @@ -44,4 +55,65 @@ module.exports = { blaze: [10, 30, 250, 1500, 5000, 20000, 100000, 400000, 1000000], vampire: [20, 75, 240, 840, 2400], }, + gardenXp: [0, 70, 70, 140, 240, 600, 1500, 2000, 2500, 3000, 10000, 10000, 10000, 10000, 10000], + wheat: [ + 30, 50, 80, 170, 330, 670, 1330, 2500, 3500, 5000, 6500, 8000, 10000, 20000, 35000, 50000, 75000, 100000, 175000, + 250000, 350000, 500000, 750000, 1000000, 1300000, 1600000, 2000000, 2300000, 2600000, 3000000, 3000000, 3000000, + 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, + 3000000, + ], + carrot: [ + 100, 150, 250, 500, 1500, 2500, 5000, 7500, 10000, 15000, 20000, 25000, 40000, 70000, 100000, 200000, 250000, + 250000, 500000, 750000, 1000000, 1500000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, + 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, + 10000000, 10000000, 10000000, 10000000, 10000000, + ], + potato: [ + 100, 150, 250, 500, 1500, 2500, 5000, 7500, 10000, 15000, 20000, 25000, 40000, 70000, 100000, 200000, 250000, + 250000, 500000, 750000, 1000000, 1500000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, + 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, 10000000, + 10000000, 10000000, 10000000, 10000000, 10000000, + ], + melon: [ + 150, 250, 400, 850, 1650, 3350, 6650, 12500, 17500, 25000, 32500, 40000, 50000, 100000, 175000, 250000, 375000, + 500000, 875000, 1250000, 1750000, 2500000, 3750000, 5000000, 6500000, 8000000, 10000000, 11500000, 13000000, + 15000000, 15000000, 15000000, 15000000, 15000000, 15000000, 15000000, 15000000, 15000000, 15000000, 15000000, + 15000000, 15000000, 15000000, 15000000, 15000000, 15000000, + ], + pumpkin: [ + 30, 50, 80, 170, 330, 670, 1330, 2500, 3500, 5000, 6500, 8000, 10000, 20000, 35000, 50000, 75000, 100000, 175000, + 250000, 350000, 500000, 750000, 1000000, 1300000, 1600000, 2000000, 2300000, 2600000, 3000000, 3000000, 3000000, + 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, + 3000000, + ], + sugarCane: [ + 60, 100, 160, 340, 660, 1340, 2660, 5000, 7000, 10000, 13000, 16000, 20000, 40000, 70000, 100000, 150000, 200000, + 350000, 500000, 700000, 1000000, 1500000, 2000000, 2600000, 3200000, 4000000, 4600000, 5200000, 6000000, 6000000, + 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, + 6000000, 6000000, + ], + cocoaBeans: [ + 90, 150, 250, 500, 1000, 2000, 4000, 7500, 10000, 15000, 20000, 25000, 30000, 50000, 100000, 150000, 200000, 300000, + 500000, 750000, 1000000, 1500000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 9000000, + 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, + 9000000, 9000000, + ], + cactus: [ + 60, 100, 160, 340, 660, 1340, 2660, 5000, 7000, 10000, 13000, 16000, 20000, 40000, 70000, 100000, 150000, 200000, + 350000, 500000, 700000, 1000000, 1500000, 2000000, 2600000, 3200000, 4000000, 4600000, 5200000, 6000000, 6000000, + 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, 6000000, + 6000000, 6000000, + ], + mushroom: [ + 30, 50, 80, 170, 330, 670, 1330, 2500, 3500, 5000, 6500, 8000, 10000, 20000, 35000, 50000, 75000, 100000, 175000, + 250000, 350000, 500000, 750000, 1000000, 1300000, 1600000, 2000000, 2300000, 2600000, 3000000, 3000000, 3000000, + 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, 3000000, + 3000000, + ], + netherWart: [ + 90, 150, 250, 500, 1000, 2000, 4000, 7500, 10000, 15000, 20000, 25000, 30000, 50000, 100000, 150000, 200000, 300000, + 500000, 750000, 1000000, 1500000, 2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 9000000, + 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, + 9000000, 9000000, + ], }; diff --git a/API/functions/getGarden.js b/API/functions/getGarden.js new file mode 100644 index 00000000..a367d8ae --- /dev/null +++ b/API/functions/getGarden.js @@ -0,0 +1,21 @@ +/* eslint-disable no-throw-literal */ +const config = require("../../config.json"); +const axios = require("axios"); + +async function getGarden(profileID, uuid) { + try { + const { data } = await axios.get( + `https://api.hypixel.net/v2/skyblock/garden?key=${config.minecraft.API.hypixelAPIkey}&profile=${profileID}`, + ); + + if (data === undefined || data.success === false) { + throw "Request to Hypixel API failed. Please try again!"; + } + + return { garden: data.garden }; + } catch (e) { + throw new Error(e); + } +} + +module.exports = { getGarden }; diff --git a/API/functions/getLatestProfile.js b/API/functions/getLatestProfile.js index 6a364277..704a0e0f 100644 --- a/API/functions/getLatestProfile.js +++ b/API/functions/getLatestProfile.js @@ -1,13 +1,14 @@ /* eslint-disable no-throw-literal */ const { getUUID } = require("../../src/contracts/API/mowojangAPI.js"); const { getMuseum } = require("./getMuseum.js"); +const { getGarden } = require("./getGarden.js"); const { isUuid } = require("../utils/uuid.js"); const config = require("../../config.json"); const axios = require("axios"); const cache = new Map(); -async function getLatestProfile(uuid, options = { museum: false }) { +async function getLatestProfile(uuid, options = { museum: false, garden: false }) { if (!isUuid(uuid)) { uuid = await getUUID(uuid).catch((error) => { throw error; @@ -59,6 +60,7 @@ async function getLatestProfile(uuid, options = { museum: false }) { playerRes: playerRes.player, uuid: uuid, ...(options.museum ? await getMuseum(profileData.profile_id, uuid) : {}), + ...(options.garden ? await getGarden(profileData.profile_id) : {}), }; cache.set(uuid, output); diff --git a/API/stats/garden.js b/API/stats/garden.js new file mode 100644 index 00000000..010c4a0c --- /dev/null +++ b/API/stats/garden.js @@ -0,0 +1,19 @@ +const calcSkill = require("../constants/skills.js"); + +module.exports = (profile) => { + return { + level: calcSkill("gardenXp", profile?.garden_experience || 0), + cropMilesstone: { + wheat: calcSkill("wheat", profile?.resources_collected?.WHEAT || 0), + carrot: calcSkill("carrot", profile?.resources_collected?.CARROT_ITEM || 0), + sugarCane: calcSkill("sugarCane", profile?.resources_collected?.SUGAR_CANE || 0), + potato: calcSkill("potato", profile?.resources_collected?.POTATO_ITEM || 0), + netherWart: calcSkill("netherWart", profile?.resources_collected?.NETHER_STALK || 0), + pumpkin: calcSkill("pumpkin", profile?.resources_collected?.PUMPKIN || 0), + melon: calcSkill("melon", profile?.resources_collected?.MELON || 0), + mushroom: calcSkill("mushroom", profile?.resources_collected?.MUSHROOM_COLLECTION || 0), + cocoaBeans: calcSkill("cocoaBeans", profile?.resources_collected?.["INK_SACK:3"] || 0), + cactus: calcSkill("cactus", profile?.resources_collected?.CACTUS || 0), + }, + }; +}; diff --git a/src/minecraft/commands/gardenCommand.js b/src/minecraft/commands/gardenCommand.js new file mode 100644 index 00000000..444a984e --- /dev/null +++ b/src/minecraft/commands/gardenCommand.js @@ -0,0 +1,40 @@ +const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js"); +const { formatUsername } = require("../../contracts/helperFunctions.js"); +const minecraftCommand = require("../../contracts/minecraftCommand.js"); +const getGarden = require("../../../API/stats/garden.js"); + +class GardenCommand extends minecraftCommand { + constructor(minecraft) { + super(minecraft); + + this.name = "garden"; + this.aliases = []; + this.description = "Skyblock Garden Stats of specified user."; + this.options = [ + { + name: "username", + description: "Minecraft username", + required: false, + }, + ]; + } + + async onCommand(username, message) { + try { + // CREDITS: by @Kathund (https://github.com/Kathund) + username = this.getArgs(message)[0] || username; + + const data = await getLatestProfile(username, { garden: true }); + username = formatUsername(username, data.profileData?.game_mode); + const garden = getGarden(data.garden); + + this.send( + `/gc ${username}'s garden ${garden.level.level} | Crop Milestones: Wheat: ${garden.cropMilesstone.wheat.level} | Carrot: ${garden.cropMilesstone.carrot.level} | Cane: ${garden.cropMilesstone.sugarCane.level} | Potato: ${garden.cropMilesstone.potato.level} | Wart: ${garden.cropMilesstone.netherWart.level} | Pumpkin: ${garden.cropMilesstone.pumpkin.level} | Melon: ${garden.cropMilesstone.melon.level} | Mushroom: ${garden.cropMilesstone.mushroom.level} | Cocoa: ${garden.cropMilesstone.cocoaBeans.level} | Cactus: ${garden.cropMilesstone.cactus.level}`, + ); + } catch (error) { + this.send(`/gc [ERROR] ${error}`); + } + } +} + +module.exports = GardenCommand; diff --git a/src/minecraft/commands/jacobCommand.js b/src/minecraft/commands/jacobCommand.js index 5d8ff705..0754f3c0 100644 --- a/src/minecraft/commands/jacobCommand.js +++ b/src/minecraft/commands/jacobCommand.js @@ -9,7 +9,7 @@ class JacobCommand extends minecraftCommand { super(minecraft); this.name = "jacob"; - this.aliases = ["jacobs", "garden", "jacobcontest", "contest"]; + this.aliases = ["jacobs", "jacobcontest", "contest"]; this.description = "Jacob's Contest Stats of specified user."; this.options = []; }