Enables use-own-generator setting.
https://github.com/BentoBoxWorld/BSkyBlock/issues/94
This commit is contained in:
parent
e2e372fa2d
commit
467f1bb305
|
@ -1,6 +1,7 @@
|
||||||
package world.bentobox.bskyblock;
|
package world.bentobox.bskyblock;
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.WorldCreator;
|
import org.bukkit.WorldCreator;
|
||||||
import org.bukkit.WorldType;
|
import org.bukkit.WorldType;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
@ -77,37 +78,41 @@ public class BSkyBlock extends GameModeAddon {
|
||||||
if (getServer().getWorld(worldName) == null) {
|
if (getServer().getWorld(worldName) == null) {
|
||||||
log("Creating BSkyBlock world ...");
|
log("Creating BSkyBlock world ...");
|
||||||
}
|
}
|
||||||
chunkGenerator = new ChunkGeneratorWorld(this);
|
chunkGenerator = settings.isUseOwnGenerator() ? null : new ChunkGeneratorWorld(this);
|
||||||
// Create the world if it does not exist
|
// Create the world if it does not exist
|
||||||
islandWorld = WorldCreator.name(worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(chunkGenerator)
|
islandWorld = getWorld(worldName, World.Environment.NORMAL, chunkGenerator);
|
||||||
.createWorld();
|
|
||||||
|
|
||||||
// Make the nether if it does not exist
|
// Make the nether if it does not exist
|
||||||
if (settings.isNetherGenerate()) {
|
if (settings.isNetherGenerate()) {
|
||||||
if (getServer().getWorld(worldName + NETHER) == null) {
|
if (getServer().getWorld(worldName + NETHER) == null) {
|
||||||
log("Creating BSkyBlock's Nether...");
|
log("Creating BSkyBlock's Nether...");
|
||||||
}
|
}
|
||||||
if (!settings.isNetherIslands()) {
|
netherWorld = settings.isNetherIslands() ? getWorld(worldName, World.Environment.NETHER, chunkGenerator) : getWorld(worldName, World.Environment.NETHER, null);
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Make the end if it does not exist
|
// Make the end if it does not exist
|
||||||
if (settings.isEndGenerate()) {
|
if (settings.isEndGenerate()) {
|
||||||
if (getServer().getWorld(worldName + THE_END) == null) {
|
if (getServer().getWorld(worldName + THE_END) == null) {
|
||||||
log("Creating BSkyBlock's End World...");
|
log("Creating BSkyBlock's End World...");
|
||||||
}
|
}
|
||||||
if (!settings.isEndIslands()) {
|
endWorld = settings.isEndIslands() ? getWorld(worldName, World.Environment.THE_END, chunkGenerator) : getWorld(worldName, World.Environment.THE_END, null);
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
@Override
|
||||||
public WorldSettings getWorldSettings() {
|
public WorldSettings getWorldSettings() {
|
||||||
return getSettings();
|
return getSettings();
|
||||||
|
|
|
@ -92,7 +92,9 @@ public class Settings implements DataObject, WorldSettings {
|
||||||
|
|
||||||
@ConfigComment("Use your own world generator for this world.")
|
@ConfigComment("Use your own world generator for this world.")
|
||||||
@ConfigComment("In this case, the plugin will not generate anything.")
|
@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;
|
private boolean useOwnGenerator;
|
||||||
|
|
||||||
@ConfigComment("Sea height (don't changes this mid-game unless you delete the world)")
|
@ConfigComment("Sea height (don't changes this mid-game unless you delete the world)")
|
||||||
|
|
|
@ -39,7 +39,8 @@ world:
|
||||||
island-height: 120
|
island-height: 120
|
||||||
# Use your own world generator for this world.
|
# Use your own world generator for this world.
|
||||||
# In this case, the plugin will not generate anything.
|
# 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
|
use-own-generator: false
|
||||||
# Sea height (don't changes this mid-game unless you delete the world)
|
# Sea height (don't changes this mid-game unless you delete the world)
|
||||||
# Minimum is 0, which means you are playing Skyblock!
|
# Minimum is 0, which means you are playing Skyblock!
|
||||||
|
|
|
@ -216,4 +216,15 @@ public class BSkyBlockTest {
|
||||||
assertTrue(addon.getDefaultWorldGenerator("", "") instanceof ChunkGeneratorWorld);
|
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("", ""));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue