diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-04 23:15:56 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-04-04 23:15:56 +0200 |
commit | e7d7ec972590853453bf0a5c87b92e75fce71273 (patch) | |
tree | ccefb6b05a044ecd5ff8e15482889794507bc92c /src/main/java/at | |
parent | 081655874773a5919782a7721c422522aabfdd95 (diff) | |
download | skyhanni-e7d7ec972590853453bf0a5c87b92e75fce71273.tar.gz skyhanni-e7d7ec972590853453bf0a5c87b92e75fce71273.tar.bz2 skyhanni-e7d7ec972590853453bf0a5c87b92e75fce71273.zip |
Added option to hide the hypixel api error message by clicking on it
Diffstat (limited to 'src/main/java/at')
4 files changed, 28 insertions, 16 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt index 638ec334f..b808c4b31 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt @@ -15,6 +15,7 @@ import at.hannibal2.skyhanni.test.LorenzTest import at.hannibal2.skyhanni.test.PacketTest import at.hannibal2.skyhanni.test.command.CopyItemCommand import at.hannibal2.skyhanni.test.command.CopyNearbyEntitiesCommand +import at.hannibal2.skyhanni.utils.APIUtil import net.minecraft.command.ICommandSender import net.minecraftforge.client.ClientCommandHandler @@ -53,6 +54,7 @@ object Commands { registerCommand("shsetapikey") { ApiDataLoader.command(it) } registerCommand("shtestgardenvisitors") { LorenzTest.testGardenVisitors() } registerCommand("shresetitemnames") { BazaarDataGrabber.resetItemNames() } + registerCommand("shtogglehypixelapierrors") { APIUtil.toggleApiErrorMessages() } } private fun registerCommand(name: String, function: (Array<String>) -> Unit) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/JoinCrystalHollows.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/JoinCrystalHollows.kt index f12506c33..7f7a0cc91 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/JoinCrystalHollows.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/JoinCrystalHollows.kt @@ -9,10 +9,6 @@ import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.RenderUtils.drawDynamicText -import net.minecraft.client.Minecraft -import net.minecraft.event.ClickEvent -import net.minecraft.event.HoverEvent -import net.minecraft.util.ChatComponentText import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -28,26 +24,18 @@ class JoinCrystalHollows { if (message == "§cYou do not have an active Crystal Hollows pass!") { lastWrongPassTime = System.currentTimeMillis() if (LorenzUtils.skyBlockIsland != IslandType.DWARVEN_MINES) { - sendClickableMessage("§e[SkyHanni] Click here to warp to Dwarven Mines!", "warp mines") + LorenzUtils.clickableChat("§e[SkyHanni] Click here to warp to Dwarven Mines!", "warp mines") } else { LorenzUtils.chat("§e[SkyHanni] Buy a §2Crystal Hollows Pass §efrom §5Gwendolyn") } } if (message == "§e[NPC] §5Gwendolyn§f: §rGreat! Now hop on into the Minecart and I'll get you on your way!") { if (inTime()) { - sendClickableMessage("§e[SkyHanni] Click here to warp to Crystal Hollows!", "warp ch") + LorenzUtils.clickableChat("§e[SkyHanni] Click here to warp to Crystal Hollows!", "warp ch") } } } - private fun sendClickableMessage(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) - } - @SubscribeEvent fun onIslandChange(event: IslandChangeEvent) { if (!isEnabled()) return @@ -77,5 +65,5 @@ class JoinCrystalHollows { private fun inTime() = lastWrongPassTime + 1000 * 60 * 2 > System.currentTimeMillis() - fun isEnabled() = SkyHanniMod.feature.misc.crystalHollowsJoin + fun isEnabled() = SkyHanniMod.feature.misc.crystalHollowsJoin }
\ No newline at end of file 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 |