Java Code Examples for org.bukkit.plugin.Plugin#getDefaultWorldGenerator()

The following examples show how to use org.bukkit.plugin.Plugin#getDefaultWorldGenerator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorldCreator.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: CraftServer.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
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;
}