Files
reallife-gamemode/ReallifeGamemode.Server/Util/PlayerTimer.cs
2021-04-13 17:57:33 +02:00

54 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Timers;
using GTANetworkAPI;
using ReallifeGamemode.Server.Inventory.Interfaces;
namespace ReallifeGamemode.Server.Util
{
public class PlayerTimer
{
private readonly Player player;
private readonly Vehicle veh;
private readonly IUsableItem usableItem;
private readonly Timer timer;
public readonly DateTime startTime;
public delegate void PlayerTimerElapsed(Player player, Vehicle veh);
public event PlayerTimerElapsed Elapsed;
public PlayerTimer(Player player, Vehicle veh = null, int milliseconds = 1000)
{
this.player = player;
this.veh = veh;
this.timer = new Timer(milliseconds);
this.timer.Elapsed += Timer_Elapsed;
this.timer.Start();
}
public PlayerTimer(Player player, IUsableItem usableItem, int milliseconds = 1000)
{
this.player = player;
this.usableItem = usableItem;
this.startTime = DateTime.Now;
this.timer = new Timer(milliseconds);
this.timer.Elapsed += Timer_Elapsed;
this.timer.Start();
}
private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
Elapsed?.Invoke(player, veh);
}
public void Stop()
{
this.timer.Stop();
}
}
}