Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 39 additions & 18 deletions src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.mvplugins.multiverse.core.utils.result.Attempt;
import org.mvplugins.multiverse.core.utils.result.FailureReason;
import org.mvplugins.multiverse.core.utils.FileUtils;
import org.mvplugins.multiverse.core.utils.text.ChatTextFormatter;
import org.mvplugins.multiverse.core.world.biomeprovider.BiomeProviderFactory;
import org.mvplugins.multiverse.core.world.entity.EntityPurger;
import org.mvplugins.multiverse.core.world.generators.GeneratorProvider;
Expand Down Expand Up @@ -244,7 +245,10 @@
.filter(world -> !isLoadedWorld(world) && world.isAutoLoad())
.forEach(world -> loadWorld(LoadWorldOptions.world(world))
.onFailure(failure ->
Logging.severe("Failed to autoload world %s: %s", world.getName(), failure))
Logging.severe("Failed to autoload world '%s': %s: %s",
world.getName(),
failure,
ChatTextFormatter.removeColor(failure.getFailureMessage().formatted())))
.onSuccess(newMVWorld ->
Logging.fine("Autoloaded world %s", newMVWorld.getName())));
}
Expand Down Expand Up @@ -282,15 +286,24 @@
WorldKeyOrName keyOrName = keyOrNameWithOptions.keyOrName();
CreateWorldOptions options = keyOrNameWithOptions.options();
String generatorString = generatorProvider.parseGeneratorString(keyOrName.usableName(), options.generator());
WorldCreator worldCreator = WorldCreatorCompatibility.ofKeyOrName(keyOrName)
.environment(options.environment())
.generateStructures(options.generateStructures())
.generatorSettings(options.generatorSettings())
.seed(options.seed())
.type(options.worldType());
WorldCreatorCompatibility.setBonusChest(worldCreator, options.bonusChest());
options.forcedSpawnPosition().peek(position -> WorldCreatorCompatibility.setForcedSpawnPosition(worldCreator, position));
return addBiomeProviderToCreator(worldCreator, keyOrName.usableName(), options.biome())

return Try.of(() -> {

Check warning on line 290 in src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Lambda body length is 12 lines (max allowed is 10). Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:290:26: info: Lambda body length is 12 lines (max allowed is 10). (LambdaGettingTooLong)
WorldCreator creator = WorldCreatorCompatibility.ofKeyOrName(keyOrName)

Check warning on line 291 in src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 'block' child has incorrect indentation level 20, expected level should be 12. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:291:21: warning: 'block' child has incorrect indentation level 20, expected level should be 12. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
.environment(options.environment())
.generateStructures(options.generateStructures())
.generatorSettings(options.generatorSettings())
.seed(options.seed())
.type(options.worldType());
WorldCreatorCompatibility.setBonusChest(creator, options.bonusChest());

Check warning on line 297 in src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 'block' child has incorrect indentation level 20, expected level should be 12. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:297:21: warning: 'block' child has incorrect indentation level 20, expected level should be 12. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
options.forcedSpawnPosition()

Check warning on line 298 in src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 'block' child has incorrect indentation level 20, expected level should be 12. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:298:21: warning: 'block' child has incorrect indentation level 20, expected level should be 12. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
.peek(position -> WorldCreatorCompatibility.setForcedSpawnPosition(creator, position));
return creator;

Check warning on line 300 in src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 'block' child has incorrect indentation level 20, expected level should be 12. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:300:21: warning: 'block' child has incorrect indentation level 20, expected level should be 12. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
})

Check warning on line 301 in src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 'block rcurly' has incorrect indentation level 16, expected level should be 8. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:301:17: warning: 'block rcurly' has incorrect indentation level 16, expected level should be 8. (com.puppycrawl.tools.checkstyle.checks.indentation.IndentationCheck)
.fold(throwable -> Attempt.<WorldCreator, WorldCreatorFailureReason>failure(WorldCreatorFailureReason.BUKKIT_CREATION_FAILED,

Check warning on line 302 in src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 141). Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:302:0: warning: Line is longer than 120 characters (found 141). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
Replace.WORLD.with(keyOrName.usableName()),
Replace.ERROR.with(throwable)),
Attempt::<WorldCreator, WorldCreatorFailureReason>success)
.mapAttempt(creator -> addBiomeProviderToCreator(creator, keyOrName.usableName(), options.biome()))
.mapAttempt(creator -> addGeneratorToCreator(creator, generatorString))
.mapAttempt(this::createBukkitWorld)
.transform(CreateFailureReason.WORLD_CREATOR_FAILED)
Expand Down Expand Up @@ -359,11 +372,15 @@
WorldKeyOrName keyOrName = keyOrNameWithOptions.keyOrName();
ImportWorldOptions options = keyOrNameWithOptions.options();
String generatorString = generatorProvider.parseGeneratorString(keyOrName.usableName(), options.generator());
WorldCreator worldCreator = WorldCreatorCompatibility.ofKeyOrName(keyOrName)
.environment(options.environment())
.generatorSettings(options.generatorSettings());

return addBiomeProviderToCreator(worldCreator, keyOrName.usableName(), options.biome())
return Try.of(() -> WorldCreatorCompatibility.ofKeyOrName(keyOrName)
.environment(options.environment())
.generatorSettings(options.generatorSettings()))
.fold(throwable -> Attempt.<WorldCreator, WorldCreatorFailureReason>failure(WorldCreatorFailureReason.BUKKIT_CREATION_FAILED,

Check warning on line 379 in src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 141). Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:379:0: warning: Line is longer than 120 characters (found 141). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
Replace.WORLD.with(keyOrName.usableName()),
Replace.ERROR.with(throwable)),
Attempt::<WorldCreator, WorldCreatorFailureReason>success)
.mapAttempt(creator -> addBiomeProviderToCreator(creator, keyOrName.usableName(), options.biome()))
.mapAttempt(creator -> addGeneratorToCreator(creator, generatorString))
.mapAttempt(this::createBukkitWorld)
.transform(ImportFailureReason.WORLD_CREATOR_FAILED)
Expand Down Expand Up @@ -528,10 +545,14 @@
}
}

