mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2026-11-07 09:42:35 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4de4e5a68e | ||
|
|
f6a8a6b3b4 | ||
|
|
d485238c56 | ||
|
|
5234445746 | ||
|
|
0b626d9eaf | ||
|
|
2ff321e475 | ||
|
|
58dbe55be4 | ||
|
|
a2045b52bd | ||
|
|
396ece4d27 |
No files matched your search
@@ -41,7 +41,7 @@ class CloneCommand extends CoreCommand {
|
||||
@Subcommand("clone")
|
||||
@CommandPermission("multiverse.core.clone")
|
||||
@CommandCompletion("@mvworlds:scope=loaded @empty @flags:groupName=" + Flags.NAME)
|
||||
@Syntax("<world> <new-world-name> [--reset-world-config --reset-gamerules --reset-world-border]")
|
||||
@Syntax("<world> <new-world-name> [--reset-world-config --reset-gamerules --reset-world-border --no-save]")
|
||||
@Description("{@@mv-core.clone.description}")
|
||||
void onCloneCommand(
|
||||
MVCommandIssuer issuer,
|
||||
@@ -55,7 +55,7 @@ class CloneCommand extends CoreCommand {
|
||||
String newWorldName,
|
||||
|
||||
@Optional
|
||||
@Syntax("[--reset-world-config --reset-gamerules --reset-world-border]")
|
||||
@Syntax("[--reset-world-config --reset-gamerules --reset-world-border --no-save]")
|
||||
@Description("{@@mv-core.regen.other.description}")
|
||||
String[] flagArray) {
|
||||
ParsedCommandFlags parsedFlags = flags.parse(flagArray);
|
||||
|
||||
@@ -56,7 +56,7 @@ class CreateCommand extends CoreCommand {
|
||||
@CommandPermission("multiverse.core.create")
|
||||
@CommandCompletion("@empty @environments @flags:groupName=" + Flags.NAME)
|
||||
@Syntax("<name> <environment> [--seed <seed> --generator <generator[:id]> --world-type <worldtype> " +
|
||||
"--adjust-spawn --no-structures --generate-bonus-chest --force-spawn-position <x,y,z:pitch:yaw> " +
|
||||
"--no-adjust-spawn --no-structures --generate-bonus-chest --force-spawn-position <x,y,z:pitch:yaw> " +
|
||||
"--biome <biome> --generator-settings <json-settings> --properties <prop1=value1,prop2=value2,...>]")
|
||||
@Description("{@@mv-core.create.description}")
|
||||
void onCreateCommand(
|
||||
@@ -71,7 +71,7 @@ class CreateCommand extends CoreCommand {
|
||||
World.Environment environment,
|
||||
|
||||
@Optional
|
||||
@Syntax("[--seed <seed> --generator <generator[:id]> --world-type <worldtype> --adjust-spawn " +
|
||||
@Syntax("[--seed <seed> --generator <generator[:id]> --world-type <worldtype> --no-adjust-spawn " +
|
||||
"--no-structures --generate-bonus-chest --force-spawn-position <x,y,z:pitch:yaw> --biome <biome> " +
|
||||
"--generator-settings <json-settings> --properties <prop1=value1,prop2=value2,...>]")
|
||||
@Description("{@@mv-core.create.flags.description}")
|
||||
|
||||
@@ -54,21 +54,21 @@ class GameruleCommand extends CoreCommand {
|
||||
@Subcommand("gamerule|rule set")
|
||||
@CommandPermission("multiverse.core.gamerule.set")
|
||||
@CommandCompletion("@gamerules @gamerulesvalues @mvworlds:multiple|*")
|
||||
@Syntax("<Gamerule> <Gamerule value> [World or *]")
|
||||
@Syntax("<gamerule> <value> [worlds|*]")
|
||||
@Description("{@@mv-core.gamerule.set.description}")
|
||||
void onGameruleSetCommand(
|
||||
MVCommandIssuer issuer,
|
||||
|
||||
@Syntax("<Gamerule>")
|
||||
@Syntax("<gamerule>")
|
||||
@Description("{@@mv-core.gamerule.set.gamerule.description}")
|
||||
GameRule gamerule,
|
||||
|
||||
@Syntax("<Value>")
|
||||
@Syntax("<value>")
|
||||
@Description("{@@mv-core.gamerule.set.value.description}")
|
||||
GameRuleValue gameRuleValue,
|
||||
|
||||
@Flags("resolve=issuerAware,maxArgForAware=2")
|
||||
@Syntax("[World or *]")
|
||||
@Syntax("[worlds|*]")
|
||||
@Description("{@@mv-core.gamerule.set.world.description}")
|
||||
LoadedMultiverseWorld[] worlds) {
|
||||
Object value = gameRuleValue.value();
|
||||
@@ -105,17 +105,17 @@ class GameruleCommand extends CoreCommand {
|
||||
@Subcommand("gamerule|rule reset")
|
||||
@CommandPermission("multiverse.core.gamerule.set")
|
||||
@CommandCompletion("@gamerules @mvworlds:multiple|*")
|
||||
@Syntax("<Gamerule> [World or *]")
|
||||
@Syntax("<gamerule> [worlds|*]")
|
||||
@Description("{@@mv-core.gamerule.reset.description}")
|
||||
void onGameruleResetCommand(
|
||||
MVCommandIssuer issuer,
|
||||
|
||||
@Syntax("<Gamerule>")
|
||||
@Syntax("<gamerule>")
|
||||
@Description("{@@mv-core.gamerule.reset.gamerule.description}")
|
||||
GameRule gamerule,
|
||||
|
||||
@Flags("resolve=issuerAware,maxArgForAware=1")
|
||||
@Syntax("[World or *]")
|
||||
@Syntax("[worlds|*]")
|
||||
@Description("{@@mv-core.gamerule.reset.world.description}")
|
||||
LoadedMultiverseWorld[] worlds) {
|
||||
AtomicBoolean success = new AtomicBoolean(true);
|
||||
@@ -153,7 +153,7 @@ class GameruleCommand extends CoreCommand {
|
||||
MVCommandIssuer issuer,
|
||||
|
||||
@Flags("resolve=issuerAware,maxArgForAware=0")
|
||||
@Syntax("<world>")
|
||||
@Syntax("[world]")
|
||||
@Description("{@@mv-core.gamerule.list.description.world}")
|
||||
LoadedMultiverseWorld world,
|
||||
|
||||
|
||||
@@ -43,7 +43,8 @@ class ImportCommand extends CoreCommand {
|
||||
@Subcommand("import")
|
||||
@CommandPermission("multiverse.core.import")
|
||||
@CommandCompletion("@mvworlds:scope=potential @environments @flags:groupName=" + Flags.NAME)
|
||||
@Syntax("<name> <environment> [--generator <generator[:id]> --adjust-spawn --biome <biome>]")
|
||||
@Syntax("<name> <environment> [--generator <generator[:id]> --no-adjust-spawn --biome <biome> " +
|
||||
"--skip-folder-check --generator-settings <json-settings>]")
|
||||
@Description("{@@mv-core.import.description}")
|
||||
void onImportCommand(
|
||||
MVCommandIssuer issuer,
|
||||
@@ -53,12 +54,13 @@ class ImportCommand extends CoreCommand {
|
||||
@Description("{@@mv-core.import.name.description}")
|
||||
String worldName,
|
||||
|
||||
@Syntax("<env>")
|
||||
@Syntax("<environment>")
|
||||
@Description("{@@mv-core.import.env.description}")
|
||||
World.Environment environment,
|
||||
|
||||
@Optional
|
||||
@Syntax("[--generator <generator[:id]> --adjust-spawn --biome <biome>]")
|
||||
@Syntax("[--generator <generator[:id]> --no-adjust-spawn --biome <biome> " +
|
||||
"--skip-folder-check --generator-settings <json-settings>]")
|
||||
@Description("{@@mv-core.import.other.description}")
|
||||
String[] flagArray) {
|
||||
ParsedCommandFlags parsedFlags = flags.parse(flagArray);
|
||||
|
||||
@@ -54,12 +54,12 @@ class ListCommand extends CoreCommand {
|
||||
@Subcommand("list")
|
||||
@CommandPermission("multiverse.core.list.worlds")
|
||||
@CommandCompletion("@flags:groupName=" + Flags.NAME)
|
||||
@Syntax("--filter [filter] --page [page] --raw")
|
||||
@Syntax("[--filter <filter>] [--page <page>] [--raw]")
|
||||
@Description("{{@mv-core.list.description}}")
|
||||
public void onListCommand(
|
||||
MVCommandIssuer issuer,
|
||||
|
||||
@Syntax("[--filter <filter>] [--page <page>]")
|
||||
@Syntax("[--filter <filter>] [--page <page>] [--raw]")
|
||||
@Description("Filters the list of worlds by the given regex and displays the given page.")
|
||||
String[] flagArray) {
|
||||
ParsedCommandFlags parsedFlags = flags.parse(flagArray);
|
||||
|
||||
@@ -39,7 +39,7 @@ class LoadCommand extends CoreCommand {
|
||||
@Subcommand("load")
|
||||
@CommandPermission("multiverse.core.load")
|
||||
@CommandCompletion("@mvworlds:scope=unloaded @flags:groupName=" + Flags.NAME)
|
||||
@Syntax("<world>")
|
||||
@Syntax("<world> [--skip-folder-check]")
|
||||
@Description("{@@mv-core.load.description}")
|
||||
void onLoadCommand(
|
||||
MVCommandIssuer issuer,
|
||||
|
||||
@@ -70,7 +70,7 @@ class RegenCommand extends CoreCommand {
|
||||
@CommandPermission("multiverse.core.regen")
|
||||
@CommandCompletion("@mvworlds:scope=loaded @flags:groupName=" + Flags.NAME)
|
||||
@Syntax("<world> [--seed [seed]] [--reset-world-config] [--reset-gamerules] [--reset-world-border] " +
|
||||
"[--remove-players [destination]]")
|
||||
"[--keep-files <files>] [--remove-players [destination]]")
|
||||
@Description("{@@mv-core.regen.description}")
|
||||
void onRegenCommand(
|
||||
MVCommandIssuer issuer,
|
||||
@@ -81,7 +81,7 @@ class RegenCommand extends CoreCommand {
|
||||
|
||||
@Optional
|
||||
@Syntax("[--seed [seed]] [--reset-world-config] [--reset-gamerules] [--reset-world-border] " +
|
||||
"[--remove-players [destination]]")
|
||||
"[--keep-files <files>] [--remove-players [destination]]")
|
||||
@Description("{@@mv-core.regen.other.description}")
|
||||
String[] flagArray) {
|
||||
ParsedCommandFlags parsedFlags = flags.parse(flagArray);
|
||||
|
||||
@@ -40,12 +40,12 @@ class SetSpawnCommand extends CoreCommand {
|
||||
@Subcommand("setspawn")
|
||||
@CommandPermission("multiverse.core.spawn.set")
|
||||
@CommandCompletion("@flags:groupName=" + UnsafeFlags.NAME + " @flags:resolveUntil=arg1,groupName=" + UnsafeFlags.NAME)
|
||||
@Syntax("[worldname:x,y,z[,pitch,yaw]] [--unsafe]")
|
||||
@Syntax("[worldname:x,y,z[,yaw,pitch]] [--unsafe]")
|
||||
@Description("{@@mv-core.setspawn.description}")
|
||||
void onSetSpawnCommand(
|
||||
MVCommandIssuer issuer,
|
||||
|
||||
@Syntax("[worldname:x,y,z[,pitch,yaw]]")
|
||||
@Syntax("[worldname:x,y,z[,yaw,pitch]]")
|
||||
@Description("{@@mv-core.setspawn.location.description}")
|
||||
PlayerLocation playerLocation,
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ final class SpawnCommand extends CoreCommand {
|
||||
@CommandPermission("@mvspawn")
|
||||
@CommandCompletion("@playersarray:checkPermissions=@mvspawnother|@flags:resolveUntil=arg1,groupName=" + UnsafeFlags.NAME
|
||||
+ " @flags:groupName=" + UnsafeFlags.NAME)
|
||||
@Syntax("[player]")
|
||||
@Syntax("[player] [--unsafe]")
|
||||
@Description("{@@mv-core.spawn.description}")
|
||||
void onSpawnTpCommand(
|
||||
MVCommandIssuer issuer,
|
||||
|
||||
@@ -59,7 +59,7 @@ final class TeleportCommand extends CoreCommand {
|
||||
@CommandCompletion("@playersarray:checkPermissions=@mvteleportother|@destinations:byIssuerForArg=arg1 "
|
||||
+ "@destinations:notByIssuerForArg=arg1|@flags:byIssuerForArg=arg1,groupName=" + Flags.NAME + " "
|
||||
+ "@flags:notByIssuerForArg=arg1,groupName=" + Flags.NAME)
|
||||
@Syntax("[player] <destination> [--unsafe]")
|
||||
@Syntax("[player] <destination> [--unsafe --silent]")
|
||||
@Description("{@@mv-core.teleport.description}")
|
||||
void onTeleportCommand(
|
||||
MVCommandIssuer issuer,
|
||||
@@ -74,7 +74,7 @@ final class TeleportCommand extends CoreCommand {
|
||||
DestinationInstance<?, ?> destination,
|
||||
|
||||
@Optional
|
||||
@Syntax("[--unsafe]")
|
||||
@Syntax("[--unsafe --silent]")
|
||||
@Description("")
|
||||
String[] flagArray) {
|
||||
Player[] players = playersValue.value();
|
||||
|
||||
@@ -52,7 +52,7 @@ class UnloadCommand extends CoreCommand {
|
||||
@Subcommand("unload")
|
||||
@CommandPermission("multiverse.core.unload")
|
||||
@CommandCompletion("@mvworlds @flags:groupName=" + Flags.NAME)
|
||||
@Syntax("<world> [--remove-players [destination]] [--no-save]")
|
||||
@Syntax("<world> [--remove-players [destination]] [--no-unload-bukkit-world] [--no-save]")
|
||||
@Description("{@@mv-core.unload.description}")
|
||||
void onUnloadCommand(
|
||||
MVCommandIssuer issuer,
|
||||
@@ -62,7 +62,7 @@ class UnloadCommand extends CoreCommand {
|
||||
LoadedMultiverseWorld world,
|
||||
|
||||
@Optional
|
||||
@Syntax("[--remove-players [destination]] [--no-save]")
|
||||
@Syntax("[--remove-players [destination]] [--no-unload-bukkit-world] [--no-save]")
|
||||
@Description("{@@mv-core.gamerules.description.page}")
|
||||
String[] flagArray) {
|
||||
ParsedCommandFlags parsedFlags = flags.parse(flagArray);
|
||||
|
||||
@@ -50,10 +50,10 @@ final class WorldBorderCommand extends CoreCommand {
|
||||
void onWorldBorderCenter(
|
||||
MVCommandIssuer issuer,
|
||||
|
||||
@Syntax("[x]")
|
||||
@Syntax("<x>")
|
||||
double x,
|
||||
|
||||
@Syntax("[z]")
|
||||
@Syntax("<z>")
|
||||
double z,
|
||||
|
||||
@Flags("resolve=issuerAware,maxArgForAware=0")
|
||||
|
||||
@@ -22,11 +22,13 @@ import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
||||
import org.mvplugins.multiverse.core.dynamiclistener.EventRunnable;
|
||||
import org.mvplugins.multiverse.core.dynamiclistener.annotations.EventClass;
|
||||
import org.mvplugins.multiverse.core.dynamiclistener.annotations.EventMethod;
|
||||
import org.mvplugins.multiverse.core.utils.compatibility.EntityCompatibility;
|
||||
import org.mvplugins.multiverse.core.world.WorldManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -96,10 +98,7 @@ final class MVEntityListener implements CoreListener {
|
||||
@Override
|
||||
public void onEvent(PreCreatureSpawnEvent event) {
|
||||
// Always allow custom command and plugins to spawn creatures
|
||||
if (event.getReason() == SpawnReason.CUSTOM
|
||||
|| event.getReason() == SpawnReason.COMMAND
|
||||
|| event.getReason() == SpawnReason.BREEDING
|
||||
|| event.getReason() == SpawnReason.SPAWNER_EGG) {
|
||||
if (isAlwaysAllowedSpawnReason(event.getReason())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -127,10 +126,7 @@ final class MVEntityListener implements CoreListener {
|
||||
}
|
||||
|
||||
// Always allow custom command and plugins to spawn creatures
|
||||
if (event.getSpawnReason() == SpawnReason.CUSTOM
|
||||
|| event.getSpawnReason() == SpawnReason.COMMAND
|
||||
|| event.getSpawnReason() == SpawnReason.BREEDING
|
||||
|| event.getSpawnReason() == SpawnReason.SPAWNER_EGG) {
|
||||
if (isAlwaysAllowedSpawnReason(event.getSpawnReason())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -168,6 +164,7 @@ final class MVEntityListener implements CoreListener {
|
||||
.peek(world -> {
|
||||
long count = Arrays.stream(event.getChunk().getEntities())
|
||||
.filter(entity -> !(entity instanceof Player))
|
||||
.filter(entity -> !isAlwaysAllowedSpawnReason(EntityCompatibility.getEntitySpawnReason(entity)))
|
||||
.filter(entity -> !world.getEntitySpawnConfig().shouldAllowSpawn(entity))
|
||||
.peek(Entity::remove)
|
||||
.count();
|
||||
@@ -177,4 +174,11 @@ final class MVEntityListener implements CoreListener {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isAlwaysAllowedSpawnReason(@Nullable SpawnReason reason) {
|
||||
return reason == SpawnReason.CUSTOM
|
||||
|| reason == SpawnReason.COMMAND
|
||||
|| reason == SpawnReason.BREEDING
|
||||
|| reason == SpawnReason.SPAWNER_EGG;
|
||||
}
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package org.mvplugins.multiverse.core.utils.compatibility;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.mvplugins.multiverse.core.utils.ReflectHelper;
|
||||
|
||||
/**
|
||||
* Compatibility class used to handle API changes in {@link Entity} class.
|
||||
*/
|
||||
// TODO: Consider making this part of the public API in v5.9.
|
||||
@ApiStatus.Internal
|
||||
public final class EntityCompatibility {
|
||||
|
||||
private static final boolean HAS_GET_ENTITY_SPAWN_REASON_METHOD;
|
||||
|
||||
static {
|
||||
HAS_GET_ENTITY_SPAWN_REASON_METHOD = ReflectHelper.hasMethod(Entity.class, "getEntitySpawnReason");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reason that initially spawned the entity when supported by the server.
|
||||
*
|
||||
* @param entity The entity to query.
|
||||
* @return The entity's spawn reason, or null when the API is unavailable.
|
||||
*/
|
||||
@Nullable
|
||||
public static SpawnReason getEntitySpawnReason(@NotNull Entity entity) {
|
||||
if (HAS_GET_ENTITY_SPAWN_REASON_METHOD) {
|
||||
return entity.getEntitySpawnReason();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private EntityCompatibility() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ import org.mvplugins.multiverse.core.utils.compatibility.WorldCreatorCompatibili
|
||||
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;
|
||||
@@ -244,7 +245,10 @@ public final class WorldManager {
|
||||
.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())));
|
||||
}
|
||||
@@ -282,15 +286,24 @@ public final class WorldManager {
|
||||
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(() -> {
|
||||
WorldCreator creator = WorldCreatorCompatibility.ofKeyOrName(keyOrName)
|
||||
.environment(options.environment())
|
||||
.generateStructures(options.generateStructures())
|
||||
.generatorSettings(options.generatorSettings())
|
||||
.seed(options.seed())
|
||||
.type(options.worldType());
|
||||
WorldCreatorCompatibility.setBonusChest(creator, options.bonusChest());
|
||||
options.forcedSpawnPosition()
|
||||
.peek(position -> WorldCreatorCompatibility.setForcedSpawnPosition(creator, position));
|
||||
return creator;
|
||||
})
|
||||
.fold(throwable -> Attempt.<WorldCreator, WorldCreatorFailureReason>failure(WorldCreatorFailureReason.BUKKIT_CREATION_FAILED,
|
||||
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)
|
||||
@@ -359,11 +372,15 @@ public final class WorldManager {
|
||||
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,
|
||||
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)
|
||||
@@ -528,10 +545,14 @@ public final class WorldManager {
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
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)
|
||||
|
||||
@@ -18,7 +18,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
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;
|
||||
|
||||
@@ -34,16 +36,18 @@ final class WorldsConfigManager {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,9 +206,59 @@ final class WorldsConfigManager {
|
||||
worldConfigMap.remove(s);
|
||||
}
|
||||
|
||||
migrateLevelNameChange();
|
||||
|
||||
return new NewAndRemovedWorlds(newWorldsAdded, worldsRemoved);
|
||||
}
|
||||
|
||||
private void migrateLevelNameChange() {
|
||||
serverProperties.getLevelName()
|
||||
.peek(levelName -> {
|
||||
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.
|
||||
*
|
||||
|
||||
@@ -73,7 +73,7 @@ public final class SpawnCategoryConfig {
|
||||
}
|
||||
|
||||
private void applyTickPerSpawns(@NotNull World bukkitWorld) {
|
||||
if (!config.getApplyEntitySpawnLimit()) {
|
||||
if (!config.getApplyEntitySpawnRate()) {
|
||||
Logging.finer("World %s %s skipping setTicksPerSpawns due to core config", world.getName(), spawnCategory);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user