下面列出了怎么用org.bukkit.WorldCreator的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Gets the skyblock island {@link World}. Creates and/or imports the world if necessary.
* @return Skyblock island world.
*/
@NotNull
public synchronized World getWorld() {
if (skyBlockWorld == null) {
skyBlockWorld = Bukkit.getWorld(Settings.general_worldName);
ChunkGenerator skyGenerator = getOverworldGenerator();
ChunkGenerator worldGenerator = skyBlockWorld != null ? skyBlockWorld.getGenerator() : null;
if (skyBlockWorld == null
|| skyBlockWorld.canGenerateStructures()
|| worldGenerator == null
|| !worldGenerator.getClass().getName().equals(skyGenerator.getClass().getName())) {
skyBlockWorld = WorldCreator
.name(Settings.general_worldName)
.type(WorldType.NORMAL)
.generateStructures(false)
.environment(World.Environment.NORMAL)
.generator(skyGenerator)
.createWorld();
skyBlockWorld.save();
}
MultiverseCoreHandler.importWorld(skyBlockWorld);
setupWorld(skyBlockWorld, island_height);
}
return skyBlockWorld;
}
/**
* Gets the skyblock nether island {@link World}. Creates and/or imports the world if necessary. Returns null if
* the nether is not enabled in the plugin configuration.
* @return Skyblock nether island world, or null if nether is disabled.
*/
@Nullable
public synchronized World getNetherWorld() {
if (skyBlockNetherWorld == null && Settings.nether_enabled) {
skyBlockNetherWorld = Bukkit.getWorld(Settings.general_worldName + "_nether");
ChunkGenerator skyGenerator = getNetherGenerator();
ChunkGenerator worldGenerator = skyBlockNetherWorld != null ? skyBlockNetherWorld.getGenerator() : null;
if (skyBlockNetherWorld == null
|| skyBlockNetherWorld.canGenerateStructures()
|| worldGenerator == null
|| !worldGenerator.getClass().getName().equals(skyGenerator.getClass().getName())) {
skyBlockNetherWorld = WorldCreator
.name(Settings.general_worldName + "_nether")
.type(WorldType.NORMAL)
.generateStructures(false)
.environment(World.Environment.NETHER)
.generator(skyGenerator)
.createWorld();
skyBlockNetherWorld.save();
}
MultiverseCoreHandler.importNetherWorld(skyBlockNetherWorld);
setupWorld(skyBlockNetherWorld, island_height / 2);
MultiverseInventoriesHandler.linkWorlds(getWorld(), skyBlockNetherWorld);
}
return skyBlockNetherWorld;
}
private static World createArenaWorld(ConfigArena arena, String name) {
World world;
world = Bukkit.getServer().getWorld(name);
if (world == null) {
WorldCreator wc = new WorldCreator(name);
wc.environment(Environment.NORMAL);
wc.type(WorldType.FLAT);
wc.generateStructures(false);
world = Bukkit.getServer().createWorld(wc);
world.setAutoSave(false);
world.setSpawnFlags(false, false);
world.setKeepSpawnInMemory(false);
ChunkCoord.addWorld(world);
}
return world;
}
/**
* @return the netherWorld
*/
public static World getNetherWorld() {
if (netherWorld == null && Settings.createNether) {
if (Settings.useOwnGenerator) {
return Bukkit.getServer().getWorld(Settings.worldName +"_nether");
}
if (plugin.getServer().getWorld(Settings.worldName + "_nether") == null) {
Bukkit.getLogger().info("Creating " + plugin.getName() + "'s Nether...");
}
if (!Settings.newNether) {
netherWorld = WorldCreator.name(Settings.worldName + "_nether").type(WorldType.NORMAL).environment(World.Environment.NETHER).createWorld();
} else {
netherWorld = WorldCreator.name(Settings.worldName + "_nether").type(WorldType.FLAT).generator(new ChunkGeneratorWorld())
.environment(World.Environment.NETHER).createWorld();
}
netherWorld.setMonsterSpawnLimit(Settings.monsterSpawnLimit);
netherWorld.setAnimalSpawnLimit(Settings.animalSpawnLimit);
}
return netherWorld;
}
@Override
public World createWorld(String worldName) throws ModuleLoadException, IOException {
if(server.getWorlds().isEmpty()) {
throw new IllegalStateException("Can't create a world because there is no default world to derive it from");
}
try {
importDestructive(terrainOptions.worldFolder().toFile(), worldName);
} catch(FileNotFoundException e) {
// If files are missing, just inform the mapmaker.
// Other IOExceptions are considered internal errors.
throw new ModuleLoadException(e.getMessage()); // Don't set the cause, it's redundant
}
final WorldCreator creator = worldCreator(worldName);
worldConfigurators.forEach(wc -> wc.configureWorld(creator));
final World world = server.createWorld(creator);
if(world == null) {
throw new IllegalStateException("Failed to create world (Server.createWorld returned null)");
}
world.setAutoSave(false);
world.setKeepSpawnInMemory(false);
world.setDifficulty(Optional.ofNullable(mapInfo.difficulty)
.orElseGet(() -> server.getWorlds().get(0).getDifficulty()));
return world;
}
public void loadOldWorld(String uuid, Environment env){
if(uuid == null || uuid.equals("null")){
Bukkit.getLogger().info("[UhcCore] No world to load, defaulting to default behavior");
this.createNewWorld(env);
}else{
File worldDir = new File(uuid);
if(worldDir.exists()){
// Loading existing world
Bukkit.getServer().createWorld(new WorldCreator(uuid));
}else{
this.createNewWorld(env);
}
}
}
/**
* Loads a local world
*
* @param name the world to load
* @return the loaded world
* @throws WorldException if the world is not found or something else goes wrong
*/
@Nonnull
public World loadLocalWorld(@Nonnull String name) {
log.finer("Loading world " + name);
org.bukkit.WorldCreator wc = new WorldCreator(name);
wc.environment(World.Environment.NORMAL); //TODO do we need support for environment in maps?
wc.generateStructures(false);
wc.type(WorldType.NORMAL);
wc.generator(new CleanRoomChunkGenerator());
wc.generatorSettings("");
World world = wc.createWorld();
world.setAutoSave(false);
return world;
}
public World createWorld(final WorldCreator creator) {
World world = TaskManager.IMP.sync(new RunnableVal<World>() {
@Override
public void run(World value) {
disableChunkLoad = true;
this.value = creator.createWorld();
disableChunkLoad = false;
}
});
return world;
}
/**
* Generate a new DResourceWorld.
*
* @return the automatically created DEditWorld instance
*/
public DEditWorld generate() {
int id = DInstanceWorld.counter;
String name = DInstanceWorld.generateName(false, id);
File folder = new File(Bukkit.getWorldContainer(), name);
WorldCreator creator = new WorldCreator(name);
creator.type(WorldType.FLAT);
creator.generateStructures(false);
DEditWorld editWorld = new DEditWorld(plugin, this, folder);
this.editWorld = editWorld;
EditWorldGenerateEvent event = new EditWorldGenerateEvent(editWorld);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;
}
if (!RAW.exists()) {
createRaw();
}
FileUtil.copyDir(RAW, folder, DungeonsXL.EXCLUDED_FILES);
editWorld.generateIdFile();
editWorld.world = creator.createWorld().getName();
editWorld.generateIdFile();
return editWorld;
}
/**
* Creates the "raw" world that is copied for new instances.
*/
public static void createRaw() {
WorldCreator rawCreator = WorldCreator.name(".raw");
rawCreator.type(WorldType.FLAT);
rawCreator.generateStructures(false);
World world = rawCreator.createWorld();
File worldFolder = new File(Bukkit.getWorldContainer(), ".raw");
FileUtil.copyDir(worldFolder, RAW, DungeonsXL.EXCLUDED_FILES);
Bukkit.unloadWorld(world, /* SPIGOT-5225 */ !Version.isAtLeast(Version.MC1_14_4));
FileUtil.removeDir(worldFolder);
}
public void create_cmd() throws CivException {
String name = getNamedString(1, "enter a world name");
WorldCreator wc = new WorldCreator(name);
wc.environment(Environment.NORMAL);
wc.type(WorldType.FLAT);
wc.generateStructures(false);
World world = Bukkit.getServer().createWorld(wc);
world.setSpawnFlags(false, false);
ChunkCoord.addWorld(world);
CivMessage.sendSuccess(sender, "World "+name+" created.");
}
/**
* Returns the World object for the island world named in config.yml.
* If the world does not exist then it is created.
*
* @return islandWorld - Bukkit World object for the ASkyBlock world
*/
public static World getIslandWorld() {
if (islandWorld == null) {
//Bukkit.getLogger().info("DEBUG worldName = " + Settings.worldName);
//
if (Settings.useOwnGenerator) {
islandWorld = Bukkit.getServer().getWorld(Settings.worldName);
//Bukkit.getLogger().info("DEBUG world is " + islandWorld);
} else {
islandWorld = WorldCreator.name(Settings.worldName).type(WorldType.FLAT).environment(World.Environment.NORMAL).generator(new ChunkGeneratorWorld())
.createWorld();
}
// Make the nether if it does not exist
if (Settings.createNether) {
getNetherWorld();
}
// Multiverse configuration
if (!Settings.useOwnGenerator && Bukkit.getServer().getPluginManager().isPluginEnabled("Multiverse-Core")) {
// Run sync
if (!Bukkit.isPrimaryThread()) {
Bukkit.getScheduler().runTask(plugin, ASkyBlock::registerMultiverse);
} else {
registerMultiverse();
}
}
}
// Set world settings
if (islandWorld != null) {
islandWorld.setWaterAnimalSpawnLimit(Settings.waterAnimalSpawnLimit);
islandWorld.setMonsterSpawnLimit(Settings.monsterSpawnLimit);
islandWorld.setAnimalSpawnLimit(Settings.animalSpawnLimit);
}
return islandWorld;
}
@Override
public void run() {
GenerateMap.copyWorldFromRepository(map.getFolder(), uuid);
World world = new WorldCreator("matches/" + uuid.toString()).generator(new NullChunkGenerator()).createWorld();
world.setPVP(true);
handler.setMatchWorld(world);
handler.setMatchFile(new File("matches/" + uuid.toString() + "/"));
}
@Override
public void configureWorld(WorldCreator worldCreator) {
worldCreator.environment(info.dimension);
}
private WorldCreator worldCreator(String worldName) {
final WorldCreator creator = server.detectWorld(worldName);
return creator != null ? creator : new WorldCreator(worldName);
}
@Override
public void configureWorld(WorldCreator worldCreator) {
worldCreator.generator(vanilla ? null : new NullChunkGenerator());
worldCreator.seed(seed);
}
public static boolean loadGameMap(File worldFolder)
{
// if(tempWorldDirec == null)
// {
// tempWorldDirec = new File(AnnihilationMain.getInstance().getDataFolder()+"/TempWorld");
// if(!tempWorldDirec.exists())
// tempWorldDirec.mkdirs();
// }
if(worldFolder.exists() && worldFolder.isDirectory())
{
File[] files = worldFolder.listFiles(new FilenameFilter()
{
public boolean accept(File file, String name)
{
return name.equalsIgnoreCase("level.dat");
}
});
if ((files != null) && (files.length == 1))
{
try
{
//We have confirmed that the folder has a level.dat
//Now we should copy all the files into the temp world folder
//worldDirec = worldFolder;
//FileUtils.copyDirectory(worldDirec, tempWorldDirec);
String path = worldFolder.getPath();
if(path.contains("plugins"))
path = path.substring(path.indexOf("plugins"));
WorldCreator cr = new WorldCreator(path);
//WorldCreator cr = new WorldCreator(new File(worldFolder,"level.dat").toString());
cr.environment(Environment.NORMAL);
World mapWorld = Bukkit.createWorld(cr);
if(mapWorld != null)
{
if(GameMap != null)
{
GameMap.unLoadMap();
GameMap = null;
}
mapWorld.setAutoSave(false);
mapWorld.setGameRuleValue("doMobSpawning", "false");
mapWorld.setGameRuleValue("doFireTick", "false");
// File anniConfig = new File(worldFolder,"AnniMapConfig.yml");
// if(!anniConfig.exists())
// anniConfig.createNewFile();
//YamlConfiguration mapconfig = ConfigManager.loadMapConfig(anniConfig);
Game.GameMap = new GameMap(mapWorld.getName(),worldFolder);
GameMap.registerListeners(AnnihilationMain.getInstance());
Game.worldNames.put(worldFolder.getName().toLowerCase(), mapWorld.getName());
Game.niceNames.put(mapWorld.getName().toLowerCase(),worldFolder.getName());
return true;
}
}
catch(Exception e)
{
e.printStackTrace();
GameMap = null;
return false;
}
}
}
return false;
}
public World createWorld(String name, World.Environment environment) {
return WorldCreator.name(name).environment(environment).createWorld();
}
public World createWorld(String name, World.Environment environment, long seed) {
return WorldCreator.name(name).environment(environment).seed(seed).createWorld();
}
public World createWorld(String name, Environment environment, ChunkGenerator generator) {
return WorldCreator.name(name).environment(environment).generator(generator).createWorld();
}
public World createWorld(String name, Environment environment, long seed, ChunkGenerator generator) {
return WorldCreator.name(name).environment(environment).seed(seed).generator(generator).createWorld();
}
@Override
public World createWorld(WorldCreator creator) {
Validate.notNull(creator, "Creator may not be null");
String name = creator.name();
ChunkGenerator generator = creator.generator();
File folder = new File(getWorldContainer(), name);
World world = getWorld(name);
net.minecraft.world.WorldType type = net.minecraft.world.WorldType.parseWorldType(creator.type().getName());
boolean generateStructures = creator.generateStructures();
if ((folder.exists()) && (!folder.isDirectory())) {
throw new IllegalArgumentException("File exists with the name '" + name + "' and isn't a folder");
}
if (world != null) {
return world;
}
boolean hardcore = false;
WorldSettings worldSettings = new WorldSettings(creator.seed(), net.minecraft.world.WorldSettings.GameType.getByID(getDefaultGameMode().getValue()), generateStructures, hardcore, type);
net.minecraft.world.WorldServer worldserver = DimensionManager.initDimension(creator, worldSettings);
pluginManager.callEvent(new WorldInitEvent(worldserver.getWorld()));
net.minecraftforge.cauldron.CauldronHooks.craftWorldLoading = true;
System.out.print("Preparing start region for level " + (console.worlds.size() - 1) + " (Dimension: " + worldserver.provider.dimensionId + ", Seed: " + worldserver.getSeed() + ")"); // Cauldron - log dimension
if (worldserver.getWorld().getKeepSpawnInMemory()) {
short short1 = 196;
long i = System.currentTimeMillis();
for (int j = -short1; j <= short1; j += 16) {
for (int k = -short1; k <= short1; k += 16) {
long l = System.currentTimeMillis();
if (l < i) {
i = l;
}
if (l > i + 1000L) {
int i1 = (short1 * 2 + 1) * (short1 * 2 + 1);
int j1 = (j + short1) * (short1 * 2 + 1) + k + 1;
System.out.println("Preparing spawn area for " + worldserver.getWorld().getName() + ", " + (j1 * 100 / i1) + "%");
i = l;
}
net.minecraft.util.ChunkCoordinates chunkcoordinates = worldserver.getSpawnPoint();
worldserver.theChunkProviderServer.loadChunk(chunkcoordinates.posX + j >> 4, chunkcoordinates.posZ + k >> 4);
}
}
}
pluginManager.callEvent(new WorldLoadEvent(worldserver.getWorld()));
net.minecraftforge.cauldron.CauldronHooks.craftWorldLoading = false;
return worldserver.getWorld();
}
/**
* Create a world async (untested)
* - Only optimized for 1.10
* @param creator
* @return
*/
public synchronized static AsyncWorld create(final WorldCreator creator) {
BukkitQueue_0 queue = (BukkitQueue_0) SetQueue.IMP.getNewQueue(creator.name(), true, false);
World world = queue.createWorld(creator);
return wrap(world);
}
void configureWorld(WorldCreator worldCreator);