diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-25 12:04:49 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-05-25 12:04:49 +0200 |
commit | c03cdfcbd136e3eceb2128c5c4d8293e39476ed4 (patch) | |
tree | 8664d0695a342b2713e0ee738dd37df95a0bc062 /src/main/java/at/hannibal2/skyhanni/features/misc | |
parent | d7b382ab6fde6d27fe0bd40dbd28b7acc4422eca (diff) | |
download | skyhanni-c03cdfcbd136e3eceb2128c5c4d8293e39476ed4.tar.gz skyhanni-c03cdfcbd136e3eceb2128c5c4d8293e39476ed4.tar.bz2 skyhanni-c03cdfcbd136e3eceb2128c5c4d8293e39476ed4.zip |
Added Server Restart Title
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/ServerRestartTitle.kt | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ServerRestartTitle.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ServerRestartTitle.kt new file mode 100644 index 000000000..852580a8d --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ServerRestartTitle.kt @@ -0,0 +1,37 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.data.ScoreboardData +import at.hannibal2.skyhanni.data.TitleUtils +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.TimeUtils +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent + +class ServerRestartTitle { + private val config get() = SkyHanniMod.feature.misc + private var tick = 0 + private val pattern = "§cServer closing: (?<minutes>\\d+):(?<seconds>\\d+) §8.*".toPattern() + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!LorenzUtils.inSkyBlock) return + if (!config.serverRestartTitle) return + + if (event.phase != TickEvent.Phase.START) return + tick++ + + if (tick % 20 != 0) return + + for (line in ScoreboardData.sidebarLinesFormatted) { + pattern.matchMatcher(line) { + val minutes = group("minutes").toInt() + val seconds = group("seconds").toInt() + val totalSeconds = minutes * 60 + seconds + val time = TimeUtils.formatDuration(totalSeconds.toLong() * 1000) + TitleUtils.sendTitle("§cServer Restart in §b$time", 2_000) + } + } + } +} |