Enables use-own-generator setting.

https://github.com/BentoBoxWorld/BSkyBlock/issues/94
This commit is contained in:
tastybento 2019-03-09 11:22:28 -08:00
parent e2e372fa2d
commit 467f1bb305
4 changed files with 36 additions and 17 deletions

View File

@ -1,6 +1,7 @@
package world.bentobox.bskyblock;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
import org.bukkit.generator.ChunkGenerator;
@ -77,37 +78,41 @@ public class BSkyBlock extends GameModeAddon {
if (getServer().getWorld(worldName) == null) {
log("Creating BSkyBlock world ...");
}
chunkGenerator = new ChunkGeneratorWorld(this);
chunkGenerator = settings.isUseOwnGenerator() ? null : new ChunkGeneratorWorld(this);
// Create the world if it does not exist
islandWorld = WorldCreator.name(worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(chunkGenerator)
.createWorld();
islandWorld = getWorld(worldName, World.Environment.NORMAL, chunkGenerator);
// Make the nether if it does not exist
if (settings.isNetherGenerate()) {
if (getServer().getWorld(worldName + NETHER) == null) {
log("Creating BSkyBlock's Nether...");
}
if (!settings.isNetherIslands()) {
netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld();
} else {
netherWorld = WorldCreator.name(worldName + NETHER).type(WorldType.FLAT).generator(chunkGenerator)
.environment(World.Environment.NETHER).createWorld();
}
netherWorld = settings.isNetherIslands() ? getWorld(worldName, World.Environment.NETHER, chunkGenerator) : getWorld(worldName, World.Environment.NETHER, null);
}
// Make the end if it does not exist
if (settings.isEndGenerate()) {
if (getServer().getWorld(worldName + THE_END) == null) {
log("Creating BSkyBlock's End World...");
}
if (!settings.isEndIslands()) {
endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.NORMAL).environment(World.Environment.THE_END).createWorld();
} else {
endWorld = WorldCreator.name(worldName + THE_END).type(WorldType.FLAT).generator(chunkGenerator)
.environment(World.Environment.THE_END).createWorld();
}
endWorld = settings.isEndIslands() ? getWorld(worldName, World.Environment.THE_END, chunkGenerator) : getWorld(worldName, World.Environment.THE_END, null);
}
}
/**
* Gets a world or generates a new world if it does not exist
* @param worldName - the overworld name
* @param env - the environment
* @param chunkGenerator2 - the chunk generator. If <tt>null</tt> then the generator will not be specified
* @return world loaded or generated
*/
private World getWorld(String worldName, Environment env, ChunkGeneratorWorld chunkGenerator2) {
// Set world name
worldName = env.equals(World.Environment.NETHER) ? worldName + NETHER : worldName;
worldName = env.equals(World.Environment.THE_END) ? worldName + THE_END : worldName;
WorldCreator wc = WorldCreator.name(worldName).type(WorldType.FLAT).environment(env);
return settings.isUseOwnGenerator() ? wc.createWorld() : wc.generator(chunkGenerator2).createWorld();
}
@Override
public WorldSettings getWorldSettings() {
return getSettings();

View File

@ -92,7 +92,9 @@ public class Settings implements DataObject, WorldSettings {
@ConfigComment("Use your own world generator for this world.")
@ConfigComment("In this case, the plugin will not generate anything.")
@ConfigEntry(path = "world.use-own-generator", experimental = true)
@ConfigComment("If used, you must specify the world name and generator in the bukkit.yml file.")
@ConfigComment("See https://bukkit.gamepedia.com/Bukkit.yml#.2AOPTIONAL.2A_worlds")
@ConfigEntry(path = "world.use-own-generator")
private boolean useOwnGenerator;
@ConfigComment("Sea height (don't changes this mid-game unless you delete the world)")

View File

@ -39,7 +39,8 @@ world:
island-height: 120
# Use your own world generator for this world.
# In this case, the plugin will not generate anything.
# /!\ This feature is experimental and might not work as expected or might not work at all.
# If used, you must specify the world name and generator in the bukkit.yml file.
# See https://bukkit.gamepedia.com/Bukkit.yml#.2AOPTIONAL.2A_worlds
use-own-generator: false
# Sea height (don't changes this mid-game unless you delete the world)
# Minimum is 0, which means you are playing Skyblock!

View File

@ -216,4 +216,15 @@ public class BSkyBlockTest {
assertTrue(addon.getDefaultWorldGenerator("", "") instanceof ChunkGeneratorWorld);
}
/**
* Test method for {@link world.bentobox.bskyblock.BSkyBlock#getDefaultWorldGenerator(java.lang.String, java.lang.String)}.
*/
@Test
public void testGetDefaultWorldGeneratorStringStringUseOwnGenerator() {
addon.onLoad();
addon.getSettings().setUseOwnGenerator(true);
addon.createWorlds();
assertNull(addon.getDefaultWorldGenerator("", ""));
}
}