下面列出了怎么用org.bukkit.generator.ChunkGenerator的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;
}
/**
* Attempts to get the {@link ChunkGenerator} with the given name.
* <p>
* If the generator is not found, null will be returned and a message will
* be printed to the specified {@link CommandSender} explaining why.
* <p>
* The name must be in the "plugin:id" notation, or optionally just
* "plugin", where "plugin" is the safe-name of a plugin and "id" is an
* optional unique identifier for the generator you wish to request from
* the plugin.
*
* @param world Name of the world this will be used for
* @param name Name of the generator to retrieve
* @param output Where to output if errors are present
* @return Resulting generator, or null
*/
public static ChunkGenerator getGeneratorForName(String world, String name, CommandSender output) {
ChunkGenerator result = null;
if (world == null) {
throw new IllegalArgumentException("World name must be specified");
}
if (output == null) {
output = Bukkit.getConsoleSender();
}
if (name != null) {
String[] split = name.split(":", 2);
String id = (split.length > 1) ? split[1] : null;
Plugin plugin = Bukkit.getPluginManager().getPlugin(split[0]);
if (plugin == null) {
output.sendMessage("Could not set generator for world '" + world + "': Plugin '" + split[0] + "' does not exist");
} else if (!plugin.isEnabled()) {
output.sendMessage("Could not set generator for world '" + world + "': Plugin '" + plugin.getDescription().getFullName() + "' is not enabled");
} else {
result = plugin.getDefaultWorldGenerator(world, id);
}
}
return result;
}
public CraftWorld(WorldServer world, ChunkGenerator gen, Environment env) {
this.world = world;
this.generator = gen;
environment = env;
if (server.chunkGCPeriod > 0) {
chunkGCTickCount = rand.nextInt(server.chunkGCPeriod);
}
}
public ChunkGenerator getGenerator(String world) {
ConfigurationSection section = configuration.getConfigurationSection("worlds");
ChunkGenerator result = null;
if (section != null) {
section = section.getConfigurationSection(world);
if (section != null) {
String name = section.getString("generator");
if ((name != null) && (!name.equals(""))) {
String[] split = name.split(":", 2);
String id = (split.length > 1) ? split[1] : null;
Plugin plugin = pluginManager.getPlugin(split[0]);
if (plugin == null) {
getLogger().severe("Could not set generator for default world '" + world + "': Plugin '"
+ split[0] + "' does not exist");
} else if (!plugin.isEnabled()) {
getLogger().severe("Could not set generator for default world '" + world + "': Plugin '"
+ plugin.getDescription().getFullName() + "' is not enabled yet (is it load:STARTUP?)");
} else {
try {
result = plugin.getDefaultWorldGenerator(world, id);
if (result == null) {
getLogger().severe("Could not set generator for default world '" + world + "': Plugin '"
+ plugin.getDescription().getFullName() + "' lacks a default world generator");
}
} catch (Throwable t) {
plugin.getLogger().log(Level.SEVERE, "Could not set generator for default world '" + world
+ "': Plugin '" + plugin.getDescription().getFullName(), t);
}
}
}
}
}
return result;
}
public CraftWorld(net.minecraft.world.WorldServer world, ChunkGenerator gen, Environment env) {
this.world = world;
this.generator = gen;
environment = env;
if (server.chunkGCPeriod > 0) {
chunkGCTickCount = rand.nextInt(server.chunkGCPeriod);
}
}
public ChunkGenerator getGenerator(String world) {
ConfigurationSection section = configuration.getConfigurationSection("worlds");
ChunkGenerator result = null;
if (section != null) {
section = section.getConfigurationSection(world);
if (section != null) {
String name = section.getString("generator");
if ((name != null) && (!name.equals(""))) {
String[] split = name.split(":", 2);
String id = (split.length > 1) ? split[1] : null;
Plugin plugin = pluginManager.getPlugin(split[0]);
if (plugin == null) {
getLogger().severe("Could not set generator for default world '" + world + "': Plugin '" + split[0] + "' does not exist");
} else if (!plugin.isEnabled()) {
getLogger().severe("Could not set generator for default world '" + world + "': Plugin '" + plugin.getDescription().getFullName() + "' is not enabled yet (is it load:STARTUP?)");
} else {
try {
result = plugin.getDefaultWorldGenerator(world, id);
if (result == null) {
getLogger().severe("Could not set generator for default world '" + world + "': Plugin '" + plugin.getDescription().getFullName() + "' lacks a default world generator");
}
} catch (Throwable t) {
plugin.getLogger().log(Level.SEVERE, "Could not set generator for default world '" + world + "': Plugin '" + plugin.getDescription().getFullName(), t);
}
}
}
}
}
return result;
}
@Override
public ChunkGenerator getChunkGenerator() {
return new ChunkGenerator() {
@Override
public final ChunkGenerator.ChunkData generateChunkData(final World world, final Random random, final int x, final int z, final ChunkGenerator.BiomeGrid chunkGererator) {
final ChunkGenerator.ChunkData chunkData = this.createChunkData(world);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
chunkGererator.setBiome(i, j, Biome.VOID);
}
}
return chunkData;
}
};
}
@Override
public ChunkGenerator getChunkGenerator() {
return new ChunkGenerator() {
@Override
public final ChunkGenerator.ChunkData generateChunkData(final World world, final Random random, final int x, final int z, final ChunkGenerator.BiomeGrid chunkGererator) {
final ChunkGenerator.ChunkData chunkData = this.createChunkData(world);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
chunkGererator.setBiome(i, j, Biome.VOID);
}
}
return chunkData;
}
};
}
@Override
public ChunkGenerator getChunkGenerator() {
return new ChunkGenerator() {
@Override
public final ChunkGenerator.ChunkData generateChunkData(final World world, final Random random, final int x, final int z, final ChunkGenerator.BiomeGrid chunkGererator) {
final ChunkGenerator.ChunkData chunkData = this.createChunkData(world);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
chunkGererator.setBiome(i, j, Biome.THE_VOID);
}
}
return chunkData;
}
};
}
@Override
public ChunkGenerator getChunkGenerator() {
return new ChunkGenerator() {
@Override
public final ChunkGenerator.ChunkData generateChunkData(final World world, final Random random, final int x, final int z, final ChunkGenerator.BiomeGrid chunkGererator) {
final ChunkGenerator.ChunkData chunkData = this.createChunkData(world);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
chunkGererator.setBiome(i, j, Biome.VOID);
}
}
return chunkData;
}
};
}
@Override
public ChunkGenerator getChunkGenerator() {
return new ChunkGenerator() {
@Override
public final ChunkGenerator.ChunkData generateChunkData(final World world, final Random random, final int x, final int z, final ChunkGenerator.BiomeGrid chunkGererator) {
final ChunkGenerator.ChunkData chunkData = this.createChunkData(world);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
chunkGererator.setBiome(i, j, Biome.VOID);
}
}
return chunkData;
}
};
}
@Override
public ChunkGenerator getChunkGenerator() {
return new ChunkGenerator() {
@Override
public final ChunkGenerator.ChunkData generateChunkData(final World world, final Random random, final int x, final int z, final ChunkGenerator.BiomeGrid chunkGererator) {
final ChunkGenerator.ChunkData chunkData = this.createChunkData(world);
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 16; j++) {
chunkGererator.setBiome(i, j, Biome.VOID);
}
}
return chunkData;
}
};
}
/**
* Gets the {@link ChunkGenerator} responsible for generating chunks in the overworld skyworld.
* @return ChunkGenerator for overworld skyworld.
*/
@NotNull
private ChunkGenerator getOverworldGenerator() {
try {
String clazz = plugin.getConfig().getString("options.advanced.chunk-generator",
"us.talabrek.ultimateskyblock.world.SkyBlockChunkGenerator");
Object generator = Class.forName(clazz).newInstance();
if (generator instanceof ChunkGenerator) {
return (ChunkGenerator) generator;
}
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException ex) {
logger.log(Level.WARNING, "Invalid overworld chunk-generator configured: " + ex);
}
return new SkyBlockChunkGenerator();
}
/**
* Gets the {@link ChunkGenerator} responsible for generating chunks in the nether skyworld.
* @return ChunkGenerator for nether skyworld.
*/
@NotNull
private ChunkGenerator getNetherGenerator() {
try {
String clazz = plugin.getConfig().getString("nether.chunk-generator",
"us.talabrek.ultimateskyblock.world.SkyBlockNetherChunkGenerator");
Object generator = Class.forName(clazz).newInstance();
if (generator instanceof ChunkGenerator) {
return (ChunkGenerator) generator;
}
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException ex) {
logger.log(Level.WARNING, "Invalid nether chunk-generator configured: " + ex);
}
return new SkyBlockNetherChunkGenerator();
}
/**
* Gets a {@link ChunkGenerator} for use in a default world, as specified in the server configuration
* @param worldName Name of the world that this will be applied to
* @param id Unique ID, if any, that was specified to indicate which generator was requested
* @return ChunkGenerator for use in the default world generation
*/
@Nullable
public ChunkGenerator getDefaultWorldGenerator(@NotNull String worldName, @Nullable String id) {
Validate.notNull(worldName, "WorldName cannot be null");
return ((id != null && id.endsWith("nether")) || (worldName.endsWith("nether")))
&& Settings.nether_enabled
? getNetherGenerator()
: getOverworldGenerator();
}
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
if (worldName.equals(configuration.worldName) || worldName.equals(configuration.netherWorldName))
return generator;
return super.getDefaultWorldGenerator(worldName, id);
}
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
return null;
}
public CustomChunkGenerator(World world, long seed, ChunkGenerator generator) {
this.world = (WorldServer) world;
this.generator = generator;
this.random = new Random(seed);
}
public ChunkGenerator getGenerator() {
return generator;
}
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);
WorldType type = 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(), WorldSettings.getGameTypeById(getDefaultGameMode().getValue()), generateStructures, hardcore, type);
WorldServer internal = DimensionManager.initDimension(creator, worldSettings);
pluginManager.callEvent(new WorldInitEvent(internal.getWorld()));
System.out.println("Preparing start region for level " + (console.worldServerList.size() - 1) + " (Seed: " + internal.getSeed() + ")");
if (internal.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 " + name + ", " + (j1 * 100 / i1) + "%");
i = l;
}
BlockPos chunkcoordinates = internal.getSpawnPoint();
internal.getChunkProvider().loadChunk(chunkcoordinates.getX() + j >> 4, chunkcoordinates.getZ() + k >> 4);
}
}
}
pluginManager.callEvent(new WorldLoadEvent(internal.getWorld()));
return internal.getWorld();
}
@Override
public ChunkGenerator.ChunkData createChunkData(World world) {
return new CraftChunkData(world);
}
@Override
public ChunkGenerator getDefaultWorldGenerator(String s, String s1) {
return null;
}
@Override
public ChunkGenerator getGenerator() {
return null;
}
@Override
public ChunkGenerator.ChunkData createChunkData(World world) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
return null;
}
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
return plugin.getDefaultWorldGenerator(worldName, id);
}
@Override
public ChunkGenerator.ChunkData createChunkData(World world) {
return null;
}