Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void TicketClear(CommandArgs args)
- {
- if (args.Parameters.Count < 1)
- {
- args.Player.SendMessage("Syntax: /ticclear <all/id> <id>", Color.Red);
- return;
- }
- switch (args.Parameters[0].ToLower())
- {
- case "all":
- try
- {
- File.Delete("Tickets.txt");
- args.Player.SendMessage("All of the Tickets were cleared!", Color.DarkCyan);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(string.Format("{0} has cleared all of the tickets.", args.Player.Name));
- Console.ResetColor();
- }
- catch (Exception e)
- {
- // Let the console know what went wrong, and tell the player that there was an error.
- args.Player.SendMessage("Something went wrong when you tried to clear the tickets, contact an administrator when you can.", Color.Red);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(e.Message);
- Console.ResetColor();
- }
- break;
- case "id":
- if (args.Parameters.Count > 0)
- {
- int lineToDelete = 0;
- if (!int.TryParse(args.Parameters[1], out lineToDelete))
- {
- args.Player.SendMessage("The line you entered was not an integer!", Color.Red);
- return;
- }
- try
- {
- var file = new List<string>(System.IO.File.ReadAllLines("Tickets.txt"));
- bool contains = false;
- foreach (var line in file)
- {
- if (line.StartsWith(lineToDelete + "."))
- {
- contains = true;
- file.Remove(line);
- break;
- }
- }
- if (contains)
- {
- File.WriteAllLines("Tickets.txt", file.ToArray());
- args.Player.SendMessage(string.Format("Ticket ID {0} was cleared!", args.Parameters[1]), Color.DarkCyan);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(string.Format("{0} has cleared ticket ID: {1}", args.Player.Name, args.Parameters[1]));
- Console.ResetColor();
- }
- else
- {
- args.Player.SendMessage("There is no ticket witht that ID.", Color.Red);
- return;
- }
- }
- catch (Exception e)
- {
- args.Player.SendMessage("Something went wrong when you tried to clear the ticket, contact an administrator when you can.", Color.Red);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(e.Message);
- Console.ResetColor();
- }
- }
- else
- {
- args.Player.SendMessage("You have to state a ticket id! Syntax: /ticclear id <ticid>", Color.Red);
- }
- break;
- default:
- args.Player.SendMessage("Syntax: /ticclear <all/id> <id>", Color.Red);
- break;
- }
- }
Add Comment
Please, Sign In to add comment