diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-16 13:22:30 +0200 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-09-16 13:22:30 +0200 |
commit | 2d920a7f83fd700cc2b0d9bfda387e66c683f885 (patch) | |
tree | 5121bb30dc13c8e665d535879f376d9f764742b5 /src/main | |
parent | 6c13cb57483fe7aa11e45fb98f927bda49e0ba73 (diff) | |
download | skyhanni-2d920a7f83fd700cc2b0d9bfda387e66c683f885.tar.gz skyhanni-2d920a7f83fd700cc2b0d9bfda387e66c683f885.tar.bz2 skyhanni-2d920a7f83fd700cc2b0d9bfda387e66c683f885.zip |
create and use JsonPrimitive.asIntOrNull
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt | 4 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt | 3 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index b0446f62e..bba813430 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -2,6 +2,7 @@ package at.hannibal2.skyhanni.config import at.hannibal2.skyhanni.events.LorenzEvent import at.hannibal2.skyhanni.utils.LorenzLogger +import at.hannibal2.skyhanni.utils.LorenzUtils.asIntOrNull import com.google.gson.JsonElement import com.google.gson.JsonObject import com.google.gson.JsonPrimitive @@ -69,8 +70,7 @@ object ConfigUpdaterMigrator { } fun fixConfig(config: JsonObject): JsonObject { - val lV = (config.get("lastVersion") as? JsonPrimitive) - ?.takeIf { it.isNumber }?.asInt ?: -1 + val lV = (config.get("lastVersion") as? JsonPrimitive)?.asIntOrNull ?: -1 if (lV == configVersion) return config logger.log("Starting config transformation from $lV to $configVersion") val migration = ConfigFixEvent(config, JsonObject().also { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 9085b96e8..a96937b88 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.StringUtils.capAtMinecraftLength import at.hannibal2.skyhanni.utils.StringUtils.removeColor import at.hannibal2.skyhanni.utils.StringUtils.toDashlessUUID import at.hannibal2.skyhanni.utils.renderables.Renderable +import com.google.gson.JsonPrimitive import io.github.moulberry.moulconfig.observer.Observer import io.github.moulberry.moulconfig.observer.Property import io.github.moulberry.notenoughupdates.util.SkyBlockTime @@ -530,4 +531,6 @@ object LorenzUtils { val modifierHeld = if (SystemUtils.IS_OS_MAC) isCommandKeyDown() else isControlKeyDown() return modifierHeld && OSUtils.isKeyHeld(Keyboard.KEY_V) } + + val JsonPrimitive.asIntOrNull get() = takeIf { it.isNumber }?.asInt } |