mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
* Fix AutoFishing crash * Fix all warnings * Remove DotNetZip. * Fix the usage of HttpClient.
42 lines
1 KiB
C#
42 lines
1 KiB
C#
using System;
|
|
|
|
namespace MinecraftClient
|
|
{
|
|
/// <summary>
|
|
/// Holds a task with delay
|
|
/// </summary>
|
|
class TaskWithDelay
|
|
{
|
|
private readonly Action _task;
|
|
private int tickCounter;
|
|
private readonly 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tick the counter
|
|
/// </summary>
|
|
/// <returns>Return true if the task should run now</returns>
|
|
public bool Tick()
|
|
{
|
|
tickCounter--;
|
|
if (tickCounter <= 0 || dateToLaunch < DateTime.Now)
|
|
return true;
|
|
return false;
|
|
}
|
|
}
|
|
}
|