From 27f0b207793ddedf406fd56521d0ae0537279661 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Thu, 2 Nov 2023 23:30:22 +0100 Subject: code cleanup --- .../skyhanni/features/misc/InGameDateDisplay.kt | 31 +++++++++++++++------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc') diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/InGameDateDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/InGameDateDisplay.kt index 1874d1143..1b08e7ebd 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/InGameDateDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/InGameDateDisplay.kt @@ -4,23 +4,33 @@ import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.ScoreboardData import at.hannibal2.skyhanni.events.GuiRenderEvent import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.events.RepositoryReloadEvent import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString -import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.matches import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeUtils.formatted +import at.hannibal2.skyhanni.utils.jsonobjects.TabListJson import io.github.moulberry.notenoughupdates.util.SkyBlockTime import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class InGameDateDisplay { - private val config get() = SkyHanniMod.feature.gui.inGameDateConfig - private val monthAndDatePattern = ".*((Early|Late) )?(Winter|Spring|Summer|Autumn) [0-9]{1,2}(nd|rd|th|st).*".toPattern() + private val config get() = SkyHanniMod.feature.gui.inGameDate + private val monthAndDatePattern = + ".*((Early|Late) )?(Winter|Spring|Summer|Autumn) [0-9]{1,2}(nd|rd|th|st).*".toPattern() private var display = "" + // sun, moon, spooky + private var sunMoonIcons = emptyList() + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + sunMoonIcons = event.getConstant("TabList").sun_moon_symbols + } + @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!isEnabled()) return - if (!LorenzUtils.inSkyBlock) return if (!config.useScoreboard && !event.repeatSeconds(config.refreshSeconds)) return if (config.useScoreboard && !event.repeatSeconds(1)) return @@ -33,16 +43,17 @@ class InGameDateDisplay { if (config.useScoreboard) { val list = ScoreboardData.sidebarLinesFormatted //we need this to grab the moon/sun symbol val year = "Year ${date.year}" - var monthAndDate = "??" //initalize as "??" as fallback value in case none of the scoreboard lines match - for (line in list) { monthAndDatePattern.matchMatcher(line) { monthAndDate = line } } - val time = list.find{ it.lowercase().contains("am ") || it.lowercase().contains("pm ") } ?: "??" + val monthAndDate = list.find { monthAndDatePattern.matches(it) } ?: "??" + val time = list.find { it.lowercase().contains("am ") || it.lowercase().contains("pm ") } ?: "??" theBaseString = "$monthAndDate, $year ${time.trim()}".removeColor() - if (!config.includeSunMoon) theBaseString = theBaseString.replace("☽", "").replace("☀", "").replace("࿇", "") + if (!config.includeSunMoon) { + sunMoonIcons.forEach { theBaseString = theBaseString.replace(it, "") } + } } else { theBaseString = date.formatted() if (config.includeSunMoon) { - if ((date.hour >= 6) && (date.hour < 17)) theBaseString = "$theBaseString ☀" - else theBaseString = "$theBaseString ☽" + theBaseString = if ((date.hour >= 6) && (date.hour < 17)) "$theBaseString ☀" + else "$theBaseString ☽" } } display = theBaseString -- cgit