-
Notifications
You must be signed in to change notification settings - Fork 2
/
cEvent.cs
87 lines (69 loc) · 3.16 KB
/
cEvent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using Rocket.API;
using Rocket.Unturned.Chat;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Countdown;
using System.Globalization;
namespace Countdown
{
public class cEvent : IRocketCommand
{
public List<string> Aliases { get { return new List<string>(); } }
public AllowedCaller AllowedCaller { get { return AllowedCaller.Both; } }
public string Help { get { return "Countdown to an event"; } }
public string Name { get { return "event"; } }
public List<string> Permissions { get { return new List<string> { "event" }; } }
public string Syntax { get { return "/event <event name> for info"; } }
public void Execute(IRocketPlayer caller, string[] command)
{
bool found = false;
if (command.Length == 1)
{
foreach (Config.Time ct in Main.Instance.Configuration.Instance._events.EventList)
{
if (command[0].ToLower() == ct.Name.ToLower())
{
DateTime thi = new DateTime(ct.Year, ct.Month, ct.Day, ct.Hour, ct.Minutes, 0, DateTimeKind.Local);
if (DateTime.Now.Ticks < thi.Ticks)
{
found = true;
TimeSpan s = new TimeSpan(thi.Ticks - DateTime.Now.Ticks);
int hours = ct.Hour;
string ampm = "am";
if (hours == 0)
hours = 12;
else if (hours == 12)
ampm = "pm";
else if (hours > 12)
{
hours -= 12;
ampm = "pm";
}
string formattedTime = hours.ToString();
string dte = "";
if (Main.Instance.Configuration.Instance.DDMMYYYY)
dte = thi.Date.ToString("dd/MM/yyyy", CultureInfo.CurrentCulture);
else
dte = thi.Date.ToString();
UnturnedChat.Say(dte);
UnturnedChat.Say(caller, Main.Instance.Translate("time", ct.Name, dte, formattedTime, s.Minutes, ampm));
if (s.Days == 1)
UnturnedChat.Say(caller, Main.Instance.Translate("dayleft", ct.Name, s.Days, s.Hours));
else
UnturnedChat.Say(caller, Main.Instance.Translate("daysleft", ct.Name, s.Days, s.Hours));
UnturnedChat.Say(caller, ct.info);
}
}
}
if (!found)
UnturnedChat.Say(caller, "Event not found, type /events for a list of events");
}
else
{
UnturnedChat.Say(caller, "Type /events for a list of events");
}
}
}
}