Copy spawn location only if seed didnt change on regen

This commit is contained in:
Ben Woo 2023-09-11 16:40:03 +08:00
parent ef0cb4b893
commit c0f2168ba4
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
2 changed files with 9 additions and 4 deletions

View File

@ -598,11 +598,15 @@ public class WorldManager {
LoadedMultiverseWorld world = options.world();
List<Player> playersInWorld = world.getPlayers().getOrElse(Collections.emptyList());
DataTransfer<LoadedMultiverseWorld> dataTransfer = transferData(options, world);
boolean shouldKeepSpawnLocation = options.keepWorldConfig() && options.seed() == world.getSeed();
Location spawnLocation = world.getSpawnLocation();
CreateWorldOptions createWorldOptions = CreateWorldOptions.worldName(world.getName())
.environment(world.getEnvironment())
.generateStructures(world.canGenerateStructures().getOrElse(true))
.generator(world.getGenerator())
.seed(options.seed())
.useSpawnAdjust(!shouldKeepSpawnLocation && world.getAdjustSpawn())
.worldType(world.getWorldType().getOrElse(WorldType.NORMAL));
return deleteWorld(world)
@ -610,6 +614,11 @@ public class WorldManager {
.mapAttempt(() -> createWorld(createWorldOptions).transform(RegenFailureReason.CREATE_FAILED))
.onSuccess(newWorld -> {
dataTransfer.pasteAllTo(newWorld);
if (shouldKeepSpawnLocation) {
// Special case for spawn location to prevent unsafe location if world was regen using a
// different seed.
newWorld.setSpawnLocation(spawnLocation);
}
teleportPlayersToWorld(playersInWorld, newWorld);
saveWorldsConfig();
});

View File

@ -66,10 +66,6 @@ class WorldConfigTest : TestWithMockBukkit() {
val blacklists = listOf("a", "b", "c")
assertTrue(worldConfig.setProperty("world-blacklist", blacklists).isSuccess)
assertEquals(blacklists, worldConfig.getProperty("world-blacklist").get())
val location = Location(null, 1.0, 2.0, 3.0)
assertTrue(worldConfig.setProperty("spawn-location", location).isSuccess)
assertEquals(location, worldConfig.getProperty("spawn-location").get())
}
@Test