diff options
author | Erymanthus[#5074] | (u/)RayDeeUx <51521765+RayDeeUx@users.noreply.github.com> | 2023-11-02 18:29:05 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-02 23:29:05 +0100 |
commit | d3e11684c9efb0635f5199183f9b97ff748c54be (patch) | |
tree | 587168e150cf98898cbf1e6f51cdd68cc75175eb /src/main/java/at/hannibal2/skyhanni/features | |
parent | 5052aca0aada1d964117542b00220c2f200c6d74 (diff) | |
download | skyhanni-d3e11684c9efb0635f5199183f9b97ff748c54be.tar.gz skyhanni-d3e11684c9efb0635f5199183f9b97ff748c54be.tar.bz2 skyhanni-d3e11684c9efb0635f5199183f9b97ff748c54be.zip |
Feature(s): Add scoreboard as data source + sunmoon (#576)
In-Game Date: Adds support for reading the in-game scoreboard, and also allow sun/moon symbol customization. #576
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/InGameDateDisplay.kt | 27 |
1 files changed, 25 insertions, 2 deletions
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 028b0edbc..1874d1143 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/InGameDateDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/InGameDateDisplay.kt @@ -1,28 +1,51 @@ package at.hannibal2.skyhanni.features.misc 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.utils.LorenzUtils import at.hannibal2.skyhanni.utils.RenderUtils.renderString +import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher +import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.TimeUtils.formatted 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 var display = "" @SubscribeEvent fun onTick(event: LorenzTickEvent) { if (!isEnabled()) return - if (!event.repeatSeconds(config.RefreshSeconds)) return + if (!LorenzUtils.inSkyBlock) return + if (!config.useScoreboard && !event.repeatSeconds(config.refreshSeconds)) return + if (config.useScoreboard && !event.repeatSeconds(1)) return checkDate() } private fun checkDate() { - display = SkyBlockTime.now().formatted() + val date = SkyBlockTime.now() + var theBaseString: String + 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 ") } ?: "??" + theBaseString = "$monthAndDate, $year ${time.trim()}".removeColor() + if (!config.includeSunMoon) theBaseString = theBaseString.replace("☽", "").replace("☀", "").replace("࿇", "") + } else { + theBaseString = date.formatted() + if (config.includeSunMoon) { + if ((date.hour >= 6) && (date.hour < 17)) theBaseString = "$theBaseString ☀" + else theBaseString = "$theBaseString ☽" + } + } + display = theBaseString } @SubscribeEvent |