Improve and fix minor migration regressions

This commit is contained in:
Ben Woo 2023-09-10 11:55:00 +08:00
parent fcbaffc821
commit 13b9419b85
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
5 changed files with 53 additions and 16 deletions

View File

@ -19,6 +19,6 @@ public class LongMigratorAction implements MigratorAction {
@Override @Override
public void migrate(ConfigurationSection config) { public void migrate(ConfigurationSection config) {
config.set(path, ACFUtil.parseLong(config.getString(path))); config.set(path, ACFUtil.parseLong(config.getString(path)));
Logging.info("Converted %s to integer %s", path, config.getLong(path)); Logging.info("Converted %s to long %s", path, config.getLong(path));
} }
} }

View File

@ -0,0 +1,23 @@
package com.onarandombox.MultiverseCore.configuration.migration;
import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.configuration.ConfigurationSection;
public class NullStringMigratorAction implements MigratorAction {
public static NullStringMigratorAction of(String path) {
return new NullStringMigratorAction(path);
}
private final String path;
protected NullStringMigratorAction(String path) {
this.path = path;
}
@Override
public void migrate(ConfigurationSection config) {
config.set(path, "null".equals(config.getString(path)) ? "" : config.getString(path));
Logging.info("Converted %s to %s", path, config.getString(path));
}
}

View File

