diff options
Diffstat (limited to 'src/main/java/at/hannibal2')
3 files changed, 43 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 42e906148..9c3ccb021 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -280,6 +280,7 @@ class SkyHanniMod { loadModule(SackDisplay()) loadModule(GardenStartLocation) loadModule(PetCandyUsedDisplay()) + loadModule(ServerRestartTitle()) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java index 9db9ea8de..72e13e528 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java @@ -421,6 +421,11 @@ public class Misc { public boolean petCandyUsed = true; @Expose + @ConfigOption(name = "Server Restart Title", desc = "Show an title with seconds remaining until the server restarts after a Aame Update or Sheduled Restart.") + @ConfigEditorBoolean + public boolean serverRestartTitle = true; + + @Expose @ConfigOption(name = "Config Button", desc = "Add a button to the pause menu to configure SkyHanni.") @ConfigEditorBoolean public boolean configButtonOnPause = true; 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) + } + } + } +} |