diff options
author | Rime <81419447+Emirlol@users.noreply.github.com> | 2024-01-18 08:23:05 +0300 |
---|---|---|
committer | Rime <81419447+Emirlol@users.noreply.github.com> | 2024-01-21 09:37:49 +0300 |
commit | 8feae9fc42e894431bc16474c4476ee0f7e58fa4 (patch) | |
tree | 53558315b64625261b70f8f19367cd21ecb3bbe3 /src/main/java/de | |
parent | 1382f6ce7f4dc9aade35f7d877e6b9ba6832ce4a (diff) | |
download | Skyblocker-8feae9fc42e894431bc16474c4476ee0f7e58fa4.tar.gz Skyblocker-8feae9fc42e894431bc16474c4476ee0f7e58fa4.tar.bz2 Skyblocker-8feae9fc42e894431bc16474c4476ee0f7e58fa4.zip |
Wrapped initializeMayorCache in a CompletableFuture
Diffstat (limited to 'src/main/java/de')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/Utils.java | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java index 3336a0a7..31157bfc 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Utils.java +++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java @@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.Collections; import java.util.List; +import java.util.concurrent.CompletableFuture; /** * Utility variables and methods for retrieving Skyblock related information. @@ -396,15 +397,18 @@ public class Utils { private static void initializeMayorCache() { if (!mayor.isEmpty()) return; - try { - JsonObject json = JsonParser.parseString(Http.sendGetRequest("https://api.hypixel.net/v2/resources/skyblock/election")).getAsJsonObject(); - if (json.get("success").getAsBoolean()) { - mayor = json.get("mayor").getAsJsonObject().get("name").getAsString(); - } else { - throw new IOException("API call for mayor failed: " + json.get("cause").getAsString()); + CompletableFuture.supplyAsync(() -> { + try { + JsonObject json = JsonParser.parseString(Http.sendGetRequest("https://api.hypixel.net/v2/resources/skyblock/election")).getAsJsonObject(); + if (json.get("success").getAsBoolean()) return json.get("mayor").getAsJsonObject().get("name").getAsString(); + throw new IOException("API call for mayor status failed: " + json.get("cause").getAsString()); + } catch (IOException | InterruptedException e) { + e.printStackTrace(); } - } catch (IOException | InterruptedException e) { - e.printStackTrace(); - } + return ""; + }).thenAccept(s -> { + if (!s.isEmpty()) mayor = s; + }); + } } |