WorldCreator worldCreator = WorldCreatorCompatibility.ofNameAndKey(mvWorld.getKey(), mvWorld.getName())
.environment(mvWorld.getEnvironment())
.seed(mvWorld.getSeed());
return addBiomeProviderToCreator(worldCreator, mvWorld.getName(), mvWorld.getBiome())
return Try.of(() -> WorldCreatorCompatibility.ofNameAndKey(mvWorld.getKey(), mvWorld.getName())
.environment(mvWorld.getEnvironment())
.seed(mvWorld.getSeed()))
.fold(throwable -> Attempt.<WorldCreator, WorldCreatorFailureReason>failure(WorldCreatorFailureReason.BUKKIT_CREATION_FAILED,

Check warning on line 551 in src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 141). Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:551:0: warning: Line is longer than 120 characters (found 141). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
Replace.WORLD.with(mvWorld.getName()),
Replace.ERROR.with(throwable)),
Attempt::<WorldCreator, WorldCreatorFailureReason>success)
.mapAttempt(creator -> addBiomeProviderToCreator(creator, mvWorld.getName(), mvWorld.getBiome()))
.mapAttempt(creator -> addGeneratorToCreator(creator, mvWorld.getGenerator()))
.mapAttempt(this::createBukkitWorld)
.transform(LoadFailureReason.WORLD_CREATOR_FAILED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import org.jvnet.hk2.annotations.Service;

import org.mvplugins.multiverse.core.MultiverseCore;
import org.mvplugins.multiverse.core.utils.ServerProperties;
import org.mvplugins.multiverse.core.utils.result.Attempt;
import org.mvplugins.multiverse.core.world.helpers.DimensionFinder;
import org.mvplugins.multiverse.core.world.key.WorldKeyOrName;
import org.mvplugins.multiverse.core.world.key.WorldKeyParseFailReason;

Expand All @@ -34,16 +36,18 @@

private final SortedMap<WorldKeyOrName, WorldConfig> worldConfigMap;
private final File worldConfigFile;
private final ServerProperties serverProperties;
private YamlConfiguration worldsConfig;

private final MultiverseCore multiverseCore;

@Inject
WorldsConfigManager(@NotNull MultiverseCore core, @NotNull MultiverseCore multiverseCore) {
WorldsConfigManager(@NotNull MultiverseCore multiverseCore, @NotNull ServerProperties serverProperties) {
worldConfigMap = new TreeMap<>();
worldConfigFile = core.getDataFolder().toPath().resolve(CONFIG_FILENAME).toFile();
worldConfigFile = multiverseCore.getDataFolder().toPath().resolve(CONFIG_FILENAME).toFile();

this.multiverseCore = multiverseCore;
this.serverProperties = serverProperties;
}

/**
Expand Down Expand Up @@ -202,9 +206,59 @@
worldConfigMap.remove(s);
}

migrateLevelNameChange();

return new NewAndRemovedWorlds(newWorldsAdded, worldsRemoved);
}

private void migrateLevelNameChange() {
serverProperties.getLevelName()
.peek(levelName -> {

Check warning on line 216 in src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Lambda body length is 21 lines (max allowed is 10). Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java:216:33: info: Lambda body length is 21 lines (max allowed is 10). (LambdaGettingTooLong)
boolean didMigrate = migrateLevelNameChange(
WorldKeyOrName.parseKey(NamespacedKey.minecraft("overworld")),
levelName
);
didMigrate = migrateLevelNameChange(
WorldKeyOrName.parseKey(NamespacedKey.minecraft("the_nether")),
DimensionFinder.DEFAULT_NETHER_FORMAT.replaceOverworld(levelName)
) || didMigrate;
didMigrate = migrateLevelNameChange(
WorldKeyOrName.parseKey(NamespacedKey.minecraft("the_end")),
DimensionFinder.DEFAULT_END_FORMAT.replaceOverworld(levelName)
) || didMigrate;

if (didMigrate) {
Logging.warning("We have detected and migrated your default world's name due to a level-name change.");
Logging.warning("Please check your worlds.yml file and world list to ensure everything is correct.");
Logging.warning("Additionally, all references to the old world name will no longer work. " +
"Please update all references within your configuration files/plugins.");
}
});
}

private boolean migrateLevelNameChange(WorldKeyOrName keyOrName, String newWorldName) {
return getWorldConfig(keyOrName).map(worldConfig -> {
if (newWorldName.equals(worldConfig.getLegacyWorldName())) {
return false;
}

boolean hasConflictKey = WorldKeyOrName.parseKey(newWorldName).map(this::getWorldConfig)
.fold(failure -> false, Option::isDefined);
if (hasConflictKey) {
Logging.severe("Unable to migrate default world's name caused by level-name change.");
Logging.severe("We have detected a clash between the default name '%s' and an existing non-default world in your worlds.yml file.", newWorldName);
Logging.severe("Please change the level-name in server.properties to something else and restart the server.");
return false;
}

Logging.info("Updating legacy world name for %s from %s to %s due to level-name change.",
keyOrName, worldConfig.getLegacyWorldName(), newWorldName);
worldConfig.setLegacyWorldName(newWorldName);
worldConfig.save();
return true;
}).getOrElse(false);
}

/**
* Whether the worlds.yml file has been loaded.
*
Expand Down
Loading