Search in sources :

Example 1 with Command

use of io.xol.chunkstories.api.plugin.commands.Command 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)

Example 2 with Command

use of io.xol.chunkstories.api.plugin.commands.Command in project chunkstories by Hugobros3.

the class DefaultPluginManager method registerCommandHandler.

public void registerCommandHandler(String commandName, CommandHandler commandHandler) {
    Command command = findCommandUsingAlias(commandName);
    if (command == null) {
        logger().warn("Can't register CommandHandler " + commandHandler + " for command " + commandName + " : Command isn't defined.");
        return;
    }
    command.setHandler(commandHandler);
}
Also used : SystemCommand(io.xol.chunkstories.api.plugin.commands.SystemCommand) Command(io.xol.chunkstories.api.plugin.commands.Command)

Example 3 with Command

use of io.xol.chunkstories.api.plugin.commands.Command in project chunkstories by Hugobros3.

the class InfoCommands method handleCommand.

@Override
public boolean handleCommand(CommandEmitter emitter, Command cmd, String[] arguments) {
    if (cmd.getName().equals("uptime")) {
        emitter.sendMessage("#00FFD0The server has been running for " + server.getUptime() + " seconds.");
        return true;
    } else if (cmd.getName().equals("info")) {
        emitter.sendMessage("#00FFD0The server's ip is " + server.getPublicIp());
        emitter.sendMessage("#00FFD0It's running version " + VersionInfo.version + " of the server software.");
        emitter.sendMessage("#00FFD0" + server.getWorld());
        emitter.sendMessage("#00FFD0" + Runtime.getRuntime().freeMemory() / 1024 / 1024 + "Mb used out of " + Runtime.getRuntime().maxMemory() / 1024 / 1024 + "Mb allocated");
        return true;
    } else if (cmd.getName().equals("help")) {
        emitter.sendMessage("#00FFD0Avaible commands :");
        emitter.sendMessage("#00FFD0" + " /plugins");
        emitter.sendMessage("#00FFD0" + " /mods");
        emitter.sendMessage("#00FFD0" + " /list");
        emitter.sendMessage("#00FFD0" + " /info");
        emitter.sendMessage("#00FFD0" + " /uptime");
        for (Command command : server.getPluginManager().commands()) {
            emitter.sendMessage("#00FFD0 /" + command.getName());
        }
        return true;
    } else if (cmd.getName().equals("plugins")) {
        String list = "";
        Iterator<ChunkStoriesPlugin> i = server.getPluginManager().activePlugins();
        while (i.hasNext()) {
            ChunkStoriesPlugin plugin = i.next();
            list += plugin.getName() + (i.hasNext() ? ", " : "");
        }
        emitter.sendMessage("#00FFD0" + i + " active server plugins : " + list);
        return true;
    } else if (cmd.getName().equals("mods")) {
        String list = "";
        int i = 0;
        for (Mod csp : server.getContent().modsManager().getCurrentlyLoadedMods()) {
            i++;
            list += csp.getModInfo().getName() + (i == server.getContent().modsManager().getCurrentlyLoadedMods().size() ? "" : ", ");
        }
        emitter.sendMessage("#FF0000" + i + " active server mods : " + list);
        return true;
    }
    System.out.println("fuck off");
    return false;
}
Also used : Mod(io.xol.chunkstories.api.content.mods.Mod) Command(io.xol.chunkstories.api.plugin.commands.Command) ChunkStoriesPlugin(io.xol.chunkstories.api.plugin.ChunkStoriesPlugin) Iterator(java.util.Iterator)

Aggregations

Command (io.xol.chunkstories.api.plugin.commands.Command)3 ChunkStoriesPlugin (io.xol.chunkstories.api.plugin.ChunkStoriesPlugin)2 SystemCommand (io.xol.chunkstories.api.plugin.commands.SystemCommand)2 Mod (io.xol.chunkstories.api.content.mods.Mod)1 PluginCreationException (io.xol.chunkstories.api.exceptions.plugins.PluginCreationException)1 Iterator (java.util.Iterator)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1