-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventHandlers.cs
60 lines (53 loc) · 1.94 KB
/
EventHandlers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// File path: GeneratorLockPlugin/EventHandlers.cs
namespace GeneratorLockPlugin
{
using System;
using Exiled.API.Features;
using Exiled.Events.EventArgs;
using MEC;
using System.Collections.Generic;
using Exiled.Events.EventArgs.Player;
public class EventHandlers
{
private readonly Plugin plugin;
private bool isLocked;
private int initialSeed;
private DateTime roundStartTime;
private CoroutineHandle lockCoroutine;
public EventHandlers(Plugin plugin)
{
this.plugin = plugin;
}
public void OnRoundStarted()
{
isLocked = true;
initialSeed = Map.Seed;
roundStartTime = DateTime.Now;
lockCoroutine = Timing.RunCoroutine(UnlockGeneratorsAfterDelay());
}
private IEnumerator<float> UnlockGeneratorsAfterDelay()
{
for (int remainingTime = plugin.Config.LockDuration; remainingTime > 0; remainingTime--)
{
if (Map.Seed != initialSeed)
{
Log.Info("The server restarted before the generators unlocked. The countdown has been reset for the next game.");
yield break;
}
yield return Timing.WaitForSeconds(1f);
}
isLocked = false;
}
public void OnInteractingGenerator(UnlockingGeneratorEventArgs ev)
{
if (isLocked)
{
// Bloquer l'interaction avec le générateur pour tous les joueurs, peu importe s'ils ont une carte ou non
ev.IsAllowed = false;
int elapsedTime = (int)(DateTime.Now - roundStartTime).TotalSeconds;
int remainingTime = plugin.Config.LockDuration - elapsedTime;
ev.Player.ShowHint(string.Format(plugin.Translation.GeneratorLockedTimeHint, remainingTime), 5);
}
}
}
}