aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/APIUtil.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt10
2 files changed, 23 insertions, 1 deletions
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("<center><h1>502 Bad Gateway</h1></center>")) {
- 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