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>>>(json); if (!data.ContainsKey("Players")) { SendReply(player, "Player data not found."); return; } var convertedData = new Dictionary(); foreach (var kvp in data["Players"]) { var steamId = kvp.Key; if (kvp.Value is Dictionary 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>(json); var originalData = new Dictionary>> { ["Players"] = new Dictionary>() }; foreach (var kvp in data) { var steamId = kvp.Key; var voted = kvp.Value; originalData["Players"].Add(steamId, new Dictionary { ["voted"] = voted }); } var originalJson = JsonConvert.SerializeObject(originalData, Formatting.Indented); File.WriteAllText(Path.Combine(Interface.Oxide.DataDirectory, "EasyVote.json"), originalJson); SendReply(player, "Reversion completed."); } } }