From 685b2da9745e9f9e0d23e1fce39e0c6bcb6ca699 Mon Sep 17 00:00:00 2001 From: Aaron <51387595+AzureAaron@users.noreply.github.com> Date: Sun, 16 Jun 2024 17:56:52 -0400 Subject: Pet Cache --- .../de/hysky/skyblocker/skyblock/item/MuseumItemCache.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker/skyblock/item/MuseumItemCache.java') 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 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 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 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 collectedItemIds) { private static final ProfileMuseumData EMPTY = new ProfileMuseumData(0L, null); private static final long TIME_BETWEEN_RESYNCING_ALLOWED = 172_800_000L; -- cgit