package me.justramon.ircbot.raqbotx.commands;

import me.justramon.ircbot.raqbotx.config.ConfigHandler;
import me.justramon.ircbot.raqbotx.core.ICommand;
import me.justramon.ircbot.raqbotx.util.MessageHandler;
import me.justramon.ircbot.raqbotx.util.StringUtils;
import org.pircbotx.hooks.events.MessageEvent;

public class Operator implements ICommand<MessageEvent> {

    @Override
    public void exe(MessageEvent event, String[] args) throws Exception {
        if (args.length == 0) {
            MessageHandler.respond(event, "Please give a first argument, valid options are [List/Add/Remove]");
            return;
        }

        if (args.length < 2) {
            MessageHandler.respond(event, "Please give a username too!");
            return;
        }

        String cmd = args[0].toLowerCase();
        switch (cmd) {
            case "list":
                MessageHandler.respond(event, "[" + StringUtils.listToString(ConfigHandler.config.operators) + "]");
                break;

            case "add":
                for (int i = 1; i < args.length; i++) {
                    if (args[i].isEmpty())
                        continue;

                    ConfigHandler.config.operators.add(args[i]);
                }

                ConfigHandler.save();
                String addedPeople = StringUtils.arrayToString(StringUtils.trimArgrumentsFromCommand(args));
                MessageHandler.respond(event, "Added [" + addedPeople + "]");
                break;

            case "remove":
                for (int i = 1; i < args.length; i++) {
                    if (args[i].isEmpty())
                        continue;

                    ConfigHandler.config.operators.remove(args[i]);
                }

                ConfigHandler.save();

                String removedPeople = StringUtils.arrayToString(StringUtils.trimArgrumentsFromCommand(args));
                MessageHandler.respond(event, "Removed [" + removedPeople + "]");
                break;

            default:
                MessageHandler.respond(event, "Not a valid first argument, valid options are [List/Add/Remove]");
        }
    }

    @Override
    public String[] getAliases() {
        return new String[]{"operator"};
    }

    @Override
    public String getInfo() {
        return "List/Add/Remove bot operators";
    }

    @Override
    public String getUsage() {
        return "?<command> <list/add/remove> <nickname> [nickname ...]";
    }

    @Override
    public boolean xtraFunc() {
        return false;
    }

    @Override
    public boolean isOperatorCommand() {
        return true;
    }
}

@@ -630,143 +630,8 @@
  %7D%0A%0A
-        if (args.length %3C 2) %7B%0A            MessageHandler.respond(event, %22Please give a username too!%22);%0A            return;%0A        %7D%0A
 %0A   
@@ -884,16 +884,184 @@
  %22add%22:%0A
+                if (args.length %3C 2) %7B%0A                    MessageHandler.respond(event, %22Please give a username too!%22);%0A                    return;%0A                %7D%0A%0A
         
@@ -1511,32 +1511,32 @@
         break;%0A%0A
-
             case
@@ -1546,16 +1546,184 @@
 emove%22:%0A
+                if (args.length %3C 2) %7B%0A                    MessageHandler.respond(event, %22Please give a username too!%22);%0A                    return;%0A                %7D%0A%0A
         

Fix arguments length check