Иконка ресурса

FREE StaffList : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using Newtonsoft.Json;
using Oxide.Core.Libraries.Covalence;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Oxide.Plugins
{
    [Info("StaffList", "Reheight", "1.0.0")]
    [Description("Show the currently active staff on your server.")]
    class StaffList : CovalencePlugin
    {
        private List<BasePlayer> ActiveStaffDirectory = Facepunch.Pool.GetList<BasePlayer>();
        private string StaffListString;

        PluginConfig _config;

        private void Init()
        {
            _config = Config.ReadObject<PluginConfig>();
        }

        private void Unload()
        {
            Facepunch.Pool.FreeList(ref ActiveStaffDirectory);
        }

        protected override void LoadDefaultConfig() => _config = GetDefaultConfig();

        protected override void LoadConfig()
        {
            base.LoadConfig();

            try
            {
                _config = Config.ReadObject<PluginConfig>();

                if (_config == null)
                {
                    throw new JsonException();
                }

                if (!_config.ToDictionary().Keys.SequenceEqual(Config.ToDictionary(x => x.Key, x => x.Value).Keys))
                {
                    PrintWarning($"PluginConfig file {Name}.json updated.");

                    SaveConfig();
                }
            }
            catch
            {
                LoadDefaultConfig();

                PrintError("Config file contains an error and has been replaced with the default file.");
            }

        }

        protected override void SaveConfig() => Config.WriteObject(_config, true);

        private class PluginConfig
        {
            [JsonProperty(PropertyName = "Commands", Order = 0)]
            public string[] CommandList { get; set; }

            [JsonProperty(PropertyName = "Permission Required", Order = 1)]
            public bool PermissionRequired { get; set; }

            [JsonProperty(PropertyName = "Permission", Order = 2)]
            public string UsePermission { get; set; }

            [JsonProperty(PropertyName = "Staff Ranks", Order = 3)]
            public List<string> StaffRanks { get; set; }

            [JsonProperty(PropertyName = "Prefix", Order = 4)]
            public string Prefix { get; set; }

            public string ToJson() => JsonConvert.SerializeObject(this);

            public Dictionary<string, object> ToDictionary() => JsonConvert.DeserializeObject<Dictionary<string, object>>(ToJson());
        }

        private PluginConfig GetDefaultConfig()
        {
            return new PluginConfig
            {
                CommandList = new string[]
                {
                    "staff",
                    "stafflist",
                    "staffonline",
                    "activestaff",
                    "as",
                    "sl"
                },

                PermissionRequired = true,

                UsePermission = "stafflist.use",

                StaffRanks = new List<string>()
                {
                    "owner",
                    "administrator",
                    "moderator"
                },

                Prefix = "<color=#42f566>StaffList:</color>"
            };
        }

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["NoPermission"] = "<size=12><color=#b6bab7>You do not have permission to do this!</color></size>",
                ["StaffList"] = "<size=12><color=#b6bab7>You are viewing a list of the active staff!\n\n{0}</color></size>",
                ["StaffIndividual"] = "<color=#61ff7e>{0}</color>",
                ["StaffSeparator"] = "<color=#b6bab7>, </color>"
            }, this);
        }

        private string Lang(string key, string pid, params object[] args) => _config.Prefix + " " + String.Format(lang.GetMessage(key, this, pid), args);
        private string LangNoPFX(string key, string pid, params object[] args) => String.Format(lang.GetMessage(key, this, pid), args);

        private void OnServerInitialized()
        {
            AddCovalenceCommand(_config.CommandList, nameof(StaffListCommand));
            permission.RegisterPermission(_config.UsePermission, this);

            foreach (IPlayer iPlayer in players.Connected)
            {
                BasePlayer player = iPlayer.Object as BasePlayer;

                ProcessPlayer(player);
            }
        }

        private void StaffListCommand(IPlayer player, string command, string[] args)
        {
            if (_config.PermissionRequired && !permission.UserHasPermission(player.Id, _config.UsePermission))
            {
                player.Reply(Lang("NoPermission", player.Id));
                return;
            }

            player.Reply(Lang("StaffList", player.Id, StaffListString));
        }

        private string GenerateStaffListString()
        {
            StringBuilder builder = new StringBuilder();

            int index = 0;
            foreach (BasePlayer player in ActiveStaffDirectory)
            {
                if (index + 1 != ActiveStaffDirectory.Count()) builder.Append($"{LangNoPFX("StaffIndividual", player.UserIDString, player.displayName)}{LangNoPFX("StaffSeparator", player.UserIDString)}");
                else builder.Append(LangNoPFX("StaffIndividual", player.UserIDString, player.displayName));

                index++;
            }

            return builder.ToString();
        }

        void OnPlayerConnected(BasePlayer player)
        {
            ProcessPlayer(player);
        }

        void OnPlayerDisconnected(BasePlayer player)
        {
            if (player == null) return;

            if (!ActiveStaffDirectory.Contains(player)) return;
            else ActiveStaffDirectory.Remove(player);
        }

        private void ProcessPlayer(BasePlayer player)
        {
            if (player == null) return;

            foreach (string group in permission.GetUserGroups(player.UserIDString))
            {
                if (ActiveStaffDirectory.Contains<BasePlayer>(player)) break;
                if (!_config.StaffRanks.Contains<string>(group)) continue;

                ActiveStaffDirectory.Add(player);
            }

            StaffListString = GenerateStaffListString();
        }
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху