public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/(pa|protectionarea)\s+(?<CommandParts>.*)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var commandParts = match.Groups["CommandParts"].Value.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (commandParts.Length < 1)
                {
                    MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Not enough parameters.");
                    Help(steamId, true);
                    return(true);
                }

                var action = commandParts[0];

                switch (action.ToLowerInvariant())
                {
                case "add":
                {
                    if (commandParts.Length == 7)
                    {
                        string name   = commandParts[1];
                        string xS     = commandParts[2];
                        string yS     = commandParts[3];
                        string zS     = commandParts[4];
                        string sizeS  = commandParts[5];
                        string shapeS = commandParts[6];

                        double x, y, z, size;
                        ProtectionAreaShape shape;

                        if (!double.TryParse(xS, out x))
                        {
                            MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Cannot parse x.");
                            return(true);
                        }

                        if (!double.TryParse(yS, out y))
                        {
                            MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Cannot parse y.");
                            return(true);
                        }

                        if (!double.TryParse(zS, out z))
                        {
                            MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Cannot parse z.");
                            return(true);
                        }

                        if (!double.TryParse(sizeS, out size))
                        {
                            MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Cannot parse size.");
                            return(true);
                        }

                        if (!TryParseShape(shapeS, out shape))
                        {
                            MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                                                               "Cannot parse shape. Shapes: cube, cubic, sphere, spherical");
                            // TODO display help
                            return(true);
                        }

                        ProtectionArea area    = new ProtectionArea(name, new Vector3D(x, y, z), size, shape);
                        var            message = new MessageProtectionArea()
                        {
                            ProtectionArea = area,
                            Type           = ProtectionAreaMessageType.Add
                        };
                        ConnectionHelper.SendMessageToServer(message);
                        return(true);
                    }

                    MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                                                       "Wrong parameters. /protectionarea add <name> <x> <y> <z> <size> <shape>");
                    break;
                }

                case "remove":
                {
                    if (commandParts.Length == 2)
                    {
                        string         name    = commandParts[1];
                        ProtectionArea area    = new ProtectionArea(name, new Vector3D(), 0, ProtectionAreaShape.Cube);
                        var            message = new MessageProtectionArea()
                        {
                            ProtectionArea = area,
                            Type           = ProtectionAreaMessageType.Remove
                        };
                        ConnectionHelper.SendMessageToServer(message);
                        return(true);
                    }

                    MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                                                       "Wrong parameters. /protectionarea remove <name>");
                    break;
                }

                case "list":
                {
                    if (ProtectionHandler.Config == null || ProtectionHandler.Config.Areas == null)
                    {
                        MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                                                           "Areas not loaded yet. Please try again later.");
                        ConnectionHelper.SendMessageToServer(new MessageSyncProtection());
                        return(true);
                    }

                    StringBuilder areaList = new StringBuilder();
                    int           index    = 1;

                    foreach (ProtectionArea protectionArea in ProtectionHandler.Config.Areas)
                    {
                        areaList.AppendLine(String.Format("#{0}, {1}:", index++, protectionArea.Name));
                        areaList.AppendLine(String.Format("X: {0:#0.0##}, Y: {1:#0.0##}, Z: {2:#0.0##}",
                                                          protectionArea.Center.X, protectionArea.Center.Y, protectionArea.Center.Z));
                        areaList.AppendLine(String.Format("Size: {0}, Shape: {1}", protectionArea.Size,
                                                          protectionArea.Shape == ProtectionAreaShape.Cube ? "cube" : "sphere"));
                        areaList.AppendLine("");
                    }

                    MyAPIGateway.Utilities.ShowMissionScreen("Protection Areas",
                                                             String.Format("Count: {0}", ProtectionHandler.Config.Areas.Count), null, areaList.ToString());
                    break;
                }

                case "config":
                case "cfg":
                {
                    if (commandParts.Length != 3)
                    {
                        MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                                                           "Wrong parameters. /protectionarea cfg <setting> <value>");
                        return(true);
                    }

                    var setting = commandParts[1].ToLowerInvariant();

                    bool value;
                    if (!bool.TryParse(commandParts[2], out value))
                    {
                        MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Cannot parse value. It must be either true or false.");
                        return(true);
                    }

                    var message = new MessageProtectionConfig()
                    {
                        Value = value
                    };

                    switch (setting)
                    {
                    case "invert":
                        message.Type = ProtectionConfigType.Invert;
                        break;

                    case "enable":
                        message.Type = ProtectionConfigType.Enable;
                        break;

                    default:
                        MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                                                           String.Format("{0} is no valid setting. Actions: invert, enable", setting));
                        return(true);
                    }

                    ConnectionHelper.SendMessageToServer(message);
                    break;
                }

                default:
                    MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                                                       String.Format("{0} is no valid action. Actions: add, remove, list", action));
                    break;
                }
            }
            else
            {
                Help(steamId, true);
            }

            return(true);
        }
        public override bool Invoke(ulong steamId, long playerId, string messageText)
        {
            var match = Regex.Match(messageText, @"/(pa|protectionarea)\s+(?<CommandParts>.*)", RegexOptions.IgnoreCase);

            if (match.Success)
            {
                var commandParts = match.Groups["CommandParts"].Value.Split(new []{ ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (commandParts.Length < 1)
                {
                    MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Not enough parameters.");
                    Help(steamId, true);
                    return true;
                }

                var action = commandParts[0];

                switch (action.ToLowerInvariant())
                {
                    case "add":
                    {
                        if (commandParts.Length == 7)
                        {
                            string name = commandParts[1];
                            string xS = commandParts[2];
                            string yS = commandParts[3];
                            string zS = commandParts[4];
                            string sizeS = commandParts[5];
                            string shapeS = commandParts[6];

                            double x, y, z, size;
                            ProtectionAreaShape shape;

                            if (!double.TryParse(xS, out x))
                            {
                                MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Cannot parse x.");
                                return true;
                            }

                            if (!double.TryParse(yS, out y))
                            {
                                MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Cannot parse y.");
                                return true;
                            }

                            if (!double.TryParse(zS, out z))
                            {
                                MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Cannot parse z.");
                                return true;
                            }

                            if (!double.TryParse(sizeS, out size))
                            {
                                MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Cannot parse size.");
                                return true;
                            }

                            if (!TryParseShape(shapeS, out shape))
                            {
                                MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                                    "Cannot parse shape. Shapes: cube, cubic, sphere, spherical");
                                // TODO display help
                                return true;
                            }

                            ProtectionArea area = new ProtectionArea(name, new Vector3D(x, y, z), size, shape);
                            var message = new MessageProtectionArea()
                            {
                                ProtectionArea = area,
                                Type = ProtectionAreaMessageType.Add
                            };
                            ConnectionHelper.SendMessageToServer(message);
                            return true;
                        }

                        MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                            "Wrong parameters. /protectionarea add <name> <x> <y> <z> <size> <shape>");
                        break;
                    }
                    case "remove":
                    {
                        if (commandParts.Length == 2)
                        {
                            string name = commandParts[1];
                            ProtectionArea area = new ProtectionArea(name, new Vector3D(), 0, ProtectionAreaShape.Cube);
                            var message = new MessageProtectionArea()
                            {
                                ProtectionArea = area,
                                Type = ProtectionAreaMessageType.Remove
                            };
                            ConnectionHelper.SendMessageToServer(message);
                            return true;
                        }

                        MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                            "Wrong parameters. /protectionarea remove <name>");
                        break;
                    }
                    case "list":
                    {
                        if (ProtectionHandler.Config == null || ProtectionHandler.Config.Areas == null)
                        {
                            MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                                "Areas not loaded yet. Please try again later.");
                            ConnectionHelper.SendMessageToServer(new MessageSyncProtection());
                            return true;
                        }

                        StringBuilder areaList = new StringBuilder();
                        int index = 1;

                        foreach (ProtectionArea protectionArea in ProtectionHandler.Config.Areas)
                        {
                            areaList.AppendLine(String.Format("#{0}, {1}:", index++, protectionArea.Name));
                            areaList.AppendLine(String.Format("X: {0:#0.0##}, Y: {1:#0.0##}, Z: {2:#0.0##}",
                                protectionArea.Center.X, protectionArea.Center.Y, protectionArea.Center.Z));
                            areaList.AppendLine(String.Format("Size: {0}, Shape: {1}", protectionArea.Size,
                                protectionArea.Shape == ProtectionAreaShape.Cube ? "cube" : "sphere"));
                            areaList.AppendLine("");
                        }

                        MyAPIGateway.Utilities.ShowMissionScreen("Protection Areas",
                            String.Format("Count: {0}", ProtectionHandler.Config.Areas.Count), null, areaList.ToString());
                        break;
                    }
                    case "config":
                    case "cfg":
                    {
                        if (commandParts.Length != 3)
                        {
                            MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                                "Wrong parameters. /protectionarea cfg <setting> <value>");
                            return true;
                        }

                        var setting = commandParts[1].ToLowerInvariant();

                        bool value;
                        if (!bool.TryParse(commandParts[2], out value))
                        {
                            MyAPIGateway.Utilities.ShowMessage("ProtectionArea", "Cannot parse value. It must be either true or false.");
                            return true;
                        }

                        var message = new MessageProtectionConfig() { Value = value};

                        switch (setting)
                        {
                            case "invert":
                                message.Type = ProtectionConfigType.Invert;
                                break;
                            case "enable":
                                message.Type = ProtectionConfigType.Enable;
                                break;
                            default:
                                MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                                    String.Format("{0} is no valid setting. Actions: invert, enable", setting));
                                return true;
                        }

                        ConnectionHelper.SendMessageToServer(message);
                        break;
                    }
                    default:
                        MyAPIGateway.Utilities.ShowMessage("ProtectionArea",
                            String.Format("{0} is no valid action. Actions: add, remove, list", action));
                        break;
                }
            }
            else
                Help(steamId, true);

            return true;
        }