Search in sources :

Example 1 with PluginCreationException

use of io.xol.chunkstories.api.exceptions.plugins.PluginCreationException in project chunkstories by Hugobros3.

the class DefaultPluginManager method enablePlugins.

private void enablePlugins(LinkedList<PluginInformationImplementation> pluginsToInitialize) {
    logger().info(pluginsToInitialize.size() + " plugins to initialize");
    Deque<PluginInformationImplementation> order = new LinkedBlockingDeque<PluginInformationImplementation>();
    // TODO sort plugins requirements (requires/before)
    for (PluginInformationImplementation pluginInformation : pluginsToInitialize) {
        order.add(pluginInformation);
    }
    // Loads each provided plugin
    for (PluginInformationImplementation pluginInformation : order) {
        try {
            // Add commands support
            for (Command command : pluginInformation.getCommands()) {
                // Checks the command isn't already defined
                if (commands.contains(command)) {
                    logger().warn("Plugin " + pluginInformation.getName() + " can't define the command " + command.getName() + " as it's already defined by another plugin.");
                    continue;
                }
                commands.add(command);
                for (String alias : command.aliases()) if (commandsAliases.put(alias, command) != null)
                    logger().warn("Plugin " + pluginInformation + " tried to register alias " + alias + " for command " + command + ".");
            }
            // Instanciate the plugin after all
            ChunkStoriesPlugin pluginInstance = pluginInformation.createInstance(pluginExecutionContext);
            activePlugins.add(pluginInstance);
            pluginInstance.onEnable();
        } catch (PluginCreationException pce) {
            logger().error("Couldn't create plugin " + pluginInformation + " : " + pce.getMessage());
            pce.printStackTrace();
        }
    }
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) SystemCommand(io.xol.chunkstories.api.plugin.commands.SystemCommand) Command(io.xol.chunkstories.api.plugin.commands.Command) PluginCreationException(io.xol.chunkstories.api.exceptions.plugins.PluginCreationException) ChunkStoriesPlugin(io.xol.chunkstories.api.plugin.ChunkStoriesPlugin)

Aggregations

PluginCreationException (io.xol.chunkstories.api.exceptions.plugins.PluginCreationException)1 ChunkStoriesPlugin (io.xol.chunkstories.api.plugin.ChunkStoriesPlugin)1 Command (io.xol.chunkstories.api.plugin.commands.Command)1 SystemCommand (io.xol.chunkstories.api.plugin.commands.SystemCommand)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1