From 64f6c78b40f616e2f11264a8c7acaaa78248a385 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 31 Jul 2023 16:48:49 +0200 Subject: Added repo switch user_api_keys --- .../java/at/hannibal2/skyhanni/data/ApiDataLoader.kt | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt b/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt index 54d86d1de..df8c511ee 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/ApiDataLoader.kt @@ -4,6 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.events.LorenzTickEvent import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.utils.APIUtil import at.hannibal2.skyhanni.utils.LorenzUtils import kotlinx.coroutines.Dispatchers @@ -15,14 +16,26 @@ import java.io.File import java.util.* class ApiDataLoader { - private var currentProfileName = "" private var currentProfileId = "" + private var usePlayerApiKey = false + + @SubscribeEvent + fun onRepositoryReload(event: RepositoryReloadEvent) { + usePlayerApiKey = false + event.getConstant("DisabledFeatures")?.let { + if (it.asJsonObject["user_api_keys"]?.asBoolean ?: false) { + usePlayerApiKey = true + } + } + } + @SubscribeEvent fun onTick(event: LorenzTickEvent) { val thePlayer = Minecraft.getMinecraft().thePlayer ?: return thePlayer.worldObj ?: return + if (!usePlayerApiKey) return if (nextApiCallTime != -1L && System.currentTimeMillis() > nextApiCallTime) { nextApiCallTime = System.currentTimeMillis() + 60_000 * 5 @@ -37,6 +50,7 @@ class ApiDataLoader { @SubscribeEvent fun onProfileJoin(event: ProfileJoinEvent) { currentProfileName = event.name + if (!usePlayerApiKey) return updateApiData() } -- cgit