Exemplo n.º 1
0
        public static bool DeleteRank(Rank deletedRank, Rank replacementRank)
        {
            if (deletedRank == null)
            {
                throw new ArgumentNullException("deletedRank");
            }
            if (replacementRank == null)
            {
                throw new ArgumentNullException("replacementRank");
            }
            if (PlayerDB.IsLoaded)
            {
                throw new InvalidOperationException("You may not add ranks after PlayerDB has already been loaded.");
            }
            bool rankLimitsChanged = false;

            Ranks.Remove(deletedRank);
            RanksByName.Remove(deletedRank.Name.ToLower());
            RanksByID.Remove(deletedRank.ID);
            RanksByFullName.Remove(deletedRank.GetFullName());
            LegacyRankMapping.Add(deletedRank.ID, replacementRank.ID);
            foreach (Rank rank in Ranks)
            {
                for (int i = 0; i < rank.PermissionLimits.Length; i++)
                {
                    if (rank.GetLimit((Permission)i) == deletedRank)
                    {
                        rank.ResetLimit((Permission)i);
                        rankLimitsChanged = true;
                    }
                }
            }
            RebuildIndex();
            return(rankLimitsChanged);
        }
Exemplo n.º 2
0
        /// <summary> Removes the specified rank from the list of available ranks </summary>
        /// <param name="deletedRank"> Rank to be deleted. </param>
        /// <param name="replacementRank"> Rank that will replace the deleted rank. </param>
        /// <returns> Whether or not the rank was succesfully deleted/replaced. </returns>
        /// <exception cref="ArgumentNullException"> If deletedRank or replacementRank is null. </exception>
        /// <exception cref="InvalidOperationException"> If PlayerDB is already loaded. </exception>
        public static bool DeleteRank([NotNull] Rank deletedRank, [NotNull] Rank replacementRank)
        {
            if (deletedRank == null)
            {
                throw new ArgumentNullException("deletedRank");
            }
            if (replacementRank == null)
            {
                throw new ArgumentNullException("replacementRank");
            }
            CheckIfPlayerDBLoaded();

            bool rankLimitsChanged = false;

            Ranks.Remove(deletedRank);
            RanksByName.Remove(deletedRank.Name.ToLower());
            RanksByID.Remove(deletedRank.ID);
            RanksByFullName.Remove(deletedRank.FullName);
            LegacyRankMapping.Add(deletedRank.ID, replacementRank.ID);
            foreach (Rank rank in Ranks)
            {
                for (int i = 0; i < rank.PermissionLimits.Length; i++)
                {
                    if (rank.GetLimit((Permission)i) == deletedRank)
                    {
                        rank.ResetLimit((Permission)i);
                        rankLimitsChanged = true;
                    }
                }
            }
            RebuildIndex();
            return(rankLimitsChanged);
        }