aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/utils')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt22
3 files changed, 17 insertions, 20 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
index 0b197e0d9..8c653edd7 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/MinecraftConsoleFilter.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Marker
@@ -118,7 +119,7 @@ class MinecraftConsoleFilter(private val loggerConfigName: String) : Filter {
// }
// }
if (SkyHanniMod.feature.dev.filterBiomeIdBounds) {
- if (patternBiomeIdBounds.matcher(formattedMessage).matches()) {
+ patternBiomeIdBounds.matchMatcher(formattedMessage) {
filterConsole("Biome ID bounds")
return Filter.Result.DENY
}
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
index 721547ef4..76da79bc5 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/NEUItems.kt
@@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.utils
import at.hannibal2.skyhanni.utils.ItemBlink.checkBlinkItem
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimal
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import io.github.moulberry.notenoughupdates.NEUManager
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import io.github.moulberry.notenoughupdates.recipes.CraftingRecipe
@@ -32,15 +33,12 @@ object NEUItems {
return itemNameCache[itemName]!!
}
- val matcher = turboBookPattern.matcher(itemName)
- var internalName = if (matcher.matches()) {
- val type = matcher.group("name")
- val level = matcher.group("level").romanToDecimal()
+ var internalName = turboBookPattern.matchMatcher(itemName) {
+ val type = group("name")
+ val level = group("level").romanToDecimal()
val name = turboCheck(type).uppercase()
"TURBO_$name;$level"
- } else {
- ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) ?: return null
- }
+ } ?: ItemResolutionQuery.findInternalNameByDisplayName(itemName, false) ?: return null
// This fixes a NEU bug with ยง9Hay Bale (cosmetic item)
// TODO remove workaround when this is fixed in neu
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
index 138c70804..df780b300 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
@@ -1,7 +1,8 @@
package at.hannibal2.skyhanni.utils
-object TimeUtils {
+import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
+object TimeUtils {
private val pattern =
"(?:(?<y>\\d+) ?y(?:\\w* ?)?)?(?:(?<d>\\d+) ?d(?:\\w* ?)?)?(?:(?<h>\\d+) ?h(?:\\w* ?)?)?(?:(?<m>\\d+) ?m(?:\\w* ?)?)?(?:(?<s>\\d+) ?s(?:\\w* ?)?)?".toPattern()
@@ -54,15 +55,12 @@ object TimeUtils {
}
// TODO: use kotlin Duration
- fun getMillis(string: String): Long {
- val matcher = pattern.matcher(string.lowercase().trim())
- if (!matcher.matches()) return tryAlternativeFormat(string)
-
- val years = matcher.group("y")?.toLong() ?: 0L
- val days = matcher.group("d")?.toLong() ?: 0L
- val hours = matcher.group("h")?.toLong() ?: 0L
- val minutes = matcher.group("m")?.toLong() ?: 0L
- val seconds = matcher.group("s")?.toLong() ?: 0L
+ fun getMillis(string: String) = pattern.matchMatcher(string.lowercase().trim()) {
+ val years = group("y")?.toLong() ?: 0L
+ val days = group("d")?.toLong() ?: 0L
+ val hours = group("h")?.toLong() ?: 0L
+ val minutes = group("m")?.toLong() ?: 0L
+ val seconds = group("s")?.toLong() ?: 0L
var millis = 0L
millis += seconds * 1000
@@ -71,8 +69,8 @@ object TimeUtils {
millis += days * 24 * 60 * 60 * 1000
millis += (years * 365.25 * 24 * 60 * 60 * 1000).toLong()
- return millis
- }
+ millis
+ } ?: tryAlternativeFormat(string)
private fun tryAlternativeFormat(string: String): Long {
val split = string.split(":")