static void TimerCallback([NotNull] SchedulerTask task) { if (task == null) { throw new ArgumentNullException("task"); } ChatTimer timer = (ChatTimer)task.UserState; if (task.MaxRepeats == 1) { if (String.IsNullOrEmpty(timer.Message)) { Chat.SendSay(Player.Console, "(Timer Up)"); } else { Chat.SendSay(Player.Console, "(Timer Up) " + timer.Message); } timer.Stop(false); } else if (timer.announceIntervalIndex >= 0) { if (timer.lastHourAnnounced != (int)timer.TimeLeft.TotalHours) { timer.lastHourAnnounced = (int)timer.TimeLeft.TotalHours; timer.Announce(TimeSpan.FromHours(Math.Ceiling(timer.TimeLeft.TotalHours))); } if (timer.TimeLeft <= AnnounceIntervals[timer.announceIntervalIndex]) { timer.Announce(AnnounceIntervals[timer.announceIntervalIndex]); timer.announceIntervalIndex--; } } }
static void TimerCallback([NotNull] SchedulerTask task) { if (task == null) { throw new ArgumentNullException("task"); } ChatTimer timer = (ChatTimer)task.UserState; if (task.MaxRepeats == 1) { if (String.IsNullOrEmpty(timer.Message)) { Server.Players.Message("&2[&7CountDown Finished&2]"); IRC.SendChannelMessage("\u212C&S[&7CountDown Finished&S]"); } else { Server.Players.Message("&2[&7Timer Finished&2] &7" + timer.Message); IRC.SendChannelMessage("\u212C&S[&7Timer Finished&S]\u211C " + timer.Message); } //Timer Ends Here. timer.Stop(false); } else if (timer.announceIntervalIndex >= 0) { if (timer.lastHourAnnounced != (int)timer.TimeLeft.TotalHours) { timer.lastHourAnnounced = (int)timer.TimeLeft.TotalHours; timer.Announce(TimeSpan.FromHours(Math.Ceiling(timer.TimeLeft.TotalHours))); } if (timer.TimeLeft <= AnnounceIntervals[timer.announceIntervalIndex]) { timer.Announce(AnnounceIntervals[timer.announceIntervalIndex]); timer.announceIntervalIndex--; } } }
static void TimerHandler(Player player, Command cmd) { string param = cmd.Next(); // List timers if (param == null) { ChatTimer[] list = ChatTimer.TimerList.OrderBy(timer => timer.TimeLeft).ToArray(); if (list.Length == 0) { player.Message("No timers running."); } else { player.Message("There are {0} timers running:", list.Length); foreach (ChatTimer timer in list) { player.Message(" #{0} \"{1}&S\" (started by {2}, {3} left)", timer.Id, timer.Message, timer.StartedBy, timer.TimeLeft.ToMiniString()); } } return; } // Abort a timer if (param.Equals("abort", StringComparison.OrdinalIgnoreCase)) { int timerId; if (cmd.NextInt(out timerId)) { ChatTimer timer = ChatTimer.FindTimerById(timerId); if (timer == null || !timer.IsRunning) { player.Message("Given timer (#{0}) does not exist.", timerId); } else { timer.Stop(); string abortMsg = String.Format("&Y(Timer) {0}&Y aborted a timer with {1} left: {2}", player.ClassyName, timer.TimeLeft.ToMiniString(), timer.Message); Chat.SendSay(player, abortMsg); } } else { CdTimer.PrintUsage(player); } return; } // Start a timer if (player.Info.IsMuted) { player.MessageMuted(); return; } if (player.DetectChatSpam()) { return; } TimeSpan duration; if (!param.TryParseMiniTimespan(out duration)) { CdTimer.PrintUsage(player); return; } if (duration > DateTimeUtil.MaxTimeSpan) { player.MessageMaxTimeSpan(); return; } if (duration < ChatTimer.MinDuration) { player.Message("Timer: Must be at least 1 second."); return; } string sayMessage; string message = cmd.NextAll(); if (String.IsNullOrEmpty(message)) { sayMessage = String.Format("&Y(Timer) {0}&Y started a {1} timer", player.ClassyName, duration.ToMiniString()); } else { sayMessage = String.Format("&Y(Timer) {0}&Y started a {1} timer: {2}", player.ClassyName, duration.ToMiniString(), message); } Chat.SendSay(player, sayMessage); ChatTimer.Start(duration, message, player.Name); }