aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2022-09-26 12:17:59 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2022-09-26 12:17:59 +0200
commit0899bc4559ecf1fc3a0475f45c59bdbe3c475fe4 (patch)
treee3cc2193a92fe84d7f431a33649a3d790170d756
parentb2fb4746a3c7116ba7536c89979f0ea78cb363fb (diff)
downloadskyhanni-0899bc4559ecf1fc3a0475f45c59bdbe3c475fe4.tar.gz
skyhanni-0899bc4559ecf1fc3a0475f45c59bdbe3c475fe4.tar.bz2
skyhanni-0899bc4559ecf1fc3a0475f45c59bdbe3c475fe4.zip
made api key checking asynchronous
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/ApiKeyGrabber.kt75
1 files changed, 40 insertions, 35 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/data/ApiKeyGrabber.kt b/src/main/java/at/hannibal2/skyhanni/data/ApiKeyGrabber.kt
index c35a78f4a..efadb448e 100644
--- a/src/main/java/at/hannibal2/skyhanni/data/ApiKeyGrabber.kt
+++ b/src/main/java/at/hannibal2/skyhanni/data/ApiKeyGrabber.kt
@@ -9,10 +9,13 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import net.minecraft.client.Minecraft
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.io.File
+import java.util.concurrent.Executors
class ApiKeyGrabber {
private var currentProfileName = ""
+ private val executors = Executors.newFixedThreadPool(1)
+
@SubscribeEvent
fun onStatusBar(event: LorenzChatEvent) {
@@ -34,49 +37,51 @@ class ApiKeyGrabber {
}
private fun updateApiData() {
- val uuid = Minecraft.getMinecraft().thePlayer.uniqueID.toString().replace("-", "")
-
- var apiKey = SkyHanniMod.feature.hidden.apiKey
- if (!verifyKey(apiKey)) {
- LorenzUtils.chat("§c[SkyHanni] Invalid api key detected, deleting it!")
- apiKey = ""
- SkyHanniMod.feature.hidden.apiKey = ""
- }
+ executors.submit {
+ val uuid = Minecraft.getMinecraft().thePlayer.uniqueID.toString().replace("-", "")
+
+ var apiKey = SkyHanniMod.feature.hidden.apiKey
+ if (!verifyKey(apiKey)) {
+ LorenzUtils.chat("§c[SkyHanni] Invalid api key detected, deleting it!")
+ apiKey = ""
+ SkyHanniMod.feature.hidden.apiKey = ""
+ }
- if (apiKey.isEmpty()) {
- readApiKeyFromOtherMods()
- apiKey = SkyHanniMod.feature.hidden.apiKey
if (apiKey.isEmpty()) {
- LorenzUtils.warning("SkyHanni has no API Key set. Type /api new to reload.")
- return
+ readApiKeyFromOtherMods()
+ apiKey = SkyHanniMod.feature.hidden.apiKey
+ if (apiKey.isEmpty()) {
+ LorenzUtils.warning("SkyHanni has no API Key set. Type /api new to reload.")
+ return@submit
+ }
}
- }
- val url = "https://api.hypixel.net/player?key=$apiKey&uuid=$uuid"
+ val url = "https://api.hypixel.net/player?key=$apiKey&uuid=$uuid"
- val jsonObject = APIUtil.getJSONResponse(url)
+ val jsonObject = APIUtil.getJSONResponse(url)
- if (!jsonObject["success"].asBoolean) {
- val cause = jsonObject["cause"].asString
- if (cause == "Invalid API key") {
- LorenzUtils.error("SkyHanni got an API error: Invalid API key! Type /api new to reload.")
- return
- } else {
- throw RuntimeException("API error for url '$url': $cause")
+ if (!jsonObject["success"].asBoolean) {
+ val cause = jsonObject["cause"].asString
+ if (cause == "Invalid API key") {
+ LorenzUtils.error("SkyHanni got an API error: Invalid API key! Type /api new to reload.")
+ return@submit
+ } else {
+ throw RuntimeException("API error for url '$url': $cause")
+ }
}
- }
- val player = jsonObject["player"].asJsonObject
- val stats = player["stats"].asJsonObject
- val skyblock = stats["SkyBlock"].asJsonObject
- val profiles = skyblock["profiles"].asJsonObject
- for (entry in profiles.entrySet()) {
- val asJsonObject = entry.value.asJsonObject
- val name = asJsonObject["cute_name"].asString
- val profileId = asJsonObject["profile_id"].asString
- if (currentProfileName == name.lowercase()) {
- loadProfile(uuid, profileId)
- return
+ val player = jsonObject["player"].asJsonObject
+ val stats = player["stats"].asJsonObject
+ val skyblock = stats["SkyBlock"].asJsonObject
+ val profiles = skyblock["profiles"].asJsonObject
+ for (entry in profiles.entrySet()) {
+ val asJsonObject = entry.value.asJsonObject
+ val name = asJsonObject["cute_name"].asString
+ val profileId = asJsonObject["profile_id"].asString
+ if (currentProfileName == name.lowercase()) {
+ loadProfile(uuid, profileId)
+ return@submit
+ }
}
}
}