diff --git a/src/main/java/world/bentobox/bskyblock/BSkyBlock.java b/src/main/java/world/bentobox/bskyblock/BSkyBlock.java index 972336e..3563f54 100644 --- a/src/main/java/world/bentobox/bskyblock/BSkyBlock.java +++ b/src/main/java/world/bentobox/bskyblock/BSkyBlock.java @@ -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 null 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(); diff --git a/src/main/java/world/bentobox/bskyblock/Settings.java b/src/main/java/world/bentobox/bskyblock/Settings.java index 9564fa7..b9ebe4d 100644 --- a/src/main/java/world/bentobox/bskyblock/Settings.java +++ b/src/main/java/world/bentobox/bskyblock/Settings.java @@ -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)") diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1478451..3f9dfc1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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! diff --git a/src/test/java/world/bentobox/bskyblock/BSkyBlockTest.java b/src/test/java/world/bentobox/bskyblock/BSkyBlockTest.java index 2f78ee0..b3565ae 100644 --- a/src/test/java/world/bentobox/bskyblock/BSkyBlockTest.java +++ b/src/test/java/world/bentobox/bskyblock/BSkyBlockTest.java @@ -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("", "")); + } + }