@ -7,6 +7,7 @@ import com.onarandombox.MultiverseCore.configuration.migration.ConfigMigrator;
import com.onarandombox.MultiverseCore.configuration.migration.IntegerMigratorAction; import com.onarandombox.MultiverseCore.configuration.migration.IntegerMigratorAction;
import com.onarandombox.MultiverseCore.configuration.migration.LongMigratorAction; import com.onarandombox.MultiverseCore.configuration.migration.LongMigratorAction;
import com.onarandombox.MultiverseCore.configuration.migration.MoveMigratorAction; import com.onarandombox.MultiverseCore.configuration.migration.MoveMigratorAction;
import com.onarandombox.MultiverseCore.configuration.migration.NullStringMigratorAction;
import com.onarandombox.MultiverseCore.configuration.migration.VersionMigrator; import com.onarandombox.MultiverseCore.configuration.migration.VersionMigrator;
import com.onarandombox.MultiverseCore.world.configuration.AllowedPortalType; import com.onarandombox.MultiverseCore.world.configuration.AllowedPortalType;
import com.onarandombox.MultiverseCore.worldnew.LoadedMultiverseWorld; import com.onarandombox.MultiverseCore.worldnew.LoadedMultiverseWorld;
@ -59,38 +60,39 @@ public final class WorldConfig {
.addAction(BooleanMigratorAction.of("auto-load")) .addAction(BooleanMigratorAction.of("auto-load"))
.addAction(MoveMigratorAction.of("bedRespawn", "bed-respawn")) .addAction(MoveMigratorAction.of("bedRespawn", "bed-respawn"))
.addAction(BooleanMigratorAction.of("bed-respawn")) .addAction(BooleanMigratorAction.of("bed-respawn"))
.addAction(MoveMigratorAction.of("difficulty", "difficulty")) //.addAction(MoveMigratorAction.of("difficulty", "difficulty"))
.addAction(MoveMigratorAction.of("entryfee.amount", "entry-fee.amount")) .addAction(MoveMigratorAction.of("entryfee.amount", "entry-fee.amount"))
.addAction(MoveMigratorAction.of("entryfee.currency", "entry-fee.currency")) .addAction(MoveMigratorAction.of("entryfee.currency", "entry-fee.currency"))
.addAction(MoveMigratorAction.of("environment", "environment")) //.addAction(MoveMigratorAction.of("environment", "environment"))
.addAction(MoveMigratorAction.of("gamemode", "gamemode")) .addAction(MoveMigratorAction.of("gameMode", "gamemode"))
.addAction(MoveMigratorAction.of("generator", "generator")) //.addAction(MoveMigratorAction.of("generator", "generator"))
.addAction(MoveMigratorAction.of("hidden", "hidden")) .addAction(NullStringMigratorAction.of("generator"))
//.addAction(MoveMigratorAction.of("hidden", "hidden"))
.addAction(BooleanMigratorAction.of("hidden")) .addAction(BooleanMigratorAction.of("hidden"))
.addAction(MoveMigratorAction.of("hunger", "hunger")) //.addAction(MoveMigratorAction.of("hunger", "hunger"))
.addAction(BooleanMigratorAction.of("hunger")) .addAction(BooleanMigratorAction.of("hunger"))
.addAction(MoveMigratorAction.of("keepSpawnInMemory", "keep-spawn-in-memory")) .addAction(MoveMigratorAction.of("keepSpawnInMemory", "keep-spawn-in-memory"))
.addAction(BooleanMigratorAction.of("keep-spawn-in-memory")) .addAction(BooleanMigratorAction.of("keep-spawn-in-memory"))
.addAction(MoveMigratorAction.of("playerLimit", "player-limit")) .addAction(MoveMigratorAction.of("playerLimit", "player-limit"))
.addAction(IntegerMigratorAction.of("player-limit")) .addAction(IntegerMigratorAction.of("player-limit"))
.addAction(MoveMigratorAction.of("portalForm", "portal-form")) .addAction(MoveMigratorAction.of("portalForm", "portal-form"))
.addAction(MoveMigratorAction.of("pvp", "pvp")) //.addAction(MoveMigratorAction.of("pvp", "pvp"))
.addAction(BooleanMigratorAction.of("pvp")) .addAction(BooleanMigratorAction.of("pvp"))
.addAction(MoveMigratorAction.of("respawnWorld", "respawn-world")) .addAction(MoveMigratorAction.of("respawnWorld", "respawn-world"))
.addAction(MoveMigratorAction.of("scale", "scale")) //.addAction(MoveMigratorAction.of("scale", "scale"))
.addAction(MoveMigratorAction.of("seed", "seed")) //.addAction(MoveMigratorAction.of("seed", "seed"))
.addAction(LongMigratorAction.of("seed")) .addAction(LongMigratorAction.of("seed"))
.addAction(MoveMigratorAction.of("spawnLocation", "spawn-location")) .addAction(MoveMigratorAction.of("spawnLocation", "spawn-location"))
.addAction(MoveMigratorAction.of("spawning.animals.spawn", "spawning.animals.spawn")) //.addAction(MoveMigratorAction.of("spawning.animals.spawn", "spawning.animals.spawn"))
.addAction(BooleanMigratorAction.of("spawning.animals.spawn")) .addAction(BooleanMigratorAction.of("spawning.animals.spawn"))
.addAction(MoveMigratorAction.of("spawning.animals.amount", "spawning.animals.tick-rate")) .addAction(MoveMigratorAction.of("spawning.animals.amount", "spawning.animals.tick-rate"))
.addAction(IntegerMigratorAction.of("spawning.animals.tick-rate")) .addAction(IntegerMigratorAction.of("spawning.animals.tick-rate"))
.addAction(MoveMigratorAction.of("spawning.animals.exceptions", "spawning.animals.exceptions")) //.addAction(MoveMigratorAction.of("spawning.animals.exceptions", "spawning.animals.exceptions"))
.addAction(MoveMigratorAction.of("spawning.monsters.spawn", "spawning.monsters.spawn")) //.addAction(MoveMigratorAction.of("spawning.monsters.spawn", "spawning.monsters.spawn"))
.addAction(BooleanMigratorAction.of("spawning.monsters.spawn")) .addAction(BooleanMigratorAction.of("spawning.monsters.spawn"))
.addAction(MoveMigratorAction.of("spawning.monsters.amount", "spawning.monsters.tick-rate")) .addAction(MoveMigratorAction.of("spawning.monsters.amount", "spawning.monsters.tick-rate"))
.addAction(IntegerMigratorAction.of("spawning.monsters.tick-rate")) .addAction(IntegerMigratorAction.of("spawning.monsters.tick-rate"))
.addAction(MoveMigratorAction.of("spawning.monsters.exceptions", "spawning.monsters.exceptions")) //.addAction(MoveMigratorAction.of("spawning.monsters.exceptions", "spawning.monsters.exceptions"))
.addAction(MoveMigratorAction.of("worldBlacklist", "world-blacklist")) .addAction(MoveMigratorAction.of("worldBlacklist", "world-blacklist"))
.addAction(new LegacyAliasMigrator()) .addAction(new LegacyAliasMigrator())
.build(); .build();

View File

@ -2,6 +2,7 @@ package org.mvplugins.multiverse.core.world
import com.onarandombox.MultiverseCore.worldnew.config.SpawnLocation import com.onarandombox.MultiverseCore.worldnew.config.SpawnLocation
import com.onarandombox.MultiverseCore.worldnew.config.WorldsConfigManager import com.onarandombox.MultiverseCore.worldnew.config.WorldsConfigManager
import org.bukkit.World.Environment
import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.mvplugins.multiverse.core.TestWithMockBukkit import org.mvplugins.multiverse.core.TestWithMockBukkit
@ -39,7 +40,18 @@ class WorldConfigMangerTest : TestWithMockBukkit() {
assertTrue(worldConfigManager.load().isSuccess) assertTrue(worldConfigManager.load().isSuccess)
assertTrue(worldConfigManager.save().isSuccess) assertTrue(worldConfigManager.save().isSuccess)
//compareConfigFile("worlds2.yml", "/migrated_worlds.yml")
val endWorldConfig = worldConfigManager.getWorldConfig("world_the_end")
assertNotNull(endWorldConfig)
assertEquals("&aworld the end", endWorldConfig.alias)
assertEquals(Environment.THE_END, endWorldConfig.environment)
val worldConfig = worldConfigManager.getWorldConfig("world")
assertNotNull(worldConfig)
assertEquals(-5176596003035866649, worldConfig.seed)
assertEquals(listOf("test"), worldConfig.worldBlacklist)
} }
@Test @Test

View File

@ -81,5 +81,5 @@ world:
tick-rate: -1 tick-rate: -1
exceptions: [] exceptions: []
world-blacklist: world-blacklist:
- test - test
version: 1.0 version: 1.0