using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MinecraftClient { /// /// Holds a task with delay /// class TaskWithDelay { private Action _task; private int tickCounter; private DateTime dateToLaunch; public Action Task { get { return _task; } } public TaskWithDelay(Action task, int delayTicks) { _task = task; tickCounter = delayTicks; dateToLaunch = DateTime.MaxValue; } public TaskWithDelay(Action task, TimeSpan delay) { _task = task; tickCounter = int.MaxValue; dateToLaunch = DateTime.Now + delay; } /// /// Tick the counter /// /// Return true if the task should run now public bool Tick() { tickCounter--; if (tickCounter <= 0 || dateToLaunch < DateTime.Now) return true; return false; } } }