diff options
Diffstat (limited to 'src/main/java/at')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/misc/HypixelData.kt | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/misc/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/misc/HypixelData.kt index 89db5edaf..9ee0982fa 100644 --- a/src/main/java/at/hannibal2/skyhanni/misc/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/misc/HypixelData.kt @@ -6,18 +6,18 @@ import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.utils.LorenzUtils.removeColorCodes import net.minecraft.client.Minecraft import net.minecraft.network.play.server.S38PacketPlayerListItem -import net.minecraft.network.play.server.S3DPacketDisplayScoreboard import net.minecraftforge.event.world.WorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent import net.minecraftforge.fml.common.network.FMLNetworkEvent class HypixelData { companion object { - var hypixel = false - var skyblock = false - var dungeon = false -} + var hypixel = false + var skyblock = false + var dungeon = false + } @SubscribeEvent fun onConnect(event: FMLNetworkEvent.ClientConnectedToServerEvent) { @@ -27,13 +27,6 @@ class HypixelData { }.onFailure { it.printStackTrace() }.getOrDefault(false) } - @SubscribeEvent - fun onScoreboardChange(event: PacketEvent.ReceiveEvent) { - if (!hypixel || skyblock || event.packet !is S3DPacketDisplayScoreboard) return - if (event.packet.func_149371_c() != 1) return - skyblock = event.packet.func_149370_d() == "SBScoreboard" - } - val areaRegex = Regex("§r§b§l(?<area>[\\w]+): §r§7(?<loc>[\\w ]+)§r") @SubscribeEvent @@ -71,13 +64,43 @@ class HypixelData { val message = event.message.removeColorCodes().lowercase() if (message.startsWith("your profile was changed to:")) { - val stripped = message.replace("your profile was changed to:", "").replace("(co-op)", "").trim(); + val stripped = message.replace("your profile was changed to:", "").replace("(co-op)", "").trim() ProfileJoinEvent(stripped).postAndCatch() } if (message.startsWith("you are playing on profile:")) { - val stripped = message.replace("you are playing on profile:", "").replace("(co-op)", "").trim(); + val stripped = message.replace("you are playing on profile:", "").replace("(co-op)", "").trim() ProfileJoinEvent(stripped).postAndCatch() } } + + var timerTick = 0 + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!hypixel) return + if (event.phase != TickEvent.Phase.START) return + + timerTick++ + + if (timerTick % 5 != 0) return + + val newState = checkScoreboard() + if (newState == skyblock) return + + skyblock = newState + } + + private fun checkScoreboard(): Boolean { + val minecraft = Minecraft.getMinecraft() + val world = minecraft.theWorld ?: return false + + val sidebarObjective = world.scoreboard.getObjectiveInDisplaySlot(1) ?: return false + + val displayName = sidebarObjective.displayName + + return displayName.removeColorCodes().contains("SKYBLOCK") + + } + }
\ No newline at end of file |