diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-16 19:47:46 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-03-16 19:47:46 +0100 |
commit | 7a7f1b9acb5990b24b8aeea5a435c136bb1bb7db (patch) | |
tree | 438c3e07e61a04f8e4e0a0b6d23abd1797ee2b37 /src/main/java | |
parent | 5ffe5dab3973b540a4e0cd1b57f13d0be77e3f84 (diff) | |
download | skyhanni-7a7f1b9acb5990b24b8aeea5a435c136bb1bb7db.tar.gz skyhanni-7a7f1b9acb5990b24b8aeea5a435c136bb1bb7db.tar.bz2 skyhanni-7a7f1b9acb5990b24b8aeea5a435c136bb1bb7db.zip |
Fixed non god pod time parsing errors
Diffstat (limited to 'src/main/java')
3 files changed, 32 insertions, 34 deletions
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 3535b3fac..09df06dff 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java @@ -80,13 +80,13 @@ public class Misc { public boolean potionEffects = false; @Expose - @ConfigOption(name = "Non-God Pot Effects", desc = "Display the active non-god potion effects.") + @ConfigOption(name = "Non God Pot Effects", desc = "Display the active potion effects that are not part of the god pot.") @ConfigEditorBoolean @ConfigAccordionId(id = 5) public boolean nonGodPotEffectDisplay = false; @Expose - @ConfigOption(name = "Real Time Position", desc = "") + @ConfigOption(name = "Pot Effects Position", desc = "") @ConfigEditorButton(runnableId = "nonGodPotEffect", buttonText = "Edit") @ConfigAccordionId(id = 5) public Position nonGodPotEffectPos = new Position(10, 10, false, true); diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt index 46a6aff78..7ae821011 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/NonGodPotEffectDisplay.kt @@ -132,7 +132,7 @@ class NonGodPotEffectDisplay { if (name in nonGodPotEffects.values) { for (line in stack.getLore()) { if (line.contains("Remaining")) { - val duration = readDuration(line.split("§f")[1]) + val duration = TimeUtils.getMillis(line.split("§f")[1]) activeEffects[name] = System.currentTimeMillis() + duration format() } @@ -152,7 +152,7 @@ class NonGodPotEffectDisplay { var effectsCount = 0 for (line in lines) { if (line.startsWith("§2Mushed Glowy Tonic I")) { - val duration = readDuration(line.split("§f")[1]) + val duration = TimeUtils.getMillis(line.split("§f")[1]) activeEffects["§2Mushed Glowy Tonic I"] = System.currentTimeMillis() + duration format() } @@ -166,32 +166,6 @@ class NonGodPotEffectDisplay { } } - private fun readDuration(text: String): Int { - val split = text.split(":") - return when (split.size) { - 3 -> { - val hours = split[0].toInt() * 1000 * 60 * 60 - val minutes = split[1].toInt() * 1000 * 60 - val seconds = split[2].toInt() * 1000 - seconds + minutes + hours - } - - 2 -> { - val minutes = split[0].toInt() * 1000 * 60 - val seconds = split[1].toInt() * 1000 - seconds + minutes - } - - 1 -> { - split[0].toInt() * 1000 - } - - else -> { - throw RuntimeException("Invalid format: '$text'") - } - } - } - @SubscribeEvent fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) { if (!isEnabled()) return diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt index 82a8532a1..0e4561041 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt @@ -11,7 +11,7 @@ object TimeUtils { millis: Long, biggestUnit: TimeUnit = TimeUnit.YEAR, showMilliSeconds: Boolean = false, - longName: Boolean = false + longName: Boolean = false, ): String { var milliseconds = millis + 999 val map = mutableMapOf<TimeUnit, Int>() @@ -50,9 +50,7 @@ object TimeUtils { fun getMillis(string: String): Long { val matcher = pattern.matcher(string.lowercase().trim()) - if (!matcher.matches()) { - throw RuntimeException("Matcher is null for '$string'") - } + if (!matcher.matches()) return tryAlternativeFormat(string) val years = matcher.group("y")?.toLong() ?: 0L val days = matcher.group("d")?.toLong() ?: 0L @@ -69,6 +67,32 @@ object TimeUtils { return millis } + + private fun tryAlternativeFormat(string: String): Long { + val split = string.split(":") + return when (split.size) { + 3 -> { + val hours = split[0].toInt() * 1000 * 60 * 60 + val minutes = split[1].toInt() * 1000 * 60 + val seconds = split[2].toInt() * 1000 + seconds + minutes + hours + } + + 2 -> { + val minutes = split[0].toInt() * 1000 * 60 + val seconds = split[1].toInt() * 1000 + seconds + minutes + } + + 1 -> { + split[0].toInt() * 1000 + } + + else -> { + throw RuntimeException("Invalid format: '$string'") + } + }.toLong() + } } private const val FACTOR_SECONDS = 1000L |