mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
+ Rework task scheduling in chatbots + Switch back terrain processing to tasks
This commit is contained in:
parent
c1cfaf520d
commit
95d6318350
7 changed files with 517 additions and 461 deletions
45
MinecraftClient/TaskWithDelay.cs
Normal file
45
MinecraftClient/TaskWithDelay.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MinecraftClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Holds a task with delay
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue