Beispiel #1
0
        public void UpdateBlacklist()
        {
            var blacklist  = MyScriptCompiler.Static.Whitelist.OpenIngameBlacklistBatch();
            var types      = new MyConcurrentHashSet <Type>();
            var memberDict = new MyConcurrentDictionary <Type, List <string> >();

            Parallel.ForEach(PluginSettings.Instance.BlacklistItems, item =>
            {
                if (string.IsNullOrEmpty(item.Type))
                {
                    return;
                }

                var targetType = FindTypeInAllAssemblies(item.Type);
                if (targetType == null)
                {
                    return;
                }

                if (string.IsNullOrEmpty(item.Member))
                {
                    lock (types)
                        types.Add(targetType);
                }

                var members = targetType.GetMember(item.Member);
                if (members.Length != 0)
                {
                    if (!memberDict.ContainsKey(targetType))
                    {
                        memberDict.Add(targetType, new List <string>());
                    }
                    memberDict[targetType].Add(item.Member);
                }
            });

            if (types.Count > 0)
            {
                blacklist.AddTypes(types.ToArray());
                foreach (var type in types)
                {
                    Essentials.Log.Info($"Added type {type.Name} to PB blacklist.");
                }
            }
            foreach (var entry in memberDict)
            {
                blacklist.AddMembers(entry.Key, entry.Value.ToArray());
                foreach (var name in entry.Value)
                {
                    Essentials.Log.Info($"Added {entry.Key.Name}.{name} to PB blacklist.");
                }
            }
        }