forked from steven4547466/Overdose
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOverdose.cs
97 lines (77 loc) · 2.94 KB
/
Overdose.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using Exiled.API.Enums;
using Exiled.API.Features;
using Player = Exiled.Events.Handlers.Player;
using Server = Exiled.Events.Handlers.Server;
using MEC;
using System;
using System.Collections.Generic;
namespace Overdose
{
public class Overdose : Plugin<Config>
{
public static Overdose Singleton;
public override PluginPriority Priority { get; } = PluginPriority.Medium;
public override string Name { get; } = "Overdose";
public override string Author { get; } = "Steven4547466";
public override Version Version { get; } = new Version(1, 1, 0);
public override Version RequiredExiledVersion { get; } = new Version(4, 1, 2);
public override string Prefix { get; } = "Overdose";
public List<CoroutineHandle> Coroutines = new List<CoroutineHandle>();
public Handlers.Player player { get; set; }
public Handlers.Server server { get; set; }
public bool mainCoroEnabled { get; set; }
public override void OnEnabled()
{
Singleton = this;
if (Overdose.Singleton.Config.IsEnabled == false) return;
base.OnEnabled();
Log.Info("Overdose enabled.");
RegisterEvents();
Coroutines = new List<CoroutineHandle>();
}
public override void OnDisabled()
{
base.OnDisabled();
Log.Info("Overdose disabled.");
UnregisterEvents();
}
public override void OnReloaded()
{
base.OnReloaded();
Log.Info("Overdose reloading.");
}
public void RegisterEvents()
{
player = new Handlers.Player();
Player.ItemUsed += player.OnUsedItem;
Player.Died += player.OnDied;
Player.ChangingRole += player.OnChangingRole;
Player.Left += player.OnLeft;
server = new Handlers.Server();
Server.RoundEnded += server.OnRoundEnded;
Server.RoundStarted += server.OnRoundStarted;
}
public void UnregisterEvents()
{
Log.Info("Events unregistered");
mainCoroEnabled = false;
Player.ItemUsed -= player.OnUsedItem;
Player.Died -= player.OnDied;
Player.ChangingRole -= player.OnChangingRole;
Player.Left -= player.OnLeft;
player = null;
Server.RoundEnded -= server.OnRoundEnded;
Server.RoundStarted -= server.OnRoundStarted;
server = null;
if (Coroutines != null)
{
foreach (CoroutineHandle handle in Coroutines)
{
Log.Debug($"Killed coro {handle}", Overdose.Singleton.Config.Debug);
Timing.KillCoroutines(handle);
}
Coroutines = null;
}
}
}
}