/// <summary>
        ///     Parse commands from plugin.yml
        /// </summary>
        /// <param name="map"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private static List<PluginCommand> ParseCommands(Mapping map)
        {
            try
            {
                List<PluginCommand> l = new List<PluginCommand>();

                Scalar sc = new Scalar();
                Sequence seq = new Sequence();
                Type typeScalar = sc.GetType();
                Type typeSequence = seq.GetType();
                Type typeMapping = map.GetType();
                if (map.GetType() != typeMapping) return l;

                foreach (MappingEntry entry in map.Enties)
                {
                    PluginCommand pc = new PluginCommand {Name = ((Scalar) entry.Key).Text};

                    if (entry.Value.GetType() == typeMapping)
                    {
                        foreach (MappingEntry secondlevel in ((Mapping) entry.Value).Enties)
                        {
                            if (secondlevel.Key.GetType() != typeScalar) continue;
                            switch (((Scalar) secondlevel.Key).Text)
                            {
                                case "description":
                                    pc.Description = ((Scalar) secondlevel.Value).Text;
                                    break;
                                case "usage":
                                    pc.Usage = ((Scalar) secondlevel.Value).Text;
                                    break;
                                case "alias":
                                    if (entry.Value.GetType() == typeSequence)
                                    {
                                        pc.Aliases = ArrayFromSequence((Sequence) secondlevel.Value);
                                    }
                                    else if (entry.Value.GetType() == typeScalar)
                                    {
                                        pc.Aliases = new string[1];
                                        // ReSharper disable once PossibleInvalidCastException
                                        pc.Aliases[0] = ((Scalar) entry.Value).Text;
                                    }
                                    break;
                                case "aliases":
                                    if (entry.Value.GetType() == typeSequence)
                                    {
                                        pc.Aliases = ArrayFromSequence((Sequence) secondlevel.Value);
                                    }
                                    else if (entry.Value.GetType() == typeScalar)
                                    {
                                        pc.Aliases = new string[1];
            // ReSharper disable once PossibleInvalidCastException
                                        pc.Aliases[0] = ((Scalar) entry.Value).Text;
                                    }
                                    break;
                            }
                        }
                    }

                    l.Add(pc);
                }
                return l;
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Warning, "InstalledPlugin",
                    "An exception occured when trying to load plugin commands", ex.Message);
                return new List<PluginCommand>();
            }
        }
        /// <summary>
        ///     Loads the contents of a plugin.yml file
        /// </summary>
        /// <param name="ymltext">the yml formatted text</param>
        /// <returns>The InstalledPlugin (me)</returns>
        /// <remarks></remarks>
        public InstalledPlugin LoadPluginYml(string ymltext)
        {
            try
            {
                Scalar sc = new Scalar();
                Sequence seq = new Sequence();
                Mapping map = new Mapping();

                //References to check file types later on
                Type typeScalar = sc.GetType();
                Type typeSequence = seq.GetType();
                Type typeMapping = map.GetType();

                if (ymltext == null | string.IsNullOrEmpty(ymltext))
                {
                    return null;
                }

                YamlStream yml = YamlParser.Load(ymltext);

                if (yml == null)
                {
                    return null;
                }

                //if mapping start parsing
                if (yml.Documents[0].Root.GetType() == typeMapping)
                {
                    foreach (MappingEntry item in ((Mapping) yml.Documents[0].Root).Enties)
                    {
                        //Check the type, check for possible keys and load the value
                        if (item.Value.GetType() == typeScalar)
                        {
                            switch (((Scalar) item.Key).Text)
                            {
                                case "name":
                                    Name = ((Scalar) item.Value).Text;
                                    break;
                                case "version":
                                    Version = ((Scalar) item.Value).Text;
                                    break;
                                case "description":
                                    Description = ((Scalar) item.Value).Text;
                                    break;
                                case "main":
                                    Mainspace = ((Scalar) item.Value).Text;
                                    break;
                                case "author":
                                    Authors = new string[1];
                                    Authors[0] = ((Scalar) item.Value).Text;
                                    break;
                                case "authors":
                                    Authors = new string[1];
                                    Authors[0] = ((Scalar) item.Value).Text;
                                    break;
                            }
                        }
                        else if (item.Value.GetType() == typeSequence)
                        {
                            switch (((Scalar) item.Key).Text)
                            {
                                case "author":
                                    Authors = ArrayFromSequence((Sequence) item.Value);
                                    break;
                                case "Authors":
                                    Authors = ArrayFromSequence((Sequence) item.Value);
                                    break;
                                case "softdepend":
                                    Softdepend = ArrayFromSequence((Sequence) item.Value);
                                    break;
                            }
                        }
                        else if (item.Value.GetType() == typeMapping)
                        {
                            switch (((Scalar) item.Key).Text)
                            {
                                case "commands":
                                    if (item.Value.GetType() == typeMapping)
                                        Commands = ParseCommands((Mapping) item.Value);
                                    else
                                        Commands = new List<PluginCommand>();
                                    break;
                                case "permissions":
                                    if (item.Value.GetType() == typeMapping)
                                        Permissions = ParsePermissions((Mapping) item.Value);
                                    else
                                        Permissions = new List<PluginPermission>();
                                    break;
                            }
                        }
                    }
                }
                return this;
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Warning, "InstalledPlugin", "An exception occured when trying to parse yml text",
                    ex.Message);
                return null;
            }
        }