package at.hannibal2.skyhanni.features.misc import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.SecondPassedEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RegexUtils.matchFirst import at.hannibal2.skyhanni.utils.TimeUtils.format import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern import net.minecraftforge.fml.common.eventhandler.SubscribeEvent import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds object ServerRestartTitle { private val config get() = SkyHanniMod.feature.misc private val patternGroup = RepoPattern.group("features.misc.serverrestart") private val restartingPattern by patternGroup.pattern( "time", "§cServer closing: (?\\d+):(?\\d+) ?§8.*" ) val restartingGreedyPattern by patternGroup.pattern( "greedy", "§cServer closing.*" ) @SubscribeEvent fun onSecondPassed(event: SecondPassedEvent) { if (!LorenzUtils.inSkyBlock) return if (!config.serverRestartTitle) return ScoreboardData.sidebarLinesFormatted.matchFirst(restartingPattern) { val minutes = group("minutes").toInt().minutes val seconds = group("seconds").toInt().seconds val totalTime = minutes + seconds if (totalTime > 2.minutes && totalTime.inWholeSeconds % 30 != 0L) return val time = totalTime.format() LorenzUtils.sendTitle("§cServer Restart in §b$time", 2.seconds) } } }