public static void Reload(CommandArgs args) { TicketReader Reader = new TicketReader(); try { ticketlist = Reader.readFile(save); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Ticket System being reloaded..."); args.Player.SendMessage("Ticket System being reloaded...", Color.Yellow); Log.Info("Ticket System Reloading..."); if (ticketlist.Tickets.Count != 0) { Console.WriteLine(ticketlist.Tickets.Count + " tickets have been reloaded."); args.Player.SendMessage(ticketlist.Tickets.Count + " tickets have been reloaded.", Color.Yellow); } else { Console.WriteLine("There are no tickets."); args.Player.SendMessage("There are no tickets.", Color.Yellow); } Console.ResetColor(); args.Player.SendMessage("Ticket System reloaded.", Color.Yellow); Log.Info("Ticket System Reloaded."); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error in Tickets.json file! Check log for more details."); args.Player.SendMessage("Error in Tickets.json file! Check log for more details.", Color.Red); Console.WriteLine(e.Message); Console.ResetColor(); Log.Error("--------- Config Exception in TicketSystem Config file (Tickets.json) ---------"); Log.Error(e.Message); Log.Error("---------------------------------- Error End ----------------------------------"); } }
public static void Setup() { save = Path.Combine(TShock.SavePath, @"TicketSystem\Tickets.json"); banned = Path.Combine(TShock.SavePath, @"TicketSystem\Banned.txt"); TicketReader Reader = new TicketReader(); Config = new Config(); if (File.Exists(save)) { try { ticketlist = Reader.readFile(save); Console.ForegroundColor = ConsoleColor.Yellow; if (ticketlist.Tickets.Count != 0) Console.WriteLine(ticketlist.Tickets.Count + " tickets have been loaded."); else Console.WriteLine("There are no tickets."); Console.ResetColor(); try { if (File.Exists(ConfigPath)) Config = Config.Read(ConfigPath); Config.Write(ConfigPath); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error in TicketSystem Config.json file! Check log for more details."); Console.WriteLine(e.Message); Console.ForegroundColor = ConsoleColor.Gray; Log.Error("Config Exception"); Log.Error(e.ToString()); } } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error in Tickets.json file! Check log for more details."); Console.WriteLine(e.Message); Console.ResetColor(); Log.Error("------------- Config Exception in Ticket List file (Tickets.json) -------------"); Log.Error(e.Message); Log.Error("---------------------------------- Error End ----------------------------------"); Console.ForegroundColor = ConsoleColor.Red; } } else { Directory.CreateDirectory(Path.Combine(TShock.SavePath, "TicketSystem")); ticketlist = Reader.writeFile(save); using (StreamWriter writer = new StreamWriter(tagpath, true)) { writer.WriteLine("Default"); writer.WriteLine("Grief"); writer.WriteLine("Report"); writer.WriteLine("High-Importance"); } using (StreamWriter writer = new StreamWriter(Path.Combine(TShock.SavePath, @"TicketSystem\loginmsg.txt"), true)) { writer.WriteLine("To write a complaint, use \"/ticket [-t:<tag>] <Message>\""); writer.WriteLine("NOTE: Tags are optional. To view a list of tags, use \"/ticket tags\""); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("There are no tickets."); Console.ResetColor(); Log.Info("No tickets submitted."); } }