From c03cdfcbd136e3eceb2128c5c4d8293e39476ed4 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 25 May 2023 12:04:49 +0200 Subject: Added Server Restart Title --- CHANGELOG.md | 3 +- FEATURES.md | 1 + src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 1 + .../hannibal2/skyhanni/config/features/Misc.java | 5 +++ .../skyhanni/features/misc/ServerRestartTitle.kt | 37 ++++++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/ServerRestartTitle.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index b1605d7ec..09d3f347a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ + Option to show prices from Bazaar or NPC + Added Farming Fortune Breakdown for Armor and Equipment (Contributed by CalMWolfs) + Works with: Base Stats, Reforge Bonus, Ability Fortune and Green Thumb -+ Fixed Hypixel bug that the equipment lore talks about "kills" instead of "visitors" (Contributed by CalMWolfs) ++ Added Server Restart Title ### Changes + Added Options for displays Crop Milestone and Best Crop Time. @@ -31,6 +31,7 @@ ### Fixes = Fixed typos in Trevor Trapper texts (Contributed by CalMWolfs) += Fixed Hypixel bug that the equipment lore talks about "kills" instead of "visitors" (Contributed by CalMWolfs) ## Version 0.17 (2023-05-11) diff --git a/FEATURES.md b/FEATURES.md index afeb6f931..d59b02bec 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -261,3 +261,4 @@ + **CH Join** - Helps buy a Pass for accessing the Crystal Hollows if needed. + **Estimated Item Value** - Displays an estimated item value for the item you hover over. + **Discord RPC** - Showing stats like Location, Purse, Bits, Purse or Held Item at Discord Rich Presence. - (contributed by NetheriteMiner) ++ Server Restart Title 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 @@ -420,6 +420,11 @@ public class Misc { @ConfigEditorBoolean 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 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: (?\\d+):(?\\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) + } + } + } +} -- cgit