Search in sources :

Example 1 with ChunkStoriesPlugin

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

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

the class ChatManager method processTextInput.

private void processTextInput(String input) {
    String username = ingame.getGameWindow().getClient().username();
    if (input.startsWith("/")) {
        String chatMsg = input;
        chatMsg = chatMsg.substring(1, chatMsg.length());
        String cmdName = chatMsg.toLowerCase();
        String[] args = {};
        if (chatMsg.contains(" ")) {
            cmdName = chatMsg.substring(0, chatMsg.indexOf(" "));
            args = chatMsg.substring(chatMsg.indexOf(" ") + 1, chatMsg.length()).split(" ");
        }
        if (ingame.getGameWindow().getClient().getPluginManager().dispatchCommand(Client.getInstance().getPlayer(), cmdName, args)) {
            if (sent.size() == 0 || !sent.get(0).equals(input)) {
                sent.add(0, input);
                sentMessages++;
            }
            return;
        } else if (cmdName.equals("plugins")) {
            String list = "";
            Iterator<ChunkStoriesPlugin> i = ingame.getGameWindow().getClient().getPluginManager().activePlugins();
            while (i.hasNext()) {
                ChunkStoriesPlugin plugin = i.next();
                list += plugin.getName() + (i.hasNext() ? ", " : "");
            }
            if (Client.getInstance().getWorld() instanceof WorldClientLocal)
                insert("#00FFD0" + i + " active client [master] plugins : " + list);
            else
                insert("#74FFD0" + i + " active client [remote] plugins : " + list);
            if (sent.size() == 0 || !sent.get(0).equals(input)) {
                sent.add(0, input);
                sentMessages++;
            }
        } else if (cmdName.equals("mods")) {
            String list = "";
            int i = 0;
            for (Mod mod : Client.getInstance().getContent().modsManager().getCurrentlyLoadedMods()) {
                i++;
                list += mod.getModInfo().getName() + (i == Client.getInstance().getContent().modsManager().getCurrentlyLoadedMods().size() ? "" : ", ");
            }
            if (Client.getInstance().getWorld() instanceof WorldClientLocal)
                insert("#FF0000" + i + " active client [master] mods : " + list);
            else
                insert("#FF7070" + i + " active client [remote] mods : " + list);
            if (sent.size() == 0 || !sent.get(0).equals(input)) {
                sent.add(0, input);
                sentMessages++;
            }
        }
    }
    if (input.equals("/locclear")) {
        chat.clear();
    } else if (input.equals("I am Mr Debug")) {
        // it was you this whole time
        ClientLimitations.isDebugAllowed = true;
    }
    if (ingame.getGameWindow().getClient().getWorld() instanceof WorldClientRemote)
        ((WorldClientRemote) ingame.getGameWindow().getClient().getWorld()).getConnection().sendTextMessage("chat/" + input);
    else
        insert(ColorsTools.getUniqueColorPrefix(username) + username + "#FFFFFF > " + input);
    System.out.println(username + " > " + input);
    if (sent.size() == 0 || !sent.get(0).equals(input)) {
        sent.add(0, input);
        sentMessages++;
    }
}
Also used : Mod(io.xol.chunkstories.api.content.mods.Mod) ChunkStoriesPlugin(io.xol.chunkstories.api.plugin.ChunkStoriesPlugin) Iterator(java.util.Iterator) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) WorldClientLocal(io.xol.chunkstories.world.WorldClientLocal)

Example 3 with ChunkStoriesPlugin

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

the class DefaultPluginManager method disablePlugins.

@Override
public void disablePlugins() {
    // Call onDisable for plugins
    for (ChunkStoriesPlugin plugin : activePlugins) plugin.onDisable();
    // Remove one by one each listener
    for (Entry<EventListeners, RegisteredListener> e : registeredEventListeners.entrySet()) {
        e.getKey().unRegisterListener(e.getValue());
    }
    // Remove registered commands
    // TODO only remove plugins commands
    commandsAliases.clear();
    commands.clear();
    // At last clear the plugins list
    activePlugins.clear();
}
Also used : ChunkStoriesPlugin(io.xol.chunkstories.api.plugin.ChunkStoriesPlugin) EventListeners(io.xol.chunkstories.api.events.EventListeners) RegisteredListener(io.xol.chunkstories.api.events.RegisteredListener)

Example 4 with ChunkStoriesPlugin

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

ChunkStoriesPlugin (io.xol.chunkstories.api.plugin.ChunkStoriesPlugin)4 Mod (io.xol.chunkstories.api.content.mods.Mod)2 Command (io.xol.chunkstories.api.plugin.commands.Command)2 Iterator (java.util.Iterator)2 EventListeners (io.xol.chunkstories.api.events.EventListeners)1 RegisteredListener (io.xol.chunkstories.api.events.RegisteredListener)1 PluginCreationException (io.xol.chunkstories.api.exceptions.plugins.PluginCreationException)1 SystemCommand (io.xol.chunkstories.api.plugin.commands.SystemCommand)1 WorldClientLocal (io.xol.chunkstories.world.WorldClientLocal)1 WorldClientRemote (io.xol.chunkstories.world.WorldClientRemote)1 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)1