SHOW:
|
|
- or go back to the newest paste.
1 | public static void TicketClear(CommandArgs args) | |
2 | { | |
3 | if (args.Parameters.Count < 1) | |
4 | { | |
5 | args.Player.SendMessage("Syntax: /ticclear <all/id> <id>", Color.Red); | |
6 | return; | |
7 | } | |
8 | switch (args.Parameters[0].ToLower()) | |
9 | { | |
10 | case "all": | |
11 | try | |
12 | { | |
13 | File.Delete("Tickets.txt"); | |
14 | args.Player.SendMessage("All of the Tickets were cleared!", Color.DarkCyan); | |
15 | Console.ForegroundColor = ConsoleColor.Red; | |
16 | Console.WriteLine(string.Format("{0} has cleared all of the tickets.", args.Player.Name)); | |
17 | Console.ResetColor(); | |
18 | } | |
19 | catch (Exception e) | |
20 | { | |
21 | // Let the console know what went wrong, and tell the player that there was an error. | |
22 | args.Player.SendMessage("Something went wrong when you tried to clear the tickets, contact an administrator when you can.", Color.Red); | |
23 | Console.ForegroundColor = ConsoleColor.Red; | |
24 | Console.WriteLine(e.Message); | |
25 | Console.ResetColor(); | |
26 | } | |
27 | break; | |
28 | case "id": | |
29 | if (args.Parameters.Count > 0) | |
30 | { | |
31 | int lineToDelete = 0; | |
32 | if (!int.TryParse(args.Parameters[1], out lineToDelete)) | |
33 | { | |
34 | args.Player.SendMessage("The line you entered was not an integer!", Color.Red); | |
35 | return; | |
36 | } | |
37 | try | |
38 | { | |
39 | var file = new List<string>(System.IO.File.ReadAllLines("Tickets.txt")); | |
40 | bool contains = false; | |
41 | foreach (var line in file) | |
42 | { | |
43 | if (line.StartsWith(lineToDelete + ".")) | |
44 | { | |
45 | contains = true; | |
46 | file.Remove(line); | |
47 | break; | |
48 | } | |
49 | } | |
50 | if (contains) | |
51 | { | |
52 | File.WriteAllLines("Tickets.txt", file.ToArray()); | |
53 | args.Player.SendMessage(string.Format("Ticket ID {0} was cleared!", args.Parameters[1]), Color.DarkCyan); | |
54 | Console.ForegroundColor = ConsoleColor.Red; | |
55 | Console.WriteLine(string.Format("{0} has cleared ticket ID: {1}", args.Player.Name, args.Parameters[1])); | |
56 | Console.ResetColor(); | |
57 | } | |
58 | else | |
59 | { | |
60 | args.Player.SendMessage("There is no ticket witht that ID.", Color.Red); | |
61 | return; | |
62 | } | |
63 | } | |
64 | catch (Exception e) | |
65 | { | |
66 | args.Player.SendMessage("Something went wrong when you tried to clear the ticket, contact an administrator when you can.", Color.Red); | |
67 | Console.ForegroundColor = ConsoleColor.Red; | |
68 | Console.WriteLine(e.Message); | |
69 | Console.ResetColor(); | |
70 | } | |
71 | } | |
72 | else | |
73 | { | |
74 | args.Player.SendMessage("You have to state a ticket id! Syntax: /ticclear id <ticid>", Color.Red); | |
75 | } | |
76 | break; | |
77 | default: | |
78 | args.Player.SendMessage("Syntax: /ticclear <all/id> <id>", Color.Red); | |
79 | break; | |
80 | } | |
81 | } |