aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-16 14:28:14 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-09-16 14:28:14 +0200
commit1fb1be3ea1e6e805f16ab09f5a0d88651c8976c1 (patch)
tree1a85faf46be87744f54c613e43426f4a30b241ea
parent2d920a7f83fd700cc2b0d9bfda387e66c683f885 (diff)
downloadskyhanni-1fb1be3ea1e6e805f16ab09f5a0d88651c8976c1.tar.gz
skyhanni-1fb1be3ea1e6e805f16ab09f5a0d88651c8976c1.tar.bz2
skyhanni-1fb1be3ea1e6e805f16ab09f5a0d88651c8976c1.zip
fixed migration problems with different versions and added edge case supports
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt33
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Features.java4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt4
3 files changed, 30 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
index bba813430..2b2d6f756 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt
@@ -9,7 +9,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {
val logger = LorenzLogger("ConfigMigration")
- val configVersion = 1
+ val configVersion = 2
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
@@ -33,6 +33,13 @@ object ConfigUpdaterMigrator {
logger.log("Skipping move from $oldPath to $newPath ($since <= $oldVersion)")
return
}
+ if (since > configVersion) {
+ error("Illegally new version $since > $configVersion")
+ }
+ if (since > oldVersion + 1) {
+ logger.log("Skipping move from $oldPath to $newPath (will be done in another pass)")
+ return
+ }
val op = oldPath.split(".")
val np = newPath.split(".")
val oldElem = old.at(op, false)
@@ -71,15 +78,21 @@ object ConfigUpdaterMigrator {
fun fixConfig(config: JsonObject): JsonObject {
val lV = (config.get("lastVersion") as? JsonPrimitive)?.asIntOrNull ?: -1
+ if (lV > configVersion) {
+ error("Cannot downgrade config")
+ }
if (lV == configVersion) return config
- logger.log("Starting config transformation from $lV to $configVersion")
- val migration = ConfigFixEvent(config, JsonObject().also {
- it.add("lastVersion", JsonPrimitive(configVersion))
- }, lV, 0).also { it.postAndCatch() }
- logger.log("Transformations scheduled: ${migration.new}")
- val mergesPerformed = merge(migration.old, migration.new)
- logger.log("Migration done with $mergesPerformed merges and ${migration.movesPerformed} moves performed")
- return migration.old
+ return (lV until configVersion).fold(config) { acc, i ->
+ logger.log("Starting config transformation from $i to ${i + 1}")
+ val migration = ConfigFixEvent(acc, JsonObject().also {
+ it.add("lastVersion", JsonPrimitive(i + 1))
+ }, i, 0).also { it.postAndCatch() }
+ logger.log("Transformations scheduled: ${migration.new}")
+ val mergesPerformed = merge(migration.old, migration.new)
+ logger.log("Migration done with $mergesPerformed merges and ${migration.movesPerformed} moves performed")
+ migration.old
+ }.also {
+ logger.log("Final config: $it")
+ }
}
-
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java
index 149f66020..9b95f8a10 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Features.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java
@@ -72,6 +72,10 @@ public class Features extends Config {
public AshfangConfig ashfang = new AshfangConfig();
@Expose
+ @Category(name = "Crimson Isle", desc = "Crimson isle nether features.")
+ public CrimsonIsleConfig crimsonIsle = new CrimsonIsleConfig();
+
+ @Expose
@Category(name = "Minion", desc = "The minions at your private island.")
public MinionsConfig minions = new MinionsConfig();
diff --git a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt
index a4d24e0dc..62376c698 100644
--- a/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt
+++ b/src/main/java/at/hannibal2/skyhanni/events/LorenzEvent.kt
@@ -12,7 +12,7 @@ abstract class LorenzEvent : Event() {
fun postAndCatch(): Boolean {
return runCatching {
- MinecraftForge.EVENT_BUS.post(this)
+ postWithoutCatch()
}.onFailure {
CopyErrorCommand.logError(
it,
@@ -20,4 +20,6 @@ abstract class LorenzEvent : Event() {
)
}.getOrDefault(isCanceled)
}
+
+ fun postWithoutCatch() = MinecraftForge.EVENT_BUS.post(this)
} \ No newline at end of file