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

FREE EasyVoteDataConverter : 1.0.2 1.0.2

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

namespace Oxide.Plugins
{
    [Info("EasyVoteDataConverter", "DeutscherRitterPlatz", "1.0.2")]
    [Description("Converts Umod's old EasyVote.json data to the correct format for BippyMiester's paid or free EasyVote version and back again!")]
    class EasyVoteDataConverter : RustPlugin
    {
        [ChatCommand("evproconvert")]
        private void ConvertVotesProCommand(BasePlayer player, string command, string[] args)
        {
            if (!player.IsAdmin)
            {
                SendReply(player, "Only administrators can use this command.");
                return;
            }

            ConvertVotes(player, "EasyVotePro");
        }

        [ChatCommand("evliteconvert")]
        private void ConvertVotesLiteCommand(BasePlayer player, string command, string[] args)
        {
            if (!player.IsAdmin)
            {
                SendReply(player, "Only administrators can use this command.");
                return;
            }

            ConvertVotes(player, "EasyVoteLite");
        }

        [ChatCommand("bevproconvert")]
        private void ConvertBackVotesProCommand(BasePlayer player, string command, string[] args)
        {
            if (!player.IsAdmin)
            {
                SendReply(player, "Only administrators can use this command.");
                return;
            }

            ConvertBackVotes(player, "EasyVotePro");
        }
		
		[ChatCommand("bevliteconvert")]
        private void ConvertBackVotesLiteCommand(BasePlayer player, string command, string[] args)
        {
            if (!player.IsAdmin)
            {
                SendReply(player, "Only administrators can use this command.");
                return;
            }

            ConvertBackVotes(player, "EasyVoteLite");
        }

        private void ConvertVotes(BasePlayer player, string outputFileName)
        {
            var filePath = Path.Combine(Interface.Oxide.DataDirectory, "EasyVote.json");
            if (!File.Exists(filePath))
            {
                SendReply(player, "EasyVote.json was not found.");
                return;
            }

            var json = File.ReadAllText(filePath);
            var data = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, Dictionary<string, object>>>>(json);

            if (!data.ContainsKey("Players"))
            {
                SendReply(player, "Player data not found.");
                return;
            }

            var convertedData = new Dictionary<string, int>();

            foreach (var kvp in data["Players"])
            {
                var steamId = kvp.Key;
                if (kvp.Value is Dictionary<string, object> playerData && playerData.TryGetValue("voted", out var votedObj) && int.TryParse(votedObj.ToString(), out var voted))
                {
                    convertedData.Add(steamId, voted);
                }
                else
                {
                    SendReply(player, $"Player data not in correct format for SteamID: {steamId}");
                }
            }

            var convertedJson = JsonConvert.SerializeObject(convertedData, Formatting.Indented);
            File.WriteAllText(Path.Combine(Interface.Oxide.DataDirectory, $"{outputFileName}.json"), convertedJson);

            SendReply(player, "Conversion completed.");
        }

        private void ConvertBackVotes(BasePlayer player, string inputFileName)
        {
            var filePath = Path.Combine(Interface.Oxide.DataDirectory, $"{inputFileName}.json");
            if (!File.Exists(filePath))
            {
                SendReply(player, $"{inputFileName}.json was not found.");
                return;
            }

            var json = File.ReadAllText(filePath);
            var data = JsonConvert.DeserializeObject<Dictionary<string, int>>(json);

            var originalData = new Dictionary<string, Dictionary<string, Dictionary<string, object>>>
            {
                ["Players"] = new Dictionary<string, Dictionary<string, object>>()
            };

            foreach (var kvp in data)
            {
                var steamId = kvp.Key;
                var voted = kvp.Value;

                originalData["Players"].Add(steamId, new Dictionary<string, object> { ["voted"] = voted });
            }

            var originalJson = JsonConvert.SerializeObject(originalData, Formatting.Indented);
            File.WriteAllText(Path.Combine(Interface.Oxide.DataDirectory, "EasyVote.json"), originalJson);

            SendReply(player, "Reversion completed.");
        }
    }
}

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