public static void LoadScript(Sender sender, string file)
 {
     if (sender is Player)
     {
         if (sender.isOp())
         {
             if (file.Length > 1 && file != null && file.Trim().Length > 0)
             {
                 try
                 {
                     _manager.DoFile(file);
                     sender.sendMessage("Lua script loaded.");
                     _initialised = true;
                 }
                 catch
                 {
                     sender.sendMessage("Loading lua script failed.");
                     _initialised = false;
                 }
             }
             else
             {
                 sender.sendMessage("Lua script not found");
                 _initialised = false;
             }
         }
         else
         {
             sender.sendMessage("You Cannot Perform That Action.", 255, 238f, 130f, 238f);
         }
     }
 }
        /// <summary>
        /// Parses new console command
        /// </summary>
        /// <param name="Line">Command to parse</param>
        /// <param name="server">Current Server instance</param>
        public void parseConsoleCommand(String Line, Server server)
        {
            ConsoleSender cSender = new ConsoleSender(server);
            cSender.ConsoleCommand.Message = Line;
            Sender sender = new Sender();
            sender.Op = true;
            cSender.ConsoleCommand.Sender = sender;
            server.PluginManager.processHook(Hooks.CONSOLE_COMMAND, cSender.ConsoleCommand);
            if (cSender.ConsoleCommand.Cancelled)
            {
                return;
            }

            if (Line.Contains("\""))
            {
                String[] commands = new String[Line.Substring(0, Line.IndexOf("\"")).Split(' ').Length + Line.Substring(Line.LastIndexOf("\"")).Split(' ').Length - 1];
                String[] temp = Line.Substring(0, Line.IndexOf("\"")).Trim().Split(' ');
                String[] temp2 = Line.Substring(Line.LastIndexOf("\"") + 1).Trim().Split(' ');
                String[] temp3 = new String[temp.Length + 1];
                temp.CopyTo(temp3, 0);

                temp3[temp3.Length - 1] = Line.Substring(Line.IndexOf("\""), Line.LastIndexOf("\"") - Line.IndexOf("\"")).Remove(0,1);

                temp3.CopyTo(commands, 0);
                temp2.CopyTo(commands, temp3.Length);

                if (commands == null || commands.Length <= 0)
                {
                    Program.tConsole.WriteLine("Issue parsing Console Command for " + Hooks.CONSOLE_COMMAND.ToString());
                    return;
                }
                switchCommands(commands, cSender.ConsoleCommand.Sender);

            }
            else
            {
                String[] commands = Line.Trim().ToLower().Split(' ');

                if (commands == null || commands.Length <= 0)
                {
                    Program.tConsole.WriteLine("Issue parsing Console Command for " + Hooks.CONSOLE_COMMAND.ToString());
                    return;
                }
                switchCommands(commands, cSender.ConsoleCommand.Sender);
            }
        }
 public void setSender(Sender Sender)
 {
     messageSender = Sender;
 }
        public static void BanList(Sender sender, string[] commands)
        {
            // /ban  <player>
            // /unban <player>

            if (sender is Player)
            {
                Player player = ((Player)sender);
                if (!player.isOp())
                {
                    NetMessage.SendData(25, player.whoAmi, -1, "You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                    return;
                }
            }

            if (commands != null && commands.Length > 1)
            {
                if (commands[0] != null && commands[1].Length > 0)
                {
                    int caseType = -1;

                    if (commands[0].Trim().ToLower().Equals("ban"))
                    {
                        caseType = 0;
                    }
                    else if (commands[0].Trim().ToLower().Equals("unban"))
                    {
                        caseType = 1;
                    }

                    switch (caseType)
                    {
                        case 0:
                            {
                                Program.server.getBanList().addException(commands[1]);

                                //We now should check to make sure they are off the server...
                                Player banee = Program.server.GetPlayerByName(commands[1]);

                                if (banee == null)
                                {
                                    foreach (Player player in Program.server.getPlayerList())
                                    {
                                        if (NetPlay.serverSock[player.whoAmi].tcpClient.Client.RemoteEndPoint.ToString()
                                            .Split(':')[0].Equals(commands[1]))
                                        {
                                            banee = player;
                                        }
                                    }
                                }

                                if (banee != null)
                                {
                                    banee.Kick("You have been banned from this Server.");
                                }
                                break;
                            }
                        case 1:
                            {
                                Program.server.getBanList().removeException(commands[1]);
                                break;
                            }
                        default:
                            {
                                goto ERROR;
                            }

                    }

                    string Message = sender.getName() + " used Ban command case " + caseType + " for: " + commands[1];
                    Program.server.notifyOps(Message);
                    sender.sendMessage(Message);

                    if (!Program.server.getWhiteList().Save())
                    {
                        Program.server.notifyOps("BanList Failed to Save due to " + sender.getName() + "'s command");
                    }
                    return;
                }
            }
            ERROR:
            sender.sendMessage("Command Error!");
        }
        public static void WhiteList(Sender sender, string[] commands)
        {
            // /whitelist <add:remove> <player>
            // arg  0         1           2
            if (sender is Player)
            {
                Player player = ((Player)sender);
                if (!player.isOp())
                {
                    NetMessage.SendData(25, player.whoAmi, -1, "You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                    return;
                }
            }

            if (commands != null && commands.Length > 2)
            {
                if (commands[1] != null && commands[2] != null && commands[1].Length > 0 && commands[2].Length > 0)
                {
                    string caseType = "ADD";

                    switch (commands[1].Trim().ToUpper())
                    {
                        case "ADD":
                            {
                                Program.server.getWhiteList().addException(commands[2]);
                                break;
                            }
                        case "REMOVE":
                            {
                                Program.server.getWhiteList().removeException(commands[2]);
                                caseType = "REMOVE";
                                break;
                            }
                        default:
                            {
                                goto ERROR;
                            }

                    }

                    string Message = sender.getName() + " used WhiteList command " + caseType + " for: " + commands[2];
                    Program.server.notifyOps(Message);
                    sender.sendMessage(Message);

                    if (!Program.server.getWhiteList().Save())
                    {
                        Program.server.notifyOps("WhiteList Failed to Save due to " + sender.getName() + "'s command");
                    }
                    return;
                }
            }
            ERROR:
            sender.sendMessage("Command args Error!");
        }
 public static void ShowHelp(Sender sender)
 {
     if (sender is Player)
     {
         for (int i = 0; i < CommandDefinition.Length; i++)
         {
             ((Player)sender).sendMessage(CommandDefinition[i] + " - " + CommandInformation[i]);
         }
     }
     else
     {
         for (int i = 0; i < CommandDefinition.Length; i++)
         {
             Console.WriteLine("\t" + CommandDefinition[i] + " - " + CommandInformation[i]);
         }
     }
 }
 public static void ReloadScript(Sender sender)
 {
     if (sender is Player)
     {
         if (sender.isOp())
         {
             try
             {
                 _manager.DoFile(_filename);
                 sender.sendMessage("Reloaded current lua script.");
                 _initialised = true;
             }
             catch
             {
                 sender.sendMessage("Failed to reload current lua script.");
                 _initialised = false;
             }
         }
     }
     else
     {
         sender.sendMessage("You Cannot Perform That Action.", 255, 238f, 130f, 238f);
     }
 }
        public void switchCommands(string[] commands, Sender sender)
        {
            switch (Commands.getCommandValue(commands[0]))
            {
                case (int)Commands.Command.NO_SUCH_COMMAND:
                    {
                        Console.WriteLine("No such command!");
                        break;
                    }
                case (int)Commands.Command.CONSOLE_EXIT:
                    {
                        if (sender is Player)
                        {
                            Player player = (Player)sender;
                            if (!player.isOp())
                            {
                                NetMessage.SendData(25, player.whoAmi, -1, "You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                                return;
                            }
                        }

                        Program.server.notifyOps("Stopping Server...");
                        Console.WriteLine("Stopping Server...");
                        Commands.Exit(sender.getServer());
                        break;
                    }
                case (int)Commands.Command.COMMAND_RELOAD:
                    {
                        if (sender is Player)
                        {
                            Player player = (Player)sender;
                            if (!player.isOp())
                            {
                                NetMessage.SendData(25, player.whoAmi, -1, "You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                                return;
                            }
                        }

                        Program.server.notifyOps("Reloading Plugins.");
                        Console.WriteLine("Reloading Plugins.");
                        Commands.Reload(sender.getServer());
                        break;
                    }
                case (int)Commands.Command.COMMAND_LIST:
                    {
                        if (sender is Player)
                        {
                            Commands.List(((Player)sender).whoAmi);
                        }
                        else
                        {
                            Console.WriteLine(Commands.List(0, false));
                        }
                        break;
                    }
                case (int)Commands.Command.COMMAND_PLAYERS:
                    {
                        //same stuff, Just making it easier.
                        goto case (int)Commands.Command.COMMAND_LIST;
                    }
                case (int)Commands.Command.PLAYER_ME:
                    {
                        string Message = Program.mergeStrArray(commands);
                        if (sender is Player)
                        {
                            Commands.Me_Say(Message.Remove(0, 3).Trim(), ((Player)sender).whoAmi);
                        }
                        else
                        {
                            Commands.Me_Say(Message.Remove(0, 4).Trim(), -1); //turn command list into a string and remove "say "
                        }
                        break;
                    }
                case (int)Commands.Command.CONSOLE_SAY:
                    {
                        goto case (int)Commands.Command.PLAYER_ME;
                    }
                case (int)Commands.Command.COMMAND_SAVE_ALL:
                    {
                        if (sender is Player)
                        {
                            Player player = (Player)sender;
                            if (!player.isOp())
                            {
                                NetMessage.SendData(25, player.whoAmi, -1, "You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                                return;
                            }
                        }
                        Commands.SaveAll();
                        break;
                    }
                /*case (int)Commands.Command.COMMAND_ALLOW_GOD_MODE:
                    {
                        if (sender is Player)
                        {
                            Player player = (Player)sender;
                            if (!player.isOp())
                            {
                                NetMessage.SendData(25, player.whoAmi, -1, "You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                                return;
                            }
                        }
                        Program.server.setGodMode(!Program.server.getGodMode());
                        Program.server.notifyAll("God Mode is now " + Program.server.getGodMode().ToString());
                        Program.server.notifyOps("Gode Mod Toggled by " + sender.getName());
                        Console.WriteLine(sender.getName() + " toggled God Mode to: " + Program.server.getGodMode().ToString());
                        break;
                    }*/
                case (int)Commands.Command.COMMAND_HELP:
                    {
                        Commands.ShowHelp(sender);
                        break;
                    }
                case (int)Commands.Command.COMMAND_WHITELIST:
                    {
                        Commands.WhiteList(sender, commands);
                        break;
                    }
                case (int)Commands.Command.COMMAND_BAN:
                    {
                        Commands.BanList(sender, commands);
                        break;
                    }
                case (int)Commands.Command.COMMAND_UNBAN:
                    {
                        Commands.BanList(sender, commands);
                        break;
                    }
                default:
                    {
                        Console.WriteLine("Uknown Command Issued.");
                        break;
                    }

            }
        }
        public void switchCommands(string[] commands, Sender sender)
        {
            switch (Commands.getCommandValue(commands[0]))
            {
                case (int)Commands.Command.NO_SUCH_COMMAND:
                    {
                        Program.tConsole.WriteLine("No such command!");
                        return;
                    }
                case (int)Commands.Command.CONSOLE_EXIT:
                    {
                        if (sender is Player)
                        {
                            Player player = (Player)sender;
                            if (!player.Op)
                            {
                                NetMessage.SendData((int)Packet.PLAYER_CHAT, player.whoAmi, -1, "You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                                return;
                            }
                        }

                        Program.server.notifyOps("Stopping Server...");
                        Commands.Exit(sender.getServer());
                        break;
                    }
                case (int)Commands.Command.COMMAND_RELOAD:
                    {
                        if (sender is Player)
                        {
                            Player player = (Player)sender;
                            if (!player.Op)
                            {
                                NetMessage.SendData((int)Packet.PLAYER_CHAT, player.whoAmi, -1, "You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                                return;
                            }
                        }

                        Program.server.notifyOps("Reloading Plugins.");
                        Commands.Reload(sender.getServer());
                        break;
                    }
                case (int)Commands.Command.COMMAND_PLAYERS:
                case (int)Commands.Command.COMMAND_LIST:
                    {
                        if (sender is Player)
                        {
                            Commands.List(((Player)sender).whoAmi);
                        }
                        else
                        {
                            Program.tConsole.WriteLine(Commands.List(0, false));
                        }
                        break;
                    }
                case (int)Commands.Command.CONSOLE_SAY:
                case (int)Commands.Command.PLAYER_ME:
                    {
                        string Message = Commands.MergeStringArray(commands);
                        if (Message.Length <= 3) { return; }

                        if (sender is Player)
                        {
                            Commands.Me_Say(Message.Remove(0, 3).Trim(), ((Player)sender).whoAmi);
                        }
                        else
                        {
                            Commands.Me_Say(Message.Remove(0, 4).Trim(), -1); //turn command list into a string and remove "say "
                        }
                        break;
                    }
                case (int)Commands.Command.COMMAND_SAVE_ALL:
                    {
                        if (sender is Player)
                        {
                            Player player = (Player)sender;
                            if (!player.Op)
                            {
                                NetMessage.SendData((int)Packet.PLAYER_CHAT, player.whoAmi, -1, "You Cannot Perform That Action.", 255, 238f, 130f, 238f);
                                return;
                            }
                        }
                        Commands.SaveAll();
                        break;
                    }
                case (int)Commands.Command.COMMAND_HELP:
                    {
                        if (commands.Length > 1)
                        {
                            Commands.ShowHelp(sender, commands);
                        }
                        else
                        {
                            Commands.ShowHelp(sender);
                        }
                        break;
                    }
                case (int)Commands.Command.COMMAND_WHITELIST:
                    {
                        Commands.WhiteList(sender, commands);
                        break;
                    }
                case (int)Commands.Command.COMMAND_BAN:
                    {
                        Commands.BanList(sender, commands);
                        break;
                    }
                case (int)Commands.Command.COMMAND_UNBAN:
                    {
                        Commands.BanList(sender, commands);
                        break;
                    }
                case (int)Commands.Command.COMMAND_TIME:
                    {
                        Commands.Time(sender, commands);
                        break;
                    }
                case (int)Commands.Command.COMMAND_GIVE:
                    {
                        Commands.Give(sender, commands);
                        break;
                    }
                case (int)Commands.Command.PLAYER_SPAWNNPC:
                    {
                        Commands.SpawnNPC(sender, commands);
                        break;
                    }
                case (int)Commands.Command.COMMAND_TELEPORT:
                    {
                        Commands.Teleport(sender, commands);
                        break;
                    }
                case (int)Commands.Command.PLAYER_TPHERE:
                    {
                        Commands.TeleportHere(sender, commands);
                        break;
                    }
                case (int)Commands.Command.COMMAND_SETTLEWATER:
                    {
                        Commands.SettleWater(sender);
                        break;
                    }
                case (int)Commands.Command.COMMAND_OP:
                    {
                        Commands.OP(sender, commands);
                        break;
                    }
                case (int)Commands.Command.COMMAND_DEOP:
                    {
                        Commands.OP(sender, commands, true);
                        break;
                    }
                case (int)Commands.Command.PLAYER_OPLOGIN:
                    {
                        Commands.OPLoginOut(sender, commands);
                        break;
                    }
                case (int)Commands.Command.PLAYER_OPLOGOUT:
                    {
                        Commands.OPLoginOut(sender, commands, true);
                        break;
                    }
                case (int)Commands.Command.COMMAND_NPCSPAWN:
                    {
                        Commands.NPCSpawns(sender);
                        break;
                    }
                case (int)Commands.Command.COMMAND_KICK:
                    {
                        Commands.Kick(sender, commands);
                        break;
                    }
                case (int)Commands.Command.COMMAND_RESTART:
                    {
                        Commands.Restart(sender, server);
                        break;
                    }
                default:
                    {
                        Program.tConsole.WriteLine("Uknown Command Issued.");
                        break;
                    }
            }
        }