diff options
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/item')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/item/ItemCooldowns.java | 44 | ||||
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/item/MuseumItemCache.java | 12 |
2 files changed, 23 insertions, 33 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/ItemCooldowns.java b/src/main/java/de/hysky/skyblocker/skyblock/item/ItemCooldowns.java index 96c21d22..8f15b20b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/ItemCooldowns.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/ItemCooldowns.java @@ -1,9 +1,9 @@ package de.hysky.skyblocker.skyblock.item; -import com.google.gson.JsonElement; import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.skyblock.PetCache; +import de.hysky.skyblocker.skyblock.PetCache.PetInfo; import de.hysky.skyblocker.utils.ItemUtils; -import de.hysky.skyblocker.utils.ProfileUtils; import net.fabricmc.fabric.api.event.client.player.ClientPlayerBlockBreakEvents; import net.fabricmc.fabric.api.event.player.UseItemCallback; import net.minecraft.block.BlockState; @@ -36,8 +36,8 @@ public class ItemCooldowns { 561700, 611700, 666700, 726700, 791700, 861700, 936700, 1016700, 1101700, 1191700, 1286700, 1386700, 1496700, 1616700, 1746700, 1886700 }; - public static int monkeyLevel = 1; - public static double monkeyExp = 0; + private static int monkeyLevel = 1; + private static double monkeyExp = 0; public static void init() { ClientPlayerBlockBreakEvents.AFTER.register(ItemCooldowns::afterBlockBreak); @@ -45,30 +45,24 @@ public class ItemCooldowns { } public static void updateCooldown() { - ProfileUtils.updateProfile().thenAccept(player -> { - for (JsonElement pet : player.getAsJsonObject("pets_data").getAsJsonArray("pets")) { - if (!pet.getAsJsonObject().get("type").getAsString().equals("MONKEY")) continue; - if (!pet.getAsJsonObject().get("active").getAsString().equals("true")) continue; - if (pet.getAsJsonObject().get("tier").getAsString().equals("LEGENDARY")) { - monkeyExp = Double.parseDouble(pet.getAsJsonObject().get("exp").getAsString()); - monkeyLevel = 0; - for (int xpLevel : EXPERIENCE_LEVELS) { - if (monkeyExp < xpLevel) { - break; - } else { - monkeyExp -= xpLevel; - monkeyLevel++; - } - } + PetInfo pet = PetCache.getCurrentPet(); + + if (pet.tier().equals("LEGENDARY")) { + monkeyExp = pet.exp(); + + monkeyLevel = 0; + for (int xpLevel : EXPERIENCE_LEVELS) { + if (monkeyExp < xpLevel) { + break; + } else { + monkeyExp -= xpLevel; + monkeyLevel++; } } - }).exceptionally(e -> { - ProfileUtils.LOGGER.error("[Skyblocker Item Cooldown] Failed to get Player Pet Data, is the API Down/Limited?", e); - return null; - }); + } } - private static int getCooldown() { + private static int getCooldown4Foraging() { int baseCooldown = 2000; int monkeyPetCooldownReduction = baseCooldown * monkeyLevel / 200; return baseCooldown - monkeyPetCooldownReduction; @@ -82,7 +76,7 @@ public class ItemCooldowns { if (usedItemId.equals(JUNGLE_AXE_ID) || usedItemId.equals(TREECAPITATOR_ID)) { updateCooldown(); if (!isOnCooldown(JUNGLE_AXE_ID) || !isOnCooldown(TREECAPITATOR_ID)) { - ITEM_COOLDOWNS.put(usedItemId, new CooldownEntry(getCooldown())); + ITEM_COOLDOWNS.put(usedItemId, new CooldownEntry(getCooldown4Foraging())); } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/MuseumItemCache.java b/src/main/java/de/hysky/skyblocker/skyblock/item/MuseumItemCache.java index 11e8ea9c..49df5b78 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/MuseumItemCache.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/MuseumItemCache.java @@ -110,7 +110,7 @@ public class MuseumItemCache { String profileId = Utils.getProfileId(); if (!itemId.isEmpty() && !profileId.isEmpty()) { - String uuid = getUndashedUuid(MinecraftClient.getInstance()); + String uuid = Utils.getUndashedUuid(); //Be safe about access to avoid NPEs Map<String, ProfileMuseumData> playerData = MUSEUM_ITEM_CACHE.computeIfAbsent(uuid, _uuid -> new Object2ObjectOpenHashMap<>()); playerData.putIfAbsent(profileId, ProfileMuseumData.EMPTY); @@ -203,7 +203,7 @@ public class MuseumItemCache { } private static boolean tryResync(FabricClientCommandSource source) { - String uuid = getUndashedUuid(source.getClient()); + String uuid = Utils.getUndashedUuid(); String profileId = Utils.getProfileId(); //Only allow resyncing if the data is actually present yet, otherwise the player needs to swap servers for the tick method to be called @@ -220,7 +220,7 @@ public class MuseumItemCache { * The cache is ticked upon switching Skyblock servers. Only loads from the API if the profile wasn't cached yet. */ public static void tick(String profileId) { - String uuid = getUndashedUuid(MinecraftClient.getInstance()); + String uuid = Utils.getUndashedUuid(); if (loaded.isDone() && (!MUSEUM_ITEM_CACHE.containsKey(uuid) || !MUSEUM_ITEM_CACHE.getOrDefault(uuid, new Object2ObjectOpenHashMap<>()).containsKey(profileId))) { Map<String, ProfileMuseumData> playerData = MUSEUM_ITEM_CACHE.computeIfAbsent(uuid, _uuid -> new Object2ObjectOpenHashMap<>()); @@ -231,16 +231,12 @@ public class MuseumItemCache { } public static boolean hasItemInMuseum(String id) { - String uuid = getUndashedUuid(MinecraftClient.getInstance()); + String uuid = Utils.getUndashedUuid(); ObjectOpenHashSet<String> collectedItemIds = (!MUSEUM_ITEM_CACHE.containsKey(uuid) || Utils.getProfileId().isBlank() || !MUSEUM_ITEM_CACHE.get(uuid).containsKey(Utils.getProfileId())) ? null : MUSEUM_ITEM_CACHE.get(uuid).get(Utils.getProfileId()).collectedItemIds(); return collectedItemIds != null && collectedItemIds.contains(id); } - private static String getUndashedUuid(MinecraftClient client) { - return UndashedUuid.toString(MinecraftClient.getInstance().getSession().getUuidOrNull()); - } - private record ProfileMuseumData(long lastResync, ObjectOpenHashSet<String> collectedItemIds) { private static final ProfileMuseumData EMPTY = new ProfileMuseumData(0L, null); private static final long TIME_BETWEEN_RESYNCING_ALLOWED = 172_800_000L; |