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

FREE MapVoter : 1.3.37 1.3.37

Нет прав для скачивания
C#:
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using Random = System.Random;
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using Oxide.Core.Libraries.Covalence;
using Oxide.Ext.Discord;
using Oxide.Ext.Discord.Attributes;
using Oxide.Ext.Discord.Entities;
using Oxide.Ext.Discord.Entities.Activities;
using Oxide.Ext.Discord.Builders.MessageComponents;
using Oxide.Ext.Discord.Entities.Interactions;
using Oxide.Ext.Discord.Entities.Interactions.ApplicationCommands;
using Oxide.Ext.Discord.Entities.Interactions.MessageComponents;
using Oxide.Ext.Discord.Entities.Emojis;
using Oxide.Ext.Discord.Entities.Channels;
using Oxide.Ext.Discord.Entities.Gatway;
using Oxide.Ext.Discord.Entities.Gatway.Commands;
using Oxide.Ext.Discord.Entities.Gatway.Events;
using Oxide.Ext.Discord.Entities.Guilds;
using Oxide.Ext.Discord.Entities.Messages;
using Oxide.Ext.Discord.Entities.Messages.Embeds;
using Oxide.Ext.Discord.Entities.Users;
using Oxide.Ext.Discord.Entities.Permissions;
using Oxide.Ext.Discord.Extensions;
namespace Oxide.Plugins {
    [Info("MapVoter", "Kaysharp", "1.3.37")]
    class MapVoter : CovalencePlugin {
        [PluginReference]
        Plugin ImageLibrary, WipeInfoApi , ServerRewards, Kits;
#region fields
        [DiscordClient]
        private DiscordClient _client;
        readonly Dictionary<string, Timer> dotimer = new Dictionary<string, Timer>();
        private readonly Random _random = new Random();
        private string permissionUse = "MapVoter.use";
        private string permissionVote = "MapVoter.vote";
        private string PermissionManager = "MapVoter.Manager";
        public static ConfigData config {
            get;
            set;
        }
        public static ConfigData configTEMP {
            get;
            set;
        }
        private List<uint> Generating = new List<uint>();
        private List<RustMaps> Maps = new List<RustMaps>();
        private List<RustMaps> MVData = new List<RustMaps>();
        private AutoWipeConfig WipeData;
        private List<RustMaps> FiltredMaps = new List<RustMaps>();
        private List<Result> FMaps = new List<Result>();
        filteredMaps fMaps = new filteredMaps();
        private Dictionary<uint, int> VoteResult = new Dictionary<uint, int>();
        private VoteData voteData;
        private List<string> Voted = new List<string>();
        private List<CustomMap> CustomMaps = new List<CustomMap>();
        private string _stopvote , nbMaps, size, CMapSize, isOnlyAuth, StopVotingafter, AutoVoting , enableautowipe, _nbMap, _isCustomMap, bpswipe, _MapWipeSchedule, _FullWipeSchedule= String.Empty;
        private bool VoteStarted = false;
        private int RustMapsPage = 0;
        private string filterId = string.Empty;
        private DateTime CurrentDate;
        private bool IsFullWipe = false;
        private bool ForcedWipe = false;
        private bool IsRestarting, WipeCanceled, VotingCanceled = false;
        private bool IsWipeDay = false;
        private string MagnifyIconURL = "https://chaoscode.io/oxide/Images/magnifyingglass.png";
        private const string VoteButtonId = nameof(MapVoter) + "_Vote";
        private const string VoteButtonIcon = "📩";
        private bool LogToDiscord = false;
        private bool isCustomMaps = false;
        private bool isFunKitEnabled = false;
#if SIMULATE_OXIDE_PATCH
        static readonly VersionNumber CurrentOxideRustVersion = new VersionNumber(0, 0, 0);
#else
        static readonly VersionNumber CurrentOxideRustVersion = Interface.Oxide.GetAllExtensions().First(e => e.Name == "Rust").Version;
#endif
        private int? _channelCount;
        private Timer StatusTimer = null;
        private UpdatePresenceCommand DiscordPresence = new UpdatePresenceCommand {
            Activities = new List<DiscordActivity> {
                new DiscordActivity {
                    Type = ActivityType.Game, Name = "Discrod bot Initializing..."
                }
            }
        }
        ;
        private Snowflake _botId;
#endregion
#region Config
        public class ConfigData {
            [JsonProperty(PropertyName = "Commands")]
            public CommandsOptions Commands = new CommandsOptions();
            [JsonProperty(PropertyName = "Rewards")]
            public Rewards rewards = new Rewards();
            [JsonProperty(PropertyName = "Fun Kit")]
            public FunKit funKit = new FunKit();
            [JsonProperty(PropertyName = "Options")]
            public Options Settings = new Options();
            [JsonProperty(PropertyName = "Discord Settings")]
            public DiscordSettings _DiscordSettings = new DiscordSettings();
            [JsonProperty(PropertyName = "Auto Vote")]
            public MVAutoVote AutoVote = new MVAutoVote();
            [JsonProperty(PropertyName = "Auto Wipe")]
            public AutoWipe _AutoWipe = new AutoWipe();
            public class CommandsOptions {
                [JsonProperty(PropertyName = "Open MapVoter UI")]
                public string mapvote {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Generate Mpas")]
                public string Generate {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "vote result")]
                public string voteresult {
                    get;
                    set;
                }
            }
            public class Rewards {
                [JsonProperty(PropertyName = "Rust rewards")]
                public bool RustRewards {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "reward points")]
                public int RWPoints {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Kits")]
                public bool Kits {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Kit name")]
                public string KitName {
                    get;
                    set;
                }
            }
            public class FunKit {
                [JsonProperty(PropertyName = "Fun kit enabled")]
                public bool enabled {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Enable Fun kit x minutes before wipe")]
                public int KitStartTime {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Kit name")]
                public string KitName {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Permission")]
                public string Perm {
                    get;
                    set;
                }
            }
            public class Options {
                [JsonProperty(PropertyName = "Select random maps from rustmaps filter id instead of generating random maps on wipe day (true/false)")]
                public bool isRandomMapsFromfilterID {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "How many pages the plugin looks up per search request(every page has 30 maps")]
                public int MaxPages {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Enable Discord bot (true/false)")]
                public bool isDiscordBot {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Only players with permission MapVoter.Vote can vote (true/false)")]
                public bool isOnlyPlayersWithPermCanVote {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Log to Discord (true/false)")]
                public bool DiscordLogs {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Discord Logs Channel Id")]
                public string DiscordLogChannelID {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Disable UI")]
                public bool UIisDisabled {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "RustMaps API key")]
                public string APIKey {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Map size")]
                public int size = 3500;
                [JsonProperty(PropertyName = "staging")]
                public bool staging {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "barren")]
                public bool barren {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Stop voting after (minutes)")]
                public int Stopvote {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "avatar url")]
                public string avatar_url {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Discord footer")]
                public string Footer {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "filter Id")]
                public string filterId {
                    get;
                    set;
                }
            }
            public class DiscordSettings {
                [JsonProperty(PropertyName = "Vote Channel id")]
                public string Vote_Channel_id {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Discord Apikey")]
                public string Discord_ApiKey {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Discord Command Prefix")]
                public string Commandprefix {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Discord Channels")]
                public List<DiscordChannel> Channels {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Discord Command Role Assignment (Empty = All roles can use command.)")]
                public Dictionary<string, List<string>> CmdRoles {
                    get;
                    set;
                }
            }
            public class DiscordChannel {
                [JsonProperty(PropertyName = "Discord Channel ID")]
                public Snowflake ChannelId {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Commands")]
                public List<string> Commands {
                    get;
                    set;
                }
            }
            public class MVAutoVote {
                [JsonProperty(PropertyName = "Auto start vote")]
                public bool isAutoVote {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Only Authenticated users can vote through discord")]
                public bool IsOnlyAuthUsers {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Start voting x days before wipe")]
                public int StartVotingDaysBeforewipe {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Start voting at (HH:mm) 24-hour clock")]
                public string StartVotingat {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Number of maps to generate")]
                public int nbm {
                    get;
                    set;
                }
            }
            public class AutoWipe {
                [JsonProperty(PropertyName = "Enable Auto wipe")]
                public bool isAutoWipe {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Custom Map")]
                public CustomMap _CustomMap = new CustomMap();
                [JsonProperty(PropertyName = "Wipe BPs at forced wipe day")]
                public bool WipeBPs {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Forced Wipe time (HH:mm) 24-hour clock")]
                public string ForcedWipeTime {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Wipe time (HH:mm) 24-hour clock")]
                public string WipeTime {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Map Wipe schedule")]
                public List<int> MWschedule = new List<int>();
                [JsonProperty(PropertyName = "BP Wipe schedule")]
                public List<int> FWSchedule = new List<int>();
            }
            public class CustomMap {
                [JsonProperty(PropertyName = "Custom map")]
                public bool isCustomMap {
                    get;
                    set;
                }
                [JsonProperty(PropertyName = "Map URL")]
                public string Url {
                    get;
                    set;
                }
            }
        }
        protected override void LoadConfig() {
            base.LoadConfig();
            try {
                config = Config.ReadObject<ConfigData>();
                Config.WriteObject(config);
                if (config == null) throw new Exception();
            }
            catch {
                Config.WriteObject(config, false, $"{Interface.Oxide.ConfigDirectory}/{Name}.jsonError");
                PrintError("The configuration file contains an error and has been replaced with a default config.\n" + "The error configuration file was saved in the.jsonError extension");
                LoadDefaultConfig();
            }
            SaveConfig();
        }
        protected override void LoadDefaultConfig() => config = GetDefaultSettings();
        private ConfigData GetDefaultSettings() {
            return new ConfigData {
                Commands = new ConfigData.CommandsOptions {
                    mapvote = "mvote", Generate = "MapVoter.generate", voteresult = "voteresult"
                }
                , rewards = new ConfigData.Rewards {
                    RustRewards = true, RWPoints = 5, Kits = true, KitName = string.Empty
                }
                , funKit = new ConfigData.FunKit {
                    enabled = false, KitStartTime = 120, KitName = "FunKit", Perm = ""
                }
                , Settings = new ConfigData.Options {
                    isRandomMapsFromfilterID = false, MaxPages = 10, isDiscordBot = true, isOnlyPlayersWithPermCanVote =false, DiscordLogs = false, DiscordLogChannelID = string.Empty, UIisDisabled = false, APIKey = "https://rustmaps.com/user/profile", size = 3500, staging = false, barren = false, Stopvote = 60, avatar_url = "", Footer = "", filterId = "Visit https://rustmaps.com/ and adjust your map requirements.In the red box above the settings hit the Share button,the string at the end of the URL is the filterId.Example URL: https://rustmaps.com/?share=gEU5W6BUuUG5FpPlyv2nhQ the string at the end in this case {gEU5W6BUuUG5FpPlyv2nhQ} is the filterId."
                }
                , _DiscordSettings = new ConfigData.DiscordSettings {
                    Vote_Channel_id = "", Discord_ApiKey = "BotToken", Commandprefix = "!", Channels = new List<ConfigData.DiscordChannel> {
                        new ConfigData.DiscordChannel {
                            Commands = new List<string> {
                                "generate", "vote", "mapwipe", "bpwipe", "cancelwipe", "stopvoting", "update", "cancelupdate"
                            }
                        }
                    }
                    , CmdRoles = new Dictionary<string, List<string>> {
                        {
                            "generate", new List<string>() {
                                "DiscordRoleName", "DiscordRoleName2"
                            }
                        }
                        , {
                            "vote", new List<string>() {
                                "DiscordRoleName", "DiscordRoleName2"
                            }
                        }
                        , {
                            "mapwipe", new List<string>() {
                                "DiscordRoleName", "DiscordRoleName2"
                            }
                        }
                        , {
                            "bpwipe", new List<string>() {
                                "DiscordRoleName", "DiscordRoleName2"
                            }
                        }
                        , {
                            "cancelwipe", new List<string>() {
                                "DiscordRoleName", "DiscordRoleName2"
                            }
                        }
                        , {
                            "stopvoting", new List<string>() {
                                "DiscordRoleName", "DiscordRoleName2"
                            }
                        }
                        , {
                            "update", new List<string>() {
                                "DiscordRoleName", "DiscordRoleName2"
                            }
                        }
                        , {
                            "cancelupdate", new List<string>() {
                                "DiscordRoleName", "DiscordRoleName2"
                            }
                        }
                    }
                }
                , AutoVote = new ConfigData.MVAutoVote {
                    isAutoVote = false, IsOnlyAuthUsers = false, StartVotingDaysBeforewipe = 0, StartVotingat = "17:00", nbm = 4,
                }
                , _AutoWipe = new ConfigData.AutoWipe {
                    isAutoWipe = true, _CustomMap = new ConfigData.CustomMap {
                        isCustomMap = false, Url = ""
                    }
                    , WipeBPs = true, ForcedWipeTime = "19:00", WipeTime = "19:00", MWschedule = new List<int> {
                        7, 14, 21, 28
                    }
                    , FWSchedule = new List<int> {
                        0
                    }
                }
            }
            ;
        }
        protected override void SaveConfig() => Config.WriteObject(config);
        protected override void LoadDefaultMessages() {
            lang.RegisterMessages(new Dictionary<string, string> {
                ["NoPermission"]
                = "You don't have the permission to use this command.", ["NoPermissionVote"] = "You don't have the permission to vote.", ["args"] = "Must type number of maps to generate.", ["GUI.Title"] = "Maps", ["GUI.CreateNew"] = "Settings", ["GUI.AddMaps"] = "Add Maps", ["UI.Title.Editor"] = "Settings", ["UI.Title.Add"] = "Add Maps", ["UI.Title"] = "Map Seed", ["UI.Details"] = "Generate", ["UI.cDetails"] = "Custom map details", ["UI.Procedural"] = "Procedural Map", ["UI.Custom"] = "Custom Map", ["UI.MapSize"] = "Map size", ["UI.generate"] = "Generate", ["UI.nb"] = "Ammount", ["UI.Save"] = "Save", ["MapLocked"] = "Map Locked {0}", ["Voting"] = "Map Vote has started! /{0}.", ["MapSave.Error.NoName"] = "Error", ["UI.NoMapsAvailable"] = "There are currently no Maps available", ["UI.Vote"] = "Vote", ["UI.Voted"] = "You have already voted.", ["UI.Generating"] = "Generating Map(s).This step usually takes around 2-5 minutes.", ["UI.Votenotstarted"] = "Map vote is not activated at the moment.", ["VoteStarted"] = "Map vote has started", ["VoteSuccess"] = "Thanks for voting", ["UI.stopVoteTimer"] = "Stop voting after", ["WipeAPIerror"] = "WipeAPI not found https://umod.org/plugins/wipe-info-api", ["GUI.SelectMaps"] = "Select Maps", ["UI.Select"] = "Select", ["UI.Loading"] = "Loading Maps.Filter Id : {0}", ["UI.Selected"] = "Selected", ["VoteResult"] = "Map Seed: {0} Votes: {1} Image Url : {2}", ["CurrentState"] = "Map Id: {0} current state: {1}", ["Commands"] = "Commands", ["Vote channel id"] = "Vote channel id", ["Error channel id"] = "Vote channel id is null or Empty", ["Options"] = "Options", ["AutoVote"] = "Auto Vote", ["AutoWipe"] = "Auto Wipe", ["Options"] = "Options", ["RustMaps API key"] = "RustMaps API key", ["Map size"] = "Map size", ["Stop voting after (minutes)"] = "Stop voting after (minutes)", ["Only Authanticated users can vote through discord"] = "Only Authanticated users can vote through discord", ["Discord avatar url"] = "Discord avatar url", ["Discord footer"] = "Discord footer", ["filter Id"] = "filter Id", ["Auto start voting"] = "Auto start voting", ["Start voting at (HH:mm) 24-hour clock (server local time)"] = "Start voting at (HH:mm) 24-hour clock (server local time)", ["Number of maps to generate"] = "Number of maps to generate", ["Open MapVoter UI"] = "Open MapVoter GUI", ["Generate Map(s)"] = "Generate Map(s)", ["vote result"] = "vote result", ["Auto Wipe"] = "Auto Wipe", ["Enable Auto wipe"] = "Enable Auto wipe", ["Custom map"] = "Custom map", ["Custom map URL"] = "Custom map URL", ["Wipe BPs at forced wipe day"] = "Wipe BPs at forced wipe day", ["Wipe time (HH:mm) 24-hour clock (server local time)"] = "Wipe time (HH:mm) 24-hour clock (server local time)", ["Map wipe schedule (Days since forced wipe)"] = "Map wipe schedule (Days since forced wipe)", ["Full wipe schedule(Days since forced wipe)"] = "Full wipe schedule(Days since forced wipe)", ["Discord Settings"] = "Discord Settings", ["Discord Webhook"] = "Discord Webhook", ["Bot Apikey"] = "Bot Apikey", ["Discord Command Prefix"] = "Discord Command Prefix", ["NewOxideVersion"] = "New Oxide.Rust version detected {0} -> {1}.", ["OxideUpToDate"] = "Current Oxide.Rust version is up-to-date, scheduling check after {0} Seconds...", ["AutoWiping"] ="Auto wiping in {0} Minutes: IsFullWipe : {1} isForcedWipe : {2}", ["VoteLog"] ="{0} has voted on map number {1}", ["SyntaxError"] = "Syntax error : canConvertDelta {0} canConvertMapSize {1} canConvertMapSeed {2}", ["SyntaxError1"] = "Syntax error : canConvertDelta {0} canConvertMapSize {1}", ["SyntaxError2"] ="Syntax error : canConvertDelta {0} canConvertMapSize {1} canConverMapUrl {2}", ["GUI.Details"] = "Details", ["map.Id"] = "Id", ["map.seed"] = "Seed", ["map.size"] = "Size", ["map.imgUrl"] = "Map image url", ["map.downloadUrl"] = "Direct download link", ["map.Name"] = "Name", ["UI.Add"] = "Add", ["Restarting"] = "Restarting the server in {0} seconds", ["UI.Added"] = "Saved", ["interrupted"] = "server restart interrupted", ["Defaultfilterid"] = "Visit https://rustmaps.com/ and adjust your map requirements.In the red box above the settings hit the Share button, the string at the end of the URL is the filterId.Example URL: https://rustmaps.com/?share=gEU5W6BUuUG5FpPlyv2nhQ the string at the end in this case {gEU5W6BUuUG5FpPlyv2nhQ} is the filterId"
            }
            , this);
        }
        string GetMsg(string key) => lang.GetMessage(key, this);
#endregion
#region Hooks
        private void OnServerInitialized() {
            Unsubscribe(nameof(OnItemAction));
            Unsubscribe(nameof(CanUnlockTechTreeNode));
            Unsubscribe(nameof(OnPlayerRespawned));
            Unsubscribe(nameof(OnPlayerConnected));
            //To make sure no one have permission for fun kit after wipe.server.Command($"oxide.revoke group default {config.funKit.Perm}");
            MVData = Interface.Oxide.DataFileSystem.ReadObject<List<RustMaps>>($"MapVoter/{Name}");
            wipeinfo = Interface.Oxide.DataFileSystem.ReadObject<Wipeinfo>("MapVoter/wipeinfo");
            voteData = Interface.Oxide.DataFileSystem.ReadObject<VoteData>("MapVoter/VotesData");
            CustomMaps = Interface.Oxide.DataFileSystem.ReadObject<List<CustomMap>>("MapVoter/CustomMapsData");
            if (voteData == null) {
                voteData = new VoteData(false);
            }
            else if (voteData.isVoteDay) {
                Maps = voteData.Maps;
                Voted = voteData.Voted;
                VoteResult = voteData.VoteResult;
                isCustomMaps = voteData.CustomMap;
                VoteStarted = true;
                dotimer["VoteA"] = timer.Every(3600, () => {
                    MapVoteA();
                }
                );
            }
            if (wipeinfo == null) {
                wipeinfo = new Wipeinfo();
                SaveWipeinfoData();
            }
            isCustomMaps = voteData.CustomMap;
            AddCovalenceCommand(config.Commands.Generate, nameof(cmdGenerate));
            AddCovalenceCommand(config.Commands.mapvote, nameof(cmdVote));
            AddCovalenceCommand(config.Commands.voteresult, nameof(cmdVoteResult));
            permission.RegisterPermission(permissionUse, this);
            permission.RegisterPermission(PermissionManager, this);
            permission.RegisterPermission(permissionVote, this);
            if (ImageLibrary != null) {
                RegisterImage("Maps.magnifyicon", MagnifyIconURL);
                foreach (var map in CustomMaps) {
                    RegisterImage(map.Name, map.Image);
                }
            }
            filterId = config.Settings.filterId;
            CurrentDate = DateTime.Now;
            WipeData = new AutoWipeConfig(IsWipeDay);
            SaveData();
            if (config.Settings.DiscordLogs && config.Settings.DiscordLogChannelID != null && config.Settings.DiscordLogChannelID != string.Empty && config.Settings.isDiscordBot) LogToDiscord = true;
            Puts("Time zone of the current computer:" + TimeZone.CurrentTimeZone.StandardName.ToString() + " \nCurrent date time : " + DateTime.Now);
            GetWipeSchedule();
            if (!IsRestarting && !WipeCanceled && config._AutoWipe.isAutoWipe) {
                CheckIfitsWipeDay();
                return;
            }
            if (config.AutoVote.isAutoVote && !VotingCanceled && !config._AutoWipe._CustomMap.isCustomMap) {
                autoStartVote();
                return;
            }
        }
        private void OnServerSave() {
            SaveData();
            SaveWipeinfoData();
            if (!IsRestarting && !WipeCanceled && config._AutoWipe.isAutoWipe) {
                CheckIfitsWipeDay();
                return;
            }
            if (config.AutoVote.isAutoVote && !VotingCanceled && !config._AutoWipe._CustomMap.isCustomMap) {
                autoStartVote();
                return;
            }
        }
        private void Unload() {
            if (isFunKitEnabled) server.Command($"oxide.revoke group default {config.funKit.Perm}");
            SaveData();
            SaveWipeinfoData();
            timer = null;
            Voted.Clear();
            Maps.Clear();
            VoteResult.Clear();
            Generating.Clear();
            FiltredMaps.Clear();
            FMaps.Clear();
            MVData.Clear();
            VoteStarted = false;
            foreach (var timer in dotimer.Values) {
                timer.Destroy();
            }
            dotimer.Clear();
            foreach (var player in BasePlayer.activePlayerList) {
                CuiHelper.DestroyUi(player, UI_MENU);
            }
        }
        private void SaveData() {
            try {
                Interface.Oxide.DataFileSystem.WriteObject($"MapVoter/{Name}", MVData);
                Interface.Oxide.DataFileSystem.WriteObject($"MapVoter/VotesData", voteData);
                Interface.Oxide.DataFileSystem.WriteObject("MapVoter/CustomMapsData", CustomMaps);
                Interface.Oxide.DataFileSystem.WriteObject("wipe", WipeData);
            }
            catch (Exception e) {
                Puts(e.Message);
            }
        }
        private void Reload() => ConsoleSystem.Run(ConsoleSystem.Option.Unrestricted, ($"oxide.reload MapVoter"));
        private void OnPlayerDisconnected (BasePlayer player) {
            CuiHelper.DestroyUi(player, UI_MENU);
            CuiHelper.DestroyUi(player, UI_POPUP);
        }
        private object OnItemAction(Item item, string action, BasePlayer player) {
            if (player == null || item == null) return null;
            if (action != "study") return null;
            return false;
        }
        private object CanUnlockTechTreeNode(BasePlayer player, TechTreeData.NodeInstance node, TechTreeData techTree) {
            return false;
        }
        void OnPlayerRespawned(BasePlayer player) {
            if (player == null || player.IsNpc) return;
            Puts($"Fun kit is enabled /kit {config.funKit.KitName}.");
            InventoryStrip(player);
            Kits?.Call("GiveKit", player, config.funKit.KitName);
        }
        void OnPlayerConnected(BasePlayer player) {
            Puts($"Fun kit is enabled /kit {config.funKit.KitName}.");
        }
#endregion
#region Commands
        private void cmdGenerate(IPlayer player, string cmd, string[] args) {
            if (!player.HasPermission(permissionUse)) {
                player.Reply(GetMsg("NoPermission"));
                return;
            }
            if (args.Length == 0) {
                player.Reply(GetMsg("args"));
                return;
            }
            if (args.Length == 2) {
                if(!string.IsNullOrEmpty(args[1])) size = args[1];
            }
            if (args.Length == 3) {
                if(!string.IsNullOrEmpty(args[2])) _stopvote = args[2];
            }
            seedGenerate(Int16.Parse(args[0]));
            foreach (var aPlayer in BasePlayer.activePlayerList) {
                if (IsAdmin(aPlayer)) aPlayer.SendConsoleCommand("chat.add", 0, 76561199214531833UL, GetMsg("UI.Generating"));
                if (LogToDiscord && config.Settings.isDiscordBot) Log(GetMsg("UI.Generating"));
            }
        }
        private void cmdVote(IPlayer player, string cmd, string[] args) {
            BasePlayer Player = player.Object as BasePlayer;
            if (Player == null) return;
            if (!IsAdmin(Player)) {
                if (!VoteStarted) {
                    player.Reply(GetMsg("UI.Votenotstarted"));
                    return;
                }
                if (config.Settings.UIisDisabled) {
                    if (config.Settings.isOnlyPlayersWithPermCanVote && !player.HasPermission(permissionVote)) {
                        player.Reply(GetMsg("NoPermissionVote"));
                        return;
                    }
                    if (Voted.Contains(Player.UserIDString)) {
                        player.Reply(GetMsg("UI.Voted"));
                        return;
                    }
                    int val;
                    var key = Convert.ToUInt32(args[0]);
                    if(VoteResult.TryGetValue(key, out val)) {
                        VoteResult[key] = val + 1;
                    }
                    Voted.Add(Player.UserIDString);
                    if (ServerRewards != null && config.rewards.RustRewards) ServerRewards?.Call("AddPoints", ((BasePlayer)player).userID, config.rewards.RWPoints);
                    if (Kits != null && config.rewards.Kits && (bool)Kits?.Call("IsKit", config.rewards.KitName)) Kits?.Call("GiveKit", (BasePlayer)player, config.rewards.KitName);
                    player.Reply(GetMsg("VoteSuccess"));
                    if (LogToDiscord && config.Settings.isDiscordBot) {
                        int i = 1;
                        foreach (var akey in VoteResult.Keys) {
                            if (akey == key) Log(string.Format(GetMsg("VoteLog"), Player.displayName, i));
                            i++;
                        }
                    }
                    return;
                }
            }
            OpenMapVoteGrid(Player);
        }
        private void cmdVoteResult(IPlayer player, string cmd, string[] args) {
            if(VoteStarted) return;
            if((VoteResult!= null) && (!VoteResult.Any())) return;
            var keyOfMaxValue = VoteResult.Aggregate((x, y) => x.Value > y.Value ? x : y).Key;
            player.Reply($"Map Locked : seed : {keyOfMaxValue} Votes : {VoteResult[keyOfMaxValue]}");
            if (LogToDiscord && config.Settings.isDiscordBot) Log($"Map Locked : seed : {keyOfMaxValue} Votes : {VoteResult[keyOfMaxValue]}");
        }
        [Command("clearvotes")]
        private void cmdClearVotes(IPlayer player, string cmd, string[] args) {
            BasePlayer Player = player.Object as BasePlayer;
            if (Player == null) return;
            if (IsAdmin(Player)) {
                voteData = new VoteData();
                SaveData();
                server.Command("o.reload MapVoter");
            }
        }
        [Command("GUI.close")]
        private void cmdMapVoteClose(IPlayer player, string cmd, string[] args) {
            BasePlayer Player = player.Object as BasePlayer;
            if (Player == null) return;
            CuiHelper.DestroyUi(Player, UI_MENU);
            CuiHelper.DestroyUi(Player, UI_POPUP);
        }
        [Command("Map.Generate")]
        private void cmdGenerateMap(IPlayer player, string cmd, string[] args) {
            BasePlayer Player = player.Object as BasePlayer;
            if (Player == null) return;
            if (IsAdmin(Player)) {
                configTEMP = config;
                CMapSize = config.Settings.size.ToString();
                StopVotingafter = config.Settings.Stopvote.ToString();
                AutoVoting = config.AutoVote.isAutoVote.ToString();
                enableautowipe = config._AutoWipe.isAutoWipe.ToString();
                _nbMap = config.AutoVote.nbm.ToString();
                _isCustomMap = config._AutoWipe._CustomMap.isCustomMap.ToString();
                bpswipe = config._AutoWipe.WipeBPs.ToString();
                isOnlyAuth = config.AutoVote.IsOnlyAuthUsers.ToString();
                _MapWipeSchedule = string.Join(",", config._AutoWipe.MWschedule.Select(x=> x.ToString()).ToArray());
                _FullWipeSchedule = string.Join(",", config._AutoWipe.FWSchedule.Select(x => x.ToString()).ToArray());
                OpenMapGenerator(Player);
            }
        }
        [Command("Map.CustomMaps")]
        private void cmdCustomMaps(IPlayer player, string cmd, string[] args) {
            if (!player.HasPermission(permissionUse)) {
                player.Reply(GetMsg("NoPermission"));
                return;
            }
            BasePlayer Player = player.Object as BasePlayer;
            if (Player == null) return;
            if (args.Length == 0) {
                OpenCustomMapSelect(Player);
                return;
            }
            if (args[0] == "add") {
                OpenCustomMapEditor(Player);
            }
        }
        [Command("StartVote")]
        private void cmdStartVote(IPlayer player, string cmd, string[] args) {
            if (!player.HasPermission(permissionUse)) {
                player.Reply(GetMsg("NoPermission"));
                return;
            }
            BasePlayer Player = player.Object as BasePlayer;
            if (Player == null) return;
            if (IsAdmin(Player)) {
                voteData = new VoteData();
                VoteResult.Clear();
                if (!Maps.Any()) {
                    if (args.Length == 0) {
                        player.Reply(GetMsg("args"));
                        return;
                    }
                    if (args.Length == 2) {
                        if(!string.IsNullOrEmpty(args[1])) size = args[1];
                    }
                    if (args.Length == 3) {
                        if(!string.IsNullOrEmpty(args[2])) _stopvote = args[2];
                    }
                    seedGenerate(Int16.Parse(args[0]));
                    return;
                }
                foreach(var map in Maps) {
                    VoteResult.Add(Convert.ToUInt32(map.Seed), 0);
                }
                VoteStarted = true;
                if (config.Settings.isDiscordBot) NotifyDiscord();
                NextTick(() => {
                    foreach (var aplayer in players.Connected) {
                        aplayer.Message(string.Format(GetMsg("Voting"), config.Commands.mapvote));
                    }
                }
                );
                dotimer["VoteA"] = timer.Every(config.Settings.Stopvote * 60 / 4, () => {
                    MapVoteA();
                }
                );
                int stopvote;
                if (args.Length != 0) {
                    if (!int.TryParse(args[0], out stopvote)) return;
                }
                else stopvote = config.Settings.Stopvote;
                dotimer["StopVoting"] = timer.Once(stopvote * 60, () => {
                    StopVoting();
                }
                );
            }
        }
        [Command("Map.Save")]
        private void cmdSaveConfig(IPlayer player, string cmd, string[] args) {
            if (!player.HasPermission(PermissionManager)) {
                player.Reply(GetMsg("NoPermission"));
                return;
            }
            SaveConfig();
            server.Command("o.reload MapVoter");
            BasePlayer Player = player.Object as BasePlayer;
            if (Player == null) return;
            CuiHelper.DestroyUi(Player, UI_MENU);
            CuiHelper.DestroyUi(Player, UI_POPUP);
            OpenMapVoteGrid(Player);
        }
        [Command("Map.Savemap")]
        private void cmdSaveMap(IPlayer player, string cmd, string[] args) {
            if (!player.HasPermission(PermissionManager)) {
                player.Reply(GetMsg("NoPermission"));
                return;
            }
            BasePlayer Player = player.Object as BasePlayer;
            CustomMaps.Add(new CustomMap(mapname, downloadurl, cimageurl));
            CreateMenuPopup(Player, GetMsg("Saved"));
            RegisterImage(mapname, cimageurl);
            mapname = string.Empty;
            downloadurl = string.Empty;
            cimageurl = string.Empty;
            OpenCustomMapEditor(Player);
        }
        [Command("Map.GenerateNow")]
        private void ccmdGenerate(IPlayer player, string cmd, string[] args) {
            if (!player.HasPermission(permissionUse)) {
                player.Reply(GetMsg("NoPermission"));
                return;
            }
            BasePlayer Player = player.Object as BasePlayer;
            if (Player == null) return;
            if (string.IsNullOrEmpty(nbMaps)) {
                CreateMenuPopup(Player, GetMsg("MapSave.Error.NoName"));
                return;
            }
            if (IsAdmin(Player)) {
                seedGenerate(Int16.Parse(nbMaps));
                CuiHelper.DestroyUi(Player, UI_MENU);
                CuiHelper.DestroyUi(Player, UI_POPUP);
            }
            OpenMapVoteGrid(Player);
            CreateMenuPopup(Player, GetMsg("UI.Generating"));
            if (IsAdmin(Player)) Player.SendConsoleCommand("chat.add", 0, 76561199214531833UL, GetMsg("UI.Generating"));
        }
        [Command("Mapvoter.reload")]
        private void ccmdClear(IPlayer player, string cmd, string[] args) {
            if (!player.HasPermission(permissionUse)) {
                player.Reply(GetMsg("NoPermission"));
                return;
            }
            foreach (BasePlayer Player in BasePlayer.activePlayerList) {
                CuiHelper.DestroyUi(Player, UI_MENU);
                CuiHelper.DestroyUi(Player, UI_POPUP);
            }
            Reload();
        }
        [Command("Map.set")]
        private void ccmdSet(IPlayer player, string cmd, string[] args) {
            if (!player.HasPermission(permissionUse)) {
                player.Reply(GetMsg("NoPermission"));
                return;
            }
            BasePlayer Player = player.Object as BasePlayer;
            if (Player == null) return;
            bool flag;
            bool canConvert;
            int x =0;
            if (args[0] == "mapname") {
                var val = string.Join(" ", args.Skip(1));
                mapname = (string)val;
                OpenCustomMapEditor(Player);
                return;
            }
            if (args[0] == "downloadurl") {
                var val = string.Join(" ", args.Skip(1));
                downloadurl = (string)val;
                OpenCustomMapEditor(Player);
                return;
            }
            if (args[0] == "imageurl") {
                var val = string.Join(" ", args.Skip(1));
                cimageurl = (string)val;
                OpenCustomMapEditor(Player);
                return;
            }
            if (args[0] == "nbMaps") {
                var val = string.Join(" ", args.Skip(1));
                nbMaps = (string)val;
            }
            if (args[0] == "Size") {
                var val = string.Join(" ", args.Skip(1));
                size = (string)val;
            }
            if (args[0] == "stopvote") {
                var val = string.Join(" ", args.Skip(1));
                _stopvote = (string)val;
            }
            if (args[0] == "filterid") {
                var val = string.Join(" ", args.Skip(1));
                filterId = (string)val;
                return;
            }
            if (args[0] == "APIKey") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP.Settings.APIKey = (string)val;
            }
            if (args[0] == "CMapSize") {
                var val = string.Join(" ", args.Skip(1));
                canConvert = Int32.TryParse((string)val, out x);
                if(canConvert) {
                    CMapSize = (string)val;
                    configTEMP.Settings.size = x;
                }
            }
            if (args[0] == "Cstopvote") {
                var val = string.Join(" ", args.Skip(1));
                canConvert = Int32.TryParse((string)val, out x);
                if(canConvert) {
                    StopVotingafter = (string)val;
                    configTEMP.Settings.Stopvote = x;
                }
            }
            if (args[0] == "votechannelid") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP._DiscordSettings.Vote_Channel_id = (string)val;
            }
            if (args[0] == "avatar") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP.Settings.avatar_url = (string)val;
            }
            if (args[0] == "BOTKey") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP._DiscordSettings.Discord_ApiKey = (string)val;
            }
            if (args[0] == "prefix") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP._DiscordSettings.Commandprefix = (string)val;
            }
            if (args[0] == "footer") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP.Settings.Footer = (string)val;
            }
            if (args[0] == "filterid") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP.Settings.filterId = (string)val;
            }
            if (args[0] == "AutoStartVoting") {
                var val = string.Join(" ", args.Skip(1));
                AutoVoting = (string)val;
                if (Boolean.TryParse(val, out flag)) configTEMP.AutoVote.isAutoVote = flag;
                else configTEMP.AutoVote.isAutoVote = false;
            }
            if (args[0] == "isOnlyAuth") {
                var val = string.Join(" ", args.Skip(1));
                isOnlyAuth = (string)val;
                if (Boolean.TryParse(val, out flag)) configTEMP.AutoVote.IsOnlyAuthUsers = flag;
                else configTEMP.AutoVote.IsOnlyAuthUsers = false;
            }
            if (args[0] == "Startat") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP.AutoVote.StartVotingat = (string)val;
            }
            if (args[0] == "nbmGenerate") {
                var val = string.Join(" ", args.Skip(1));
                canConvert = Int32.TryParse((string)val, out x);
                if (canConvert) {
                    _nbMap = (string)val;
                    configTEMP.AutoVote.nbm = x;
                }
            }
            if (args[0] == "UICmd") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP.Commands.mapvote = (string)val;
            }
            if (args[0] == "GenerateCmd") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP.Commands.Generate = (string)val;
            }
            if (args[0] == "resultCmd") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP.Commands.voteresult = (string)val;
            }
            if (args[0] == "enableautowipe") {
                var val = string.Join(" ", args.Skip(1));
                enableautowipe = (string)val;
                if (Boolean.TryParse(val, out flag)) configTEMP._AutoWipe.isAutoWipe = flag;
                else configTEMP._AutoWipe.isAutoWipe = false;
            }
            if (args[0] == "iscustommap") {
                var val = string.Join(" ", args.Skip(1));
                _isCustomMap = (string)val;
                if (Boolean.TryParse(val, out flag)) configTEMP._AutoWipe._CustomMap.isCustomMap = flag;
                else configTEMP._AutoWipe._CustomMap.isCustomMap = false;
            }
            if (args[0] == "custommapurl") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP._AutoWipe._CustomMap.Url = (string)val;
            }
            if (args[0] == "wipebps") {
                var val = string.Join(" ", args.Skip(1));
                bpswipe = (string)val;
                if (Boolean.TryParse(val, out flag)) configTEMP._AutoWipe.WipeBPs = flag;
                else configTEMP._AutoWipe.WipeBPs = false;
            }
            if (args[0] == "wipetime") {
                var val = string.Join(" ", args.Skip(1));
                configTEMP._AutoWipe.WipeTime = (string)val;
            }
            if (args[0]
// ... [Code preview truncated due to length. Full source in attached file] ...

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