aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/misc
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-10-08 14:58:29 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-10-08 14:58:29 +0200
commit79ca9b0494f88fed8030911fe994165a1c072f2f (patch)
tree6bc00efd9dfb24aa0d7205199802dce6c5d9820e /src/main/java/at/hannibal2/skyhanni/features/misc
parent261e4012d6f7e129f7311f270147caddcc20a22a (diff)
downloadskyhanni-79ca9b0494f88fed8030911fe994165a1c072f2f.tar.gz
skyhanni-79ca9b0494f88fed8030911fe994165a1c072f2f.tar.bz2
skyhanni-79ca9b0494f88fed8030911fe994165a1c072f2f.zip
Added Kick Duration and Time In Limbo
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/LimboTimeTracker.kt51
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/SkyBlockKickDuration.kt76
2 files changed, 127 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/LimboTimeTracker.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/LimboTimeTracker.kt
new file mode 100644
index 000000000..395cfcecd
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/LimboTimeTracker.kt
@@ -0,0 +1,51 @@
+package at.hannibal2.skyhanni.features.misc
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.TimeUtils.format
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.seconds
+
+class LimboTimeTracker {
+ private val config get() = SkyHanniMod.feature.misc
+
+ private var limboJoinTime = SimpleTimeMark.farPast()
+ private var inLimbo = false
+
+ @SubscribeEvent
+ fun onChat(event: LorenzChatEvent) {
+ if (event.message == "§cYou are AFK. Move around to return from AFK.") {
+ limboJoinTime = SimpleTimeMark.now()
+ inLimbo = true
+ }
+ }
+
+ @SubscribeEvent
+ fun onWorldChange(event: LorenzWorldChangeEvent) {
+ if (!inLimbo) return
+
+ val passedSince = limboJoinTime.passedSince()
+ val duration = passedSince.format()
+ if (passedSince > 5.seconds) {
+ inLimbo = false
+ if (!isEnabled()) return
+ LorenzUtils.run { chat("§e[SkyHanni] You left the limbo after §b$duration") }
+ }
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
+ if (!isEnabled()) return
+ if (!inLimbo) return
+
+ val duration = limboJoinTime.passedSince().format()
+ config.showTimeInLimboPosition.renderString("§eIn limbo since §b$duration", posLabel = "Limbo Time Tracker")
+ }
+
+ fun isEnabled() = config.showTimeInLimbo
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/SkyBlockKickDuration.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/SkyBlockKickDuration.kt
new file mode 100644
index 000000000..c571a2d63
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/SkyBlockKickDuration.kt
@@ -0,0 +1,76 @@
+package at.hannibal2.skyhanni.features.misc
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.TitleUtils
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.LorenzChatEvent
+import at.hannibal2.skyhanni.events.LorenzWorldChangeEvent
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import at.hannibal2.skyhanni.utils.SimpleTimeMark
+import at.hannibal2.skyhanni.utils.TimeUtils.format
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import kotlin.time.Duration.Companion.minutes
+import kotlin.time.Duration.Companion.seconds
+
+class SkyBlockKickDuration {
+ private val config get() = SkyHanniMod.feature.misc.kickDuration
+
+ var kickMessage = false
+ var showTime = false
+ var lastKickTime = SimpleTimeMark.farPast()
+ var hasWarned = false
+
+ @SubscribeEvent
+ fun onChat(event: LorenzChatEvent) {
+ if (!isEnabled()) return
+ if (event.message == "§cYou were kicked while joining that server!") {
+ kickMessage = true
+ }
+ }
+
+ @SubscribeEvent
+ fun onWorldChange(event: LorenzWorldChangeEvent) {
+ if (!isEnabled()) return
+ if (kickMessage) {
+ kickMessage = false
+ showTime = true
+ lastKickTime = SimpleTimeMark.farPast()
+ }
+ hasWarned = false
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
+ if (!isEnabled()) return
+ if (!LorenzUtils.onHypixel) return
+ if (!showTime) return
+
+ if (LorenzUtils.inSkyBlock) {
+ showTime = false
+ }
+
+ if (lastKickTime.passedSince() > 5.minutes) {
+ showTime = false
+ }
+
+ if (lastKickTime.passedSince() > config.warnTime.get().seconds) {
+ if (!hasWarned) {
+ hasWarned = true
+ warn()
+ }
+ }
+
+ val format = lastKickTime.passedSince().format()
+ config.position.renderString(
+ "§cLast kicked from SkyBlock §b$format ago",
+ posLabel = "SkyBlock Kick Duration"
+ )
+ }
+
+ private fun warn() {
+ TitleUtils.sendTitle("§eTry rejoining SkyBlock now!", 3.seconds)
+ }
+
+ fun isEnabled() = config.enabled
+}