diff options
| author | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2024-08-25 13:50:35 -0400 |
|---|---|---|
| committer | Aaron <51387595+AzureAaron@users.noreply.github.com> | 2024-08-25 14:02:25 -0400 |
| commit | 928b4a4bf101a5cb1647325ef333b85113839c0a (patch) | |
| tree | 79883c348483151f6a7b97edef648e14f06176cc /src/main/java | |
| parent | b97b085426de3a9310f87667a2b502bf24f12e9b (diff) | |
| download | Skyblocker-928b4a4bf101a5cb1647325ef333b85113839c0a.tar.gz Skyblocker-928b4a4bf101a5cb1647325ef333b85113839c0a.tar.bz2 Skyblocker-928b4a4bf101a5cb1647325ef333b85113839c0a.zip | |
Fix PV Collections Crash
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/profileviewer/ProfileViewerScreen.java | 56 | ||||
| -rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java | 7 |
2 files changed, 32 insertions, 31 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/ProfileViewerScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/ProfileViewerScreen.java index 80af2935..d9a99b54 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/ProfileViewerScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/ProfileViewerScreen.java @@ -39,7 +39,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.awt.*; -import java.io.IOException; import java.util.List; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -214,34 +213,37 @@ public class ProfileViewerScreen extends Screen { } @NotNull - public static Map<String, Map<String, ?>> fetchCollectionsData() { - if (!COLLECTIONS_CACHE.isEmpty()) return COLLECTIONS_CACHE; - try { - JsonObject jsonObject = JsonParser.parseString(Http.sendGetRequest(HYPIXEL_COLLECTIONS)).getAsJsonObject(); - if (jsonObject.get("success").getAsBoolean()) { - Map<String, String[]> collectionsMap = new HashMap<>(); - Map<String, IntList> tierRequirementsMap = new HashMap<>(); - JsonObject collections = jsonObject.getAsJsonObject("collections"); - collections.entrySet().forEach(entry -> { - String category = entry.getKey(); - JsonObject itemsObject = entry.getValue().getAsJsonObject().getAsJsonObject("items"); - String[] items = itemsObject.keySet().toArray(new String[0]); - collectionsMap.put(category, items); - itemsObject.entrySet().forEach(itemEntry -> { - IntList tierReqs = new IntArrayList(); - itemEntry.getValue().getAsJsonObject().getAsJsonArray("tiers").forEach(req -> - tierReqs.add(req.getAsJsonObject().get("amountRequired").getAsInt())); - tierRequirementsMap.put(itemEntry.getKey(), tierReqs); + private static void fetchCollectionsData() { + CompletableFuture.runAsync(() -> { + try { + JsonObject jsonObject = JsonParser.parseString(Http.sendGetRequest(HYPIXEL_COLLECTIONS)).getAsJsonObject(); + if (jsonObject.get("success").getAsBoolean()) { + Map<String, String[]> collectionsMap = new HashMap<>(); + Map<String, IntList> tierRequirementsMap = new HashMap<>(); + JsonObject collections = jsonObject.getAsJsonObject("collections"); + collections.entrySet().forEach(entry -> { + String category = entry.getKey(); + JsonObject itemsObject = entry.getValue().getAsJsonObject().getAsJsonObject("items"); + String[] items = itemsObject.keySet().toArray(new String[0]); + collectionsMap.put(category, items); + itemsObject.entrySet().forEach(itemEntry -> { + IntList tierReqs = new IntArrayList(); + itemEntry.getValue().getAsJsonObject().getAsJsonArray("tiers").forEach(req -> + tierReqs.add(req.getAsJsonObject().get("amountRequired").getAsInt())); + tierRequirementsMap.put(itemEntry.getKey(), tierReqs); + }); }); - }); - COLLECTIONS_CACHE.put("COLLECTIONS", collectionsMap); - COLLECTIONS_CACHE.put("TIER_REQS", tierRequirementsMap); - return COLLECTIONS_CACHE; + COLLECTIONS_CACHE.put("COLLECTIONS", collectionsMap); + COLLECTIONS_CACHE.put("TIER_REQS", tierRequirementsMap); + } + } catch (Exception e) { + LOGGER.error("[Skyblocker Profile Viewer] Failed to fetch collections data", e); } - } catch (IOException | InterruptedException e) { - LOGGER.error("[Skyblocker Profile Viewer] Failed to fetch collections data", e); - } - return Collections.emptyMap(); + }); + } + + public static Map<String, Map<String, ?>> getCollectionsData() { + return COLLECTIONS_CACHE; } /** diff --git a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java index 10778adc..ec8fcd6d 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java @@ -26,7 +26,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import static de.hysky.skyblocker.skyblock.profileviewer.ProfileViewerScreen.fetchCollectionsData; +import static de.hysky.skyblocker.skyblock.profileviewer.ProfileViewerScreen.getCollectionsData; import static de.hysky.skyblocker.skyblock.profileviewer.utils.ProfileViewerUtils.COMMA_FORMATTER; public class GenericCategory implements ProfileViewerPage { @@ -44,11 +44,10 @@ public class GenericCategory implements ProfileViewerPage { Map.entry("MUSHROOM_COLLECTION", "RED_MUSHROOM")); private final String[] ROMAN_NUMERALS = {"-", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX"}; + @SuppressWarnings("unchecked") public GenericCategory(JsonObject hProfile, JsonObject pProfile, String collection) { - Map<String, Map<String, ?>> fetchedData = fetchCollectionsData(); - //noinspection unchecked + Map<String, Map<String, ?>> fetchedData = getCollectionsData(); collectionsMap = (Map<String, String[]>) fetchedData.get("COLLECTIONS"); - //noinspection unchecked tierRequirementsMap = (Map<String, IntList>) fetchedData.get("TIER_REQS"); this.category = collection; setupItemStacks(hProfile, pProfile); |
