diff --git a/common/src/main/java/dev/sweetberry/wwizardry/api/Badges.java b/common/src/main/java/dev/sweetberry/wwizardry/api/Badges.java index 30b2dae3..f24ba61c 100644 --- a/common/src/main/java/dev/sweetberry/wwizardry/api/Badges.java +++ b/common/src/main/java/dev/sweetberry/wwizardry/api/Badges.java @@ -14,10 +14,7 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; -import java.util.HashMap; -import java.util.Map; -import java.util.Queue; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; @@ -27,7 +24,7 @@ public class Badges { private static final Gson GSON = new Gson(); - private static final Map BADGES_CACHE = new ConcurrentHashMap<>(); + private static final Map> BADGES_CACHE = new ConcurrentHashMap<>(); private static final String BASE_URL = "https://badges.wwizardry.sweetberry.dev"; @@ -51,10 +48,10 @@ public class Badges { @Nullable public static Component getBadgeFor(UUID player) { - if (!WORKER.isAlive()) + if (!WORKER.isAlive() && !WORKER.isInterrupted()) WORKER.start(); if (BADGES_CACHE.containsKey(player)) - return BADGES_CACHE.get(player); + return BADGES_CACHE.get(player).orElse(null); if (!RESOLUTION_QUEUE.contains(player)) RESOLUTION_QUEUE.add(player); return null; @@ -73,14 +70,14 @@ private static void resolveThread() { var name = makeRequest(player); if (!MAP.containsKey(name)) - BADGES_CACHE.put(player, null); + BADGES_CACHE.put(player, Optional.empty()); WanderingWizardry.LOGGER.info(player + " -> " + name); var badge = MAP.get(name); - BADGES_CACHE.put(player, badge); + BADGES_CACHE.put(player, Optional.ofNullable(badge)); } catch (IOException | InterruptedException | JsonSyntaxException e) { - BADGES_CACHE.put(player, null); + BADGES_CACHE.put(player, Optional.empty()); } RESOLUTION_QUEUE.poll(); } diff --git a/gradle.properties b/gradle.properties index a6e3f292..0ca9cb0a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs = -Xmx4G org.gradle.parallel = true # Mod Properties -version = 1.0.13 +version = 1.0.14 classification = maven_group = dev.sweetberry archives_base_name = wwizardry