diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-02 23:30:22 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-11-02 23:30:22 +0100 |
commit | 27f0b207793ddedf406fd56521d0ae0537279661 (patch) | |
tree | 86eac7c15b1253536db7b781acc7019f0196bc64 /src | |
parent | d3e11684c9efb0635f5199183f9b97ff748c54be (diff) | |
download | skyhanni-27f0b207793ddedf406fd56521d0ae0537279661.tar.gz skyhanni-27f0b207793ddedf406fd56521d0ae0537279661.tar.bz2 skyhanni-27f0b207793ddedf406fd56521d0ae0537279661.zip |
code cleanup
Diffstat (limited to 'src')
5 files changed, 54 insertions, 27 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/GUIConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/GUIConfig.java index 177c0b3ce..79df5cdd8 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/GUIConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/GUIConfig.java @@ -98,15 +98,15 @@ public class GUIConfig { @Expose @ConfigOption(name = "In-Game Date", desc = "") @Accordion - public InGameDateConfig inGameDateConfig = new InGameDateConfig(); + public InGameDateConfig inGameDate = new InGameDateConfig(); public static class InGameDateConfig { @Expose @ConfigOption( - name = "Enabled", - desc = "Show the in-game date of SkyBlock (like in Apec, §ebut with mild delays§7).\n" + - "(Though this one includes the SkyBlock year!)" + name = "Enabled", + desc = "Show the in-game date of SkyBlock (like in Apec, §ebut with mild delays§7).\n" + + "(Though this one includes the SkyBlock year!)" ) @ConfigEditorBoolean @FeatureToggle @@ -117,8 +117,8 @@ public class GUIConfig { @Expose @ConfigOption( - name = "Use Scoreboard for Date", - desc = "Uses the scoreboard instead to find the current month, date, and time. Greater \"accuracy\", depending on who's asking." + name = "Use Scoreboard for Date", + desc = "Uses the scoreboard instead to find the current month, date, and time. Greater \"accuracy\", depending on who's asking." ) @ConfigEditorBoolean @FeatureToggle @@ -126,8 +126,8 @@ public class GUIConfig { @Expose @ConfigOption( - name = "Show Sun/Moon", - desc = "Show the sun or moon symbol seen on the scoreboard." + name = "Show Sun/Moon", + desc = "Show the sun or moon symbol seen on the scoreboard." ) @ConfigEditorBoolean @FeatureToggle @@ -135,13 +135,14 @@ public class GUIConfig { @Expose @ConfigOption( - name = "Refresh Rate", - desc = "Change the time in seconds you would like to refresh the In-Game Date Display.\n§eNOTE: If \"Use Scoreboard for Date\" is enabled, this setting is ignored." + name = "Refresh Rate", + desc = "Change the time in seconds you would like to refresh the In-Game Date Display." + + "\n§eNOTE: If \"Use Scoreboard for Date\" is enabled, this setting is ignored." ) @ConfigEditorSlider( - minValue = 1, - maxValue = 60, - minStep = 1 + minValue = 1, + maxValue = 60, + minStep = 1 ) public int refreshSeconds = 30; } 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<String>() + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + sunMoonIcons = event.getConstant<TabListJson>("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 diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 28afe3b4e..751271510 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -139,6 +139,7 @@ object LorenzUtils { } // TODO replace all calls with regex + @Deprecated("Do not use complicated string operations", ReplaceWith("Regex")) fun String.between(start: String, end: String): String = this.split(start, end)[1] // TODO use derpy() on every use case @@ -426,11 +427,12 @@ object LorenzUtils { val tileSign = (this as AccessorGuiEditSign).tileSign return (tileSign.signText[1].unformattedText.removeColor() == "^^^^^^" - && tileSign.signText[2].unformattedText.removeColor() == "Set your" - && tileSign.signText[3].unformattedText.removeColor() == "speed cap!") + && tileSign.signText[2].unformattedText.removeColor() == "Set your" + && tileSign.signText[3].unformattedText.removeColor() == "speed cap!") } - fun inIsland(island: IslandType) = inSkyBlock && (skyBlockIsland == island || island == IslandType.CATACOMBS && inDungeons) + fun inIsland(island: IslandType) = + inSkyBlock && (skyBlockIsland == island || island == IslandType.CATACOMBS && inDungeons) fun IslandType.isInIsland() = inIsland(this) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 66eb0faad..0900b3812 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -235,4 +235,6 @@ object StringUtils { fun String.convertToFormatted(): String { return this.replace("&&", "§") } -}
\ No newline at end of file + + fun Pattern.matches(string: String) = matcher(string).matches() +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/TabListJson.java b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/TabListJson.java new file mode 100644 index 000000000..03c256256 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/jsonobjects/TabListJson.java @@ -0,0 +1,11 @@ +package at.hannibal2.skyhanni.utils.jsonobjects; + +import com.google.gson.annotations.Expose; + +import java.util.List; + +public class TabListJson { + + @Expose + public List<String> sun_moon_symbols; +} |