Search in sources :

Example 1 with ChunkGenerator

use of org.bukkit.generator.ChunkGenerator in project Bukkit by Bukkit.

the class WorldCreator method getGeneratorForName.

/**
     * 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;
}
Also used : ChunkGenerator(org.bukkit.generator.ChunkGenerator) Plugin(org.bukkit.plugin.Plugin)

Example 2 with ChunkGenerator

use of org.bukkit.generator.ChunkGenerator in project Glowstone by GlowstoneMC.

the class GlowServer method getGenerator.

/**
     * Gets the default ChunkGenerator for the given environment and type.
     *
     * @return The ChunkGenerator.
     */
private ChunkGenerator getGenerator(String name, Environment environment, WorldType type) {
    // find generator based on configuration
    ConfigurationSection worlds = config.getWorlds();
    if (worlds != null) {
        String genName = worlds.getString(name + ".generator", null);
        ChunkGenerator generator = WorldCreator.getGeneratorForName(name, genName, getConsoleSender());
        if (generator != null) {
            return generator;
        }
    }
    // find generator based on environment and world type
    if (environment == Environment.NETHER) {
        return new NetherGenerator();
    } else if (environment == Environment.THE_END) {
        return new TheEndGenerator();
    } else {
        if (type == WorldType.FLAT) {
            return new SuperflatGenerator();
        } else {
            return new OverworldGenerator();
        }
    }
}
Also used : ChunkGenerator(org.bukkit.generator.ChunkGenerator) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

ChunkGenerator (org.bukkit.generator.ChunkGenerator)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 Plugin (org.bukkit.plugin.Plugin)1