mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2026-11-04 16:50:03 -05:00
Compare commits
4
Commits
5.8.2-pre.1
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34185b90a9 | ||
|
|
5d57bbfda9 | ||
|
|
a78459ab77 | ||
|
|
0ad795b27f |
No files matched your search
@@ -46,3 +46,6 @@ debug.txt
|
||||
|
||||
# Gradle
|
||||
.gradle
|
||||
|
||||
# Kotlin generated files
|
||||
/.kotlin/
|
||||
@@ -55,6 +55,7 @@ public final class LoadedMultiverseWorld extends MultiverseWorld {
|
||||
worldConfig.load();
|
||||
worldConfig.setEnvironment(world.getEnvironment());
|
||||
worldConfig.setSeed(world.getSeed());
|
||||
worldConfig.setLegacyWorldName(world.getName());
|
||||
}
|
||||
|
||||
private void setupSpawnLocation(World world) {
|
||||
|
||||
@@ -323,6 +323,8 @@ final class WorldConfigNodes {
|
||||
.hidden());
|
||||
|
||||
final ConfigNode<String> legacyWorldName = node(ConfigNode.builder("read-only.legacy-world-name", String.class)
|
||||
.onLoadAndChange((oldValue, newValue) -> worldManager.getWorldStore().changeLegacyWorldName(
|
||||
oldValue, newValue, keyOrName.usableKey()))
|
||||
.hidden());
|
||||
|
||||
final ConfigNode<Long> seed = node(ConfigNode.builder("read-only.seed", Long.class)
|
||||
|
||||
@@ -120,6 +120,29 @@ final class WorldStore {
|
||||
unloadedList.add(unloadedMap.get(world.getKey().toString()));
|
||||
}
|
||||
|
||||
void changeLegacyWorldName(@Nullable String oldName, @Nullable String newName, @NotNull NamespacedKey worldKey) {
|
||||
if (Objects.equals(oldName, newName)) {
|
||||
return;
|
||||
}
|
||||
String key = worldKey.toString();
|
||||
updateLegacyWorldName(loadedMap, oldName, newName, key);
|
||||
updateLegacyWorldName(unloadedMap, oldName, newName, key);
|
||||
}
|
||||
|
||||
private <T extends MultiverseWorld> void updateLegacyWorldName(
|
||||
Map<String, T> map, @Nullable String oldName, @Nullable String newName, String key) {
|
||||
T world = map.get(key);
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
if (oldName != null && !key.equalsIgnoreCase(oldName)) {
|
||||
map.remove(oldName, world);
|
||||
}
|
||||
if (newName != null) {
|
||||
map.put(newName, world);
|
||||
}
|
||||
}
|
||||
|
||||
void changeAlias(@Nullable String oldAlias, @Nullable String newAlias, @NotNull NamespacedKey worldKey) {
|
||||
if (Objects.equals(oldAlias, newAlias)) {
|
||||
// nothing changed, ignore
|
||||
|
||||
@@ -49,6 +49,38 @@ class WorldManagerTest : TestWithMockBukkit() {
|
||||
assertNotNull(world2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Legacy world name changes update loaded and unloaded lookups`() {
|
||||
val worldKey = world.key.toString()
|
||||
assertTrue(world.worldConfig.setLegacyWorldName("renamed_world").isSuccess)
|
||||
|
||||
assertFalse(worldManager.getWorld("world").isDefined)
|
||||
assertSame(world, worldManager.getLoadedWorld("RENAMED_WORLD").get())
|
||||
assertSame(world, worldManager.getLoadedWorld(worldKey).get())
|
||||
|
||||
assertTrue(worldManager.unloadWorld(UnloadWorldOptions.world(world)).isSuccess)
|
||||
assertFalse(worldManager.getWorld("world").isDefined)
|
||||
assertFalse(worldManager.getLoadedWorld("renamed_world").isDefined)
|
||||
assertEquals(world.key, worldManager.getUnloadedWorld("RENAMED_WORLD").get().key)
|
||||
assertEquals(world.key, worldManager.getUnloadedWorld(worldKey).get().key)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Setting up loaded world config refreshes legacy world name lookups`() {
|
||||
assertTrue(world.worldConfig.setLegacyWorldName("stale_name").isSuccess)
|
||||
assertTrue(world.worldConfig.save().isSuccess)
|
||||
|
||||
world.setWorldConfig(world.worldConfig)
|
||||
|
||||
assertEquals("world", world.name)
|
||||
assertSame(world, worldManager.getLoadedWorld("world").get())
|
||||
assertFalse(worldManager.getWorld("stale_name").isDefined)
|
||||
|
||||
assertTrue(worldManager.unloadWorld(UnloadWorldOptions.world(world)).isSuccess)
|
||||
assertTrue(worldManager.getUnloadedWorld("world").isDefined)
|
||||
assertFalse(worldManager.getWorld("stale_name").isDefined)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Create world with custom options`() {
|
||||
assertTrue(worldManager.createWorld(
|
||||
|
||||
Reference in new issue
Block a user