diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/CreateCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/CreateCommand.java index 9f05089c1..8e949ab26 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/CreateCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/CreateCommand.java @@ -11,9 +11,13 @@ import co.aikar.commands.annotation.Subcommand; import co.aikar.commands.annotation.Syntax; import com.dumptruckman.minecraft.util.Logging; +import com.google.common.collect.Lists; import jakarta.inject.Inject; +import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.World; import org.bukkit.WorldType; +import org.bukkit.block.Biome; import org.jetbrains.annotations.NotNull; import org.jvnet.hk2.annotations.Service; @@ -59,6 +63,15 @@ class CreateCommand extends CoreCommand { .addAlias("-a") .build()); + private final CommandValueFlag BIOME_FLAG = flag(CommandValueFlag.builder("--biome", Biome.class) + .addAlias("-b") + .completion(input -> Lists.newArrayList(Registry.BIOME).stream() + .filter(biome -> biome !=Biome.CUSTOM) + .map(biome -> biome.getKey().getKey()) + .toList()) + .context(biomeStr -> Registry.BIOME.get(NamespacedKey.minecraft(biomeStr))) + .build()); + @Inject CreateCommand( @NotNull MVCommandManager commandManager, @@ -73,7 +86,7 @@ class CreateCommand extends CoreCommand { @Subcommand("create") @CommandPermission("multiverse.core.create") @CommandCompletion("@empty @environments @flags:groupName=mvcreatecommand") - @Syntax(" --seed [seed] --generator [generator[:id]] --world-type [worldtype] --adjust-spawn --no-structures") + @Syntax(" [--seed --generator --world-type --adjust-spawn --no-structures --biome ]") @Description("{@@mv-core.create.description}") void onCreateCommand( MVCommandIssuer issuer, @@ -87,7 +100,7 @@ void onCreateCommand( World.Environment environment, @Optional - @Syntax("--seed [seed] --generator [generator[:id]] --world-type [worldtype] --adjust-spawn --no-structures") + @Syntax("[--seed --generator --world-type --adjust-spawn --no-structures --biome ]") @Description("{@@mv-core.create.flags.description}") String[] flags) { ParsedCommandFlags parsedFlags = parseFlags(flags); @@ -102,14 +115,21 @@ void onCreateCommand( "{worldType}", parsedFlags.flagValue(WORLD_TYPE_FLAG, WorldType.NORMAL).name()); issuer.sendInfo(MVCorei18n.CREATE_PROPERTIES_ADJUSTSPAWN, "{adjustSpawn}", String.valueOf(!parsedFlags.hasFlag(NO_ADJUST_SPAWN_FLAG))); - issuer.sendInfo(MVCorei18n.CREATE_PROPERTIES_GENERATOR, - "{generator}", parsedFlags.flagValue(GENERATOR_FLAG, "")); + if (parsedFlags.hasFlag(BIOME_FLAG)) { + issuer.sendInfo(MVCorei18n.CREATE_PROPERTIES_BIOME, + "{biome}", parsedFlags.flagValue(BIOME_FLAG, Biome.CUSTOM).name()); + } + if (parsedFlags.hasFlag(GENERATOR_FLAG)) { + issuer.sendInfo(MVCorei18n.CREATE_PROPERTIES_GENERATOR, + "{generator}", parsedFlags.flagValue(GENERATOR_FLAG)); + } issuer.sendInfo(MVCorei18n.CREATE_PROPERTIES_STRUCTURES, "{structures}", String.valueOf(!parsedFlags.hasFlag(NO_STRUCTURES_FLAG))); issuer.sendInfo(MVCorei18n.CREATE_LOADING); worldManager.createWorld(CreateWorldOptions.worldName(worldName) + .biome(parsedFlags.flagValue(BIOME_FLAG, Biome.CUSTOM)) .environment(environment) .seed(parsedFlags.flagValue(SEED_FLAG)) .worldType(parsedFlags.flagValue(WORLD_TYPE_FLAG, WorldType.NORMAL)) diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/ImportCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/ImportCommand.java index 5e3505382..8146e1cdc 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/ImportCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/ImportCommand.java @@ -9,8 +9,12 @@ import co.aikar.commands.annotation.Subcommand; import co.aikar.commands.annotation.Syntax; import com.dumptruckman.minecraft.util.Logging; +import com.google.common.collect.Lists; import jakarta.inject.Inject; +import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.World; +import org.bukkit.block.Biome; import org.jetbrains.annotations.NotNull; import org.jvnet.hk2.annotations.Service; @@ -42,6 +46,16 @@ class ImportCommand extends CoreCommand { .addAlias("-n") .build()); + private final CommandValueFlag BIOME_FLAG = flag(CommandValueFlag.builder("--biome", Biome.class) + .addAlias("-b") + //todo: Implement some default completions or smt to reduce duplication + .completion(input -> Lists.newArrayList(Registry.BIOME).stream() + .filter(biome -> biome !=Biome.CUSTOM) + .map(biome -> biome.getKey().getKey()) + .toList()) + .context(biomeStr -> Registry.BIOME.get(NamespacedKey.minecraft(biomeStr))) + .build()); + @Inject ImportCommand( @NotNull MVCommandManager commandManager, @@ -56,7 +70,7 @@ class ImportCommand extends CoreCommand { @Subcommand("import") @CommandPermission("multiverse.core.import") @CommandCompletion("@mvworlds:scope=potential @environments @flags:groupName=mvimportcommand") - @Syntax(" --generator [generator[:id]] --adjust-spawn") + @Syntax(" [--generator --adjust-spawn --biome ]") @Description("{@@mv-core.import.description}") void onImportCommand( MVCommandIssuer issuer, @@ -71,13 +85,14 @@ void onImportCommand( World.Environment environment, @Optional - @Syntax("--generator [generator[:id]] --adjust-spawn") + @Syntax("[--generator --adjust-spawn --biome ]") @Description("{@@mv-core.import.other.description}") String[] flags) { ParsedCommandFlags parsedFlags = parseFlags(flags); issuer.sendInfo(MVCorei18n.IMPORT_IMPORTING, "{world}", worldName); worldManager.importWorld(ImportWorldOptions.worldName(worldName) + .biome(parsedFlags.flagValue(BIOME_FLAG, Biome.CUSTOM)) .environment(environment) .generator(parsedFlags.flagValue(GENERATOR_FLAG, String.class)) .useSpawnAdjust(!parsedFlags.hasFlag(NO_ADJUST_SPAWN_FLAG))) diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/InfoCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/InfoCommand.java index d2907f093..c26328fef 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/InfoCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/InfoCommand.java @@ -117,13 +117,14 @@ private Map getInfo(LoadedMultiverseWorld world) { outMap.put("World Name", world.getName()); outMap.put("World Alias", world.getAlias()); outMap.put("World UID", world.getUID().toString()); - outMap.put("Game Mode: ", world.getGameMode().toString()); + outMap.put("Game Mode", world.getGameMode().toString()); outMap.put("Difficulty", world.getDifficulty().toString()); outMap.put("Spawn Location", locationManipulation.strCoords(world.getSpawnLocation())); outMap.put("Seed", String.valueOf(world.getSeed())); getEntryFeeInfo(outMap, world); // Entry fee/reward outMap.put("Respawn World", world.getRespawnWorldName()); outMap.put("World Type", world.getWorldType().get().toString()); + outMap.put("Biome", world.getBiome() == null ? "@vanilla" : world.getBiome().getKey().getKey()); outMap.put("Generator", world.getGenerator()); outMap.put("Generate Structures", world.canGenerateStructures().get().toString()); outMap.put("World Scale", String.valueOf(world.getScale())); diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/RegenCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/RegenCommand.java index 01558a658..a9fa52e77 100644 --- a/src/main/java/org/mvplugins/multiverse/core/commands/RegenCommand.java +++ b/src/main/java/org/mvplugins/multiverse/core/commands/RegenCommand.java @@ -13,7 +13,10 @@ import co.aikar.commands.annotation.Subcommand; import co.aikar.commands.annotation.Syntax; import com.dumptruckman.minecraft.util.Logging; +import com.google.common.collect.Lists; import jakarta.inject.Inject; +import org.bukkit.Registry; +import org.bukkit.block.Biome; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.jvnet.hk2.annotations.Service; @@ -114,6 +117,7 @@ private void doWorldRegening( LoadedMultiverseWorld world, ParsedCommandFlags parsedFlags, List worldPlayers) { + //todo: Change biome on regen RegenWorldOptions regenWorldOptions = RegenWorldOptions.world(world) .randomSeed(parsedFlags.hasFlag(SEED_FLAG)) .seed(parsedFlags.flagValue(SEED_FLAG)) diff --git a/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java b/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java index aa75792ac..bae012993 100644 --- a/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java +++ b/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java @@ -37,6 +37,7 @@ public enum MVCorei18n implements MessageKeyProvider { CREATE_PROPERTIES_SEED, CREATE_PROPERTIES_WORLDTYPE, CREATE_PROPERTIES_ADJUSTSPAWN, + CREATE_PROPERTIES_BIOME, CREATE_PROPERTIES_GENERATOR, CREATE_PROPERTIES_STRUCTURES, CREATE_LOADING, diff --git a/src/main/java/org/mvplugins/multiverse/core/world/LoadedMultiverseWorld.java b/src/main/java/org/mvplugins/multiverse/core/world/LoadedMultiverseWorld.java index c1aba2ab2..4b2bad922 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/LoadedMultiverseWorld.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/LoadedMultiverseWorld.java @@ -10,6 +10,7 @@ import org.bukkit.World; import org.bukkit.WorldType; import org.bukkit.entity.Player; +import org.bukkit.generator.BiomeProvider; import org.jetbrains.annotations.NotNull; import org.mvplugins.multiverse.core.api.BlockSafety; @@ -47,6 +48,10 @@ public class LoadedMultiverseWorld extends MultiverseWorld { private void setupWorldConfig(World world) { worldConfig.setMVWorld(this); worldConfig.load(); + BiomeProvider biomeProvider = world.getBiomeProvider(); + if (biomeProvider instanceof SingleBiomeProvider singleBiomeProvider) { + worldConfig.setBiome(singleBiomeProvider.getBiome()); + } worldConfig.setEnvironment(world.getEnvironment()); worldConfig.setSeed(world.getSeed()); } diff --git a/src/main/java/org/mvplugins/multiverse/core/world/MultiverseWorld.java b/src/main/java/org/mvplugins/multiverse/core/world/MultiverseWorld.java index d043d9a72..ecc22609b 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/MultiverseWorld.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/MultiverseWorld.java @@ -10,6 +10,8 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Biome; +import org.bukkit.generator.BiomeProvider; import org.jetbrains.annotations.Nullable; import org.mvplugins.multiverse.core.configuration.handle.StringPropertyHandle; @@ -195,6 +197,16 @@ public boolean getBedRespawn() { return worldConfig.getBedRespawn(); } + /** + * Gets the single biome used for this world. This may be null, in which case the biome from the generator will be used. + * If no generator is specified, the "natural" biome behaviour for this environment will be used. + * + * @return The biome used for this world + */ + public @Nullable Biome getBiome() { + return worldConfig.getBiome(); + } + /** * Sets whether or not a player who dies in this world will respawn in their * bed or follow the normal respawn pattern. diff --git a/src/main/java/org/mvplugins/multiverse/core/world/SingleBiomeProvider.java b/src/main/java/org/mvplugins/multiverse/core/world/SingleBiomeProvider.java new file mode 100644 index 000000000..cfbf570b6 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/core/world/SingleBiomeProvider.java @@ -0,0 +1,37 @@ +package org.mvplugins.multiverse.core.world; + +import org.bukkit.WorldCreator; +import org.bukkit.block.Biome; +import org.bukkit.generator.BiomeProvider; +import org.bukkit.generator.WorldInfo; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Helps create a world with only 1 type of Biome specified. Used in {@link WorldCreator#biomeProvider(BiomeProvider)} + */ +public class SingleBiomeProvider extends BiomeProvider { + + private final Biome biome; + private final List biomes; + + public SingleBiomeProvider(Biome biome) { + this.biome = biome; + this.biomes = List.of(biome); + } + + @Override + public @NotNull Biome getBiome(@NotNull WorldInfo worldInfo, int x, int y, int z) { + return this.biome; + } + + @Override + public @NotNull List getBiomes(@NotNull WorldInfo worldInfo) { + return this.biomes; + } + + public Biome getBiome() { + return biome; + } +} diff --git a/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java b/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java index b130d0748..1f10aa792 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java @@ -20,6 +20,8 @@ import org.bukkit.World; import org.bukkit.WorldCreator; import org.bukkit.WorldType; +import org.bukkit.block.Biome; +import org.bukkit.generator.BiomeProvider; import org.bukkit.plugin.PluginManager; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -199,6 +201,7 @@ private Attempt createValidatedWorld CreateWorldOptions options) { String parsedGenerator = parseGenerator(options.worldName(), options.generator()); WorldCreator worldCreator = WorldCreator.name(options.worldName()) + .biomeProvider(createSingleBiomeProvider(options.biome())) .environment(options.environment()) .generateStructures(options.generateStructures()) .generator(parsedGenerator) @@ -246,6 +249,7 @@ private Attempt doImportWorld( ImportWorldOptions options) { String parsedGenerator = parseGenerator(options.worldName(), options.generator()); WorldCreator worldCreator = WorldCreator.name(options.worldName()) + .biomeProvider(createSingleBiomeProvider(options.biome())) .environment(options.environment()) .generator(parsedGenerator); return createBukkitWorld(worldCreator).fold( @@ -337,6 +341,7 @@ private Attempt validateWorldToLoad( private Attempt doLoadWorld(@NotNull MultiverseWorld mvWorld) { return createBukkitWorld(WorldCreator.name(mvWorld.getName()) + .biomeProvider(createSingleBiomeProvider(mvWorld.getBiome())) .environment(mvWorld.getEnvironment()) .generator(Strings.isNullOrEmpty(mvWorld.getGenerator()) ? null : mvWorld.getGenerator()) .seed(mvWorld.getSeed())).fold( @@ -355,6 +360,18 @@ private Attempt doLoadWorld(@NotNull M }); } + /** + * Creates a single biome provider for the specified biome. + * @param biome The biome + * @return The single biome provider or null if biome is null or custom + */ + private @Nullable BiomeProvider createSingleBiomeProvider(@Nullable Biome biome) { + if (biome == null || biome == Biome.CUSTOM) { + return null; + } + return new SingleBiomeProvider(biome); + } + /** * Unloads an existing multiverse world. It will still remain as an unloaded world. * @@ -516,6 +533,7 @@ public Attempt cloneWorld(@NotNull Cl .mapAttempt(validatedOptions -> { ImportWorldOptions importWorldOptions = ImportWorldOptions .worldName(validatedOptions.newWorldName()) + .biome(validatedOptions.world().getBiome()) .environment(validatedOptions.world().getEnvironment()) .generator(validatedOptions.world().getGenerator()); return importWorld(importWorldOptions).transform(CloneFailureReason.IMPORT_FAILED); diff --git a/src/main/java/org/mvplugins/multiverse/core/world/config/BiomeSerializer.java b/src/main/java/org/mvplugins/multiverse/core/world/config/BiomeSerializer.java new file mode 100644 index 000000000..e5a062957 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/core/world/config/BiomeSerializer.java @@ -0,0 +1,33 @@ +package org.mvplugins.multiverse.core.world.config; + +import org.bukkit.block.Biome; +import org.mvplugins.multiverse.core.configuration.functions.NodeSerializer; + +public class BiomeSerializer implements NodeSerializer { + + static final String VANILLA_BIOME_BEHAVIOUR = "@vanilla"; + + @Override + public Biome deserialize(Object object, Class type) { + if (object instanceof Biome) { + return (Biome) object; + } + try { + String biomeStr = String.valueOf(object); + if (biomeStr.equalsIgnoreCase(VANILLA_BIOME_BEHAVIOUR)) { + return null; + } + return Biome.valueOf(biomeStr.toUpperCase()); + } catch (IllegalArgumentException e) { + return null; + } + } + + @Override + public Object serialize(Biome biome, Class type) { + if (biome == null || biome == Biome.CUSTOM) { + return VANILLA_BIOME_BEHAVIOUR; + } + return biome.name().toLowerCase(); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfig.java b/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfig.java index e9eb85083..c16eb1b2b 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfig.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfig.java @@ -10,6 +10,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Biome; import org.bukkit.configuration.ConfigurationSection; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -165,6 +166,14 @@ public Try setAutoLoad(boolean autoLoad) { return configHandle.set(configNodes.AUTO_LOAD, autoLoad); } + public Biome getBiome() { + return configHandle.get(configNodes.BIOME); + } + + public Try setBiome(Biome biome) { + return configHandle.set(configNodes.BIOME, biome); + } + public boolean getBedRespawn() { return configHandle.get(configNodes.BED_RESPAWN); } diff --git a/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfigNodes.java b/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfigNodes.java index 353c7557d..1c2ae7770 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfigNodes.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/config/WorldConfigNodes.java @@ -7,6 +7,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Biome; import org.jetbrains.annotations.NotNull; import org.mvplugins.multiverse.core.MultiverseCore; @@ -95,6 +96,12 @@ private N node(N node) { .defaultValue(true) .build()); + final ConfigNode BIOME = node(ConfigNode.builder("biome", Biome.class) + .defaultValue(Biome.CUSTOM) + .name(null) + .serializer(new BiomeSerializer()) + .build()); + final ConfigNode DIFFICULTY = node(ConfigNode.builder("difficulty", Difficulty.class) .defaultValue(Difficulty.NORMAL) .onSetValue((oldValue, newValue) -> { diff --git a/src/main/java/org/mvplugins/multiverse/core/world/options/CreateWorldOptions.java b/src/main/java/org/mvplugins/multiverse/core/world/options/CreateWorldOptions.java index bbbc9d44d..92f6531d5 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/options/CreateWorldOptions.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/options/CreateWorldOptions.java @@ -4,6 +4,7 @@ import org.bukkit.World; import org.bukkit.WorldType; +import org.bukkit.block.Biome; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -23,6 +24,7 @@ public class CreateWorldOptions { } private final String worldName; + private Biome biome; private World.Environment environment = World.Environment.NORMAL; private boolean generateStructures = true; private String generator = null; @@ -49,6 +51,28 @@ public class CreateWorldOptions { return worldName; } + /** + * Sets the single biome used for this world. This may be null, in which case the biome from the generator will be used. + * If no generator is specified, the "natural" biome behaviour for this environment will be used. + * + * @param biome The biome used for this world + * @return This {@link CreateWorldOptions} instance. + */ + public @NotNull CreateWorldOptions biome(@Nullable Biome biome) { + this.biome = biome; + return this; + } + + /** + * Gets the single biome used for this world. This may be null, in which case the biome from the generator will be used. + * If no generator is specified, the "natural" biome behaviour for this environment will be used. + * + * @return The biome used for this world + */ + public @NotNull Biome biome() { + return biome; + } + /** * Sets the environment of the world to create. * diff --git a/src/main/java/org/mvplugins/multiverse/core/world/options/ImportWorldOptions.java b/src/main/java/org/mvplugins/multiverse/core/world/options/ImportWorldOptions.java index a082ca4eb..48daa854a 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/options/ImportWorldOptions.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/options/ImportWorldOptions.java @@ -1,6 +1,7 @@ package org.mvplugins.multiverse.core.world.options; import org.bukkit.World; +import org.bukkit.block.Biome; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -20,6 +21,7 @@ public class ImportWorldOptions { } private final String worldName; + private Biome biome; private World.Environment environment = World.Environment.NORMAL; private String generator = null; private boolean useSpawnAdjust = true; @@ -37,6 +39,28 @@ public class ImportWorldOptions { return worldName; } + /** + * Sets the single biome used for this world. This may be null, in which case the biome from the generator will be used. + * If no generator is specified, the "natural" biome behaviour for this environment will be used. + * + * @param biome The biome used for this world + * @return This {@link ImportWorldOptions} instance. + */ + public @NotNull ImportWorldOptions biome(@Nullable Biome biome) { + this.biome = biome; + return this; + } + + /** + * Gets the single biome used for this world. This may be null, in which case the biome from the generator will be used. + * If no generator is specified, the "natural" biome behaviour for this environment will be used. + * + * @return The biome used for this world + */ + public @NotNull Biome biome() { + return biome; + } + /** * Sets the environment of the world to create. * diff --git a/src/main/java/org/mvplugins/multiverse/core/world/options/RegenWorldOptions.java b/src/main/java/org/mvplugins/multiverse/core/world/options/RegenWorldOptions.java index c7475039f..e71c79631 100644 --- a/src/main/java/org/mvplugins/multiverse/core/world/options/RegenWorldOptions.java +++ b/src/main/java/org/mvplugins/multiverse/core/world/options/RegenWorldOptions.java @@ -2,6 +2,7 @@ import java.util.Random; +import org.bukkit.block.Biome; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -23,9 +24,9 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions { } private final LoadedMultiverseWorld world; + private Biome biome; private boolean keepGameRule = true; private boolean keepWorldConfig = true; - private boolean keepWorldBorder = true; private boolean randomSeed = false; private long seed = Long.MIN_VALUE; @@ -43,6 +44,28 @@ public final class RegenWorldOptions implements KeepWorldSettingsOptions { return world; } + /** + * Sets the single biome used for this world. This may be null, in which case the biome from the generator will be used. + * If no generator is specified, the "natural" biome behaviour for this environment will be used. + * + * @param biome The biome used for this world + * @return This {@link RegenWorldOptions} instance. + */ + public @NotNull RegenWorldOptions biome(@Nullable Biome biome) { + this.biome = biome; + return this; + } + + /** + * Gets the single biome used for this world. This may be null, in which case the biome from the generator will be used. + * If no generator is specified, the "natural" biome behaviour for this environment will be used. + * + * @return The biome used for this world + */ + public @NotNull Biome biome() { + return biome; + } + /** * Sets whether to keep the game rule of the world during regeneration. * diff --git a/src/main/resources/multiverse-core_en.properties b/src/main/resources/multiverse-core_en.properties index 12accad63..d393b7d46 100644 --- a/src/main/resources/multiverse-core_en.properties +++ b/src/main/resources/multiverse-core_en.properties @@ -39,6 +39,7 @@ mv-core.create.properties.environment=- Environment: &f{environment} mv-core.create.properties.seed=- Seed: &f{seed} mv-core.create.properties.worldtype=- World Type: &f{worldType} mv-core.create.properties.adjustspawn=- Adjust Spawn: &f{adjustSpawn} +mv-core.create.properties.biome=- Biome: &f{biome} mv-core.create.properties.generator=- Generator: &f{generator} mv-core.create.properties.structures=- Structures: &f{structures} mv-core.create.loading=Creating world... diff --git a/src/test/java/org/mvplugins/multiverse/core/commands/CreateCommandTest.kt b/src/test/java/org/mvplugins/multiverse/core/commands/CreateCommandTest.kt index fc8f7222e..dd6b451b0 100644 --- a/src/test/java/org/mvplugins/multiverse/core/commands/CreateCommandTest.kt +++ b/src/test/java/org/mvplugins/multiverse/core/commands/CreateCommandTest.kt @@ -27,4 +27,6 @@ class CreateCommandTest : AbstractWorldCommandTest() { assertEquals(WorldType.FLAT, world.get().worldType.get()) assertFalse(world.get().canGenerateStructures().get()) } + + //todo: Fix mockbukkit getBiomeProvider then added test on single biome world creation } diff --git a/src/test/resources/default_worlds.yml b/src/test/resources/default_worlds.yml index 2a436ab05..5a40e2a1f 100644 --- a/src/test/resources/default_worlds.yml +++ b/src/test/resources/default_worlds.yml @@ -13,6 +13,7 @@ world: currency: '@vault-economy' environment: NORMAL gamemode: SURVIVAL + biome: '@vanilla' generator: '' hidden: false hunger: true @@ -51,6 +52,7 @@ world_nether: currency: '@vault-economy' environment: NETHER gamemode: SURVIVAL + biome: '@vanilla' generator: '' hidden: false hunger: true diff --git a/src/test/resources/delete_worlds.yml b/src/test/resources/delete_worlds.yml index 90e307ecd..b99cd977f 100644 --- a/src/test/resources/delete_worlds.yml +++ b/src/test/resources/delete_worlds.yml @@ -13,6 +13,7 @@ world_nether: currency: '@vault-economy' environment: NETHER gamemode: SURVIVAL + biome: '@vanilla' generator: '' hidden: false hunger: true diff --git a/src/test/resources/migrated_worlds.yml b/src/test/resources/migrated_worlds.yml index abd03db90..bbd9b8177 100644 --- a/src/test/resources/migrated_worlds.yml +++ b/src/test/resources/migrated_worlds.yml @@ -13,6 +13,7 @@ world_the_end: currency: '@vault-economy' environment: THE_END gamemode: SURVIVAL + biome: '@vanilla' generator: '' hidden: false hunger: true @@ -56,6 +57,7 @@ world: currency: '@vault-economy' environment: NORMAL gamemode: SURVIVAL + biome: '@vanilla' generator: '' hidden: false hunger: true diff --git a/src/test/resources/newworld_worlds.yml b/src/test/resources/newworld_worlds.yml index 0049a327c..97ba9ba91 100644 --- a/src/test/resources/newworld_worlds.yml +++ b/src/test/resources/newworld_worlds.yml @@ -13,6 +13,7 @@ world: currency: '@vault-economy' environment: NORMAL gamemode: SURVIVAL + biome: '@vanilla' generator: '' hidden: false hunger: true @@ -51,6 +52,7 @@ world_nether: currency: '@vault-economy' environment: NETHER gamemode: SURVIVAL + biome: '@vanilla' generator: '' hidden: false hunger: true @@ -82,6 +84,7 @@ newworld: auto-heal: true auto-load: true bed-respawn: true + biome: '@vanilla' difficulty: NORMAL entry-fee: enabled: false diff --git a/src/test/resources/properties_worlds.yml b/src/test/resources/properties_worlds.yml index f1bc5cfa0..de66380af 100644 --- a/src/test/resources/properties_worlds.yml +++ b/src/test/resources/properties_worlds.yml @@ -13,6 +13,7 @@ world: currency: @vault-economy environment: NORMAL gamemode: SURVIVAL + biome: '@vanilla' generator: '' hidden: false hunger: true @@ -56,6 +57,7 @@ world_nether: currency: @vault-economy environment: NETHER gamemode: SURVIVAL + biome: '@vanilla' generator: '' hidden: false hunger: true