-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
85 lines (74 loc) · 2.88 KB
/
Plugin.cs
File metadata and controls
85 lines (74 loc) · 2.88 KB
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
using EffectDisplay.EventHandler;
using EffectDisplay.Features;
using Exiled.API.Features;
using System;
using System.IO;
namespace EffectDisplay
{
public class Plugin : Plugin<Configs>
{
public override string Author { get; } = "notifapi";
public override string Name { get; } = "EffectDisplay";
public override Version Version { get; } = new Version(2, 9, 0);
public override Version RequiredExiledVersion { get; } = new Version(9, 0, 0);
public override bool IgnoreRequiredVersionCheck { get; } = false;
public static Plugin Instance { get; private set; }
public override void OnEnabled()
{
DBCondition();
Instance = this;
ServerSpecifiqManager.Init(Config);
SubscribeEvents();
base.OnEnabled();
if (Config.CheckForUpdate)
{
Version ver = GithubUpdater.GetLatestAsync("NOTIF-API", "EffectDisplay").Result;
if (ver == null || ver == new Version(0, 0, 0))
{
Log.Debug($"[OnEnabled] Failed to check for updates.");
return;
}
else
{
if (Version < ver)
{
Log.Warn($"A new version of the plugin is available: {ver}. You are using version {Version}. Download it from\nhttps://github.com/NOTIF-API/EffectDisplay/releases/latest");
return;
}
}
}
}
public override void OnDisabled()
{
ServerSpecifiqManager.Disable();
UnsubscribeEvents();
Instance = null;
base.OnDisabled();
}
protected void SubscribeEvents()
{
Log.Debug($"[SubscribeEvents] Subscribe to the event.");
Exiled.Events.Handlers.Player.Verified += PlayerEvent.OnVerefied;
}
protected void UnsubscribeEvents()
{
Log.Debug($"[UnsubscribeEvents] Unsubscribe from events.");
Exiled.Events.Handlers.Player.Verified -= PlayerEvent.OnVerefied;
}
// Check directory and file existance for work and create if not exist
private void DBCondition()
{
if (!this.Config.DataBaseEnabled)
{
Log.Warn($"[DBCondition] Database usage has been disabled in the plugin configuration!");
return;
}
else
{
string file_directory = Path.GetDirectoryName(Config.DataPath);
if (!Directory.Exists(file_directory)) Directory.CreateDirectory(file_directory);
if (!File.Exists(Config.DataPath)) File.Create(Config.DataPath).Close();
}
}
}
}