From e7d7ec972590853453bf0a5c87b92e75fce71273 Mon Sep 17 00:00:00 2001
From: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Date: Tue, 4 Apr 2023 23:15:56 +0200
Subject: Added option to hide the hypixel api error message by clicking on it
---
src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt | 14 +++++++++++++-
src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 10 ++++++++++
2 files changed, 23 insertions(+), 1 deletion(-)
(limited to 'src/main/java/at/hannibal2/skyhanni/utils')
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
index 91f54e6a3..77fc27298 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt
@@ -19,6 +19,7 @@ import java.nio.charset.StandardCharsets
object APIUtil {
private val parser = JsonParser()
+ private var showApiErrors = false
val builder: HttpClientBuilder =
HttpClients.custom().setUserAgent("SkyHanni/${SkyHanniMod.VERSION}")
@@ -45,7 +46,13 @@ object APIUtil {
return parser.parse(retSrc) as JsonObject
} catch (e: JsonSyntaxException) {
if (retSrc.contains("
502 Bad Gateway
")) {
- LorenzUtils.error("[SkyHanni] Hypixel API is down :(")
+ if (showApiErrors) {
+ LorenzUtils.clickableChat(
+ "[SkyHanni] Problems with detecting the Hypixel API. §eClick here to hide this message for now.",
+ "shtogglehypixelapierrors"
+ )
+ }
+
} else {
println("JsonSyntaxException at getJSONResponse '$urlString'")
LorenzUtils.error("[SkyHanni] JsonSyntaxException at getJSONResponse!")
@@ -71,4 +78,9 @@ object APIUtil {
fun readFile(file: File): BufferedReader {
return BufferedReader(InputStreamReader(FileInputStream(file), StandardCharsets.UTF_8))
}
+
+ fun toggleApiErrorMessages() {
+ showApiErrors = !showApiErrors
+ LorenzUtils.chat("§e[SkyHanni] HyPixel API error messages " + if (showApiErrors) "§chidden" else "§ashown")
+ }
}
\ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
index 938a0326f..5f5f83514 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt
@@ -12,6 +12,8 @@ import net.minecraft.client.Minecraft
import net.minecraft.client.gui.inventory.GuiEditSign
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.SharedMonsterAttributes
+import net.minecraft.event.ClickEvent
+import net.minecraft.event.HoverEvent
import net.minecraft.util.ChatComponentText
import java.text.DecimalFormat
import java.text.NumberFormat
@@ -198,4 +200,12 @@ object LorenzUtils {
gui as AccessorGuiEditSign
gui.tileSign.signText[0] = ChatComponentText(text)
}
+
+ fun clickableChat(message: String, command: String) {
+ val text = ChatComponentText(message)
+ text.chatStyle.chatClickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, "/$command")
+ text.chatStyle.chatHoverEvent =
+ HoverEvent(HoverEvent.Action.SHOW_TEXT, ChatComponentText("§eExecute /$command"))
+ Minecraft.getMinecraft().thePlayer.addChatMessage(text)
+ }
}
\ No newline at end of file
--
cgit