-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPurgePlugins.cs
193 lines (165 loc) · 6 KB
/
PurgePlugins.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using Newtonsoft.Json;
using Oxide.Core;
using System;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("PurgePlugins", "SiCkNeSs", "1.0.2")]
[Description("Unload/Load plugins you specify for purge or other events")]
partial class PurgePlugins : RustPlugin
{
#region Commands
[ConsoleCommand("purge_plugins")]
private void CmdUnload(ConsoleSystem.Arg arg)
{
if (!arg.IsRcon && arg.Connection != null && !arg.IsAdmin)
{
Puts("Not Admin");
return;
}
//reload config incase its been changed since load
LoadConfig();
if (arg.Args == null || arg.Args.Length == 0 || arg.Args[0].ToLower() == "unload")
{
//unload plugins
loadPlugins(configData.LoadPlugins, false);
if (configData.BroadcastUnload)
{
foreach (var broadcastMessage in configData.BroadcastMessagesUnload)
{
if (string.IsNullOrEmpty(configData.BroadcastPrefix))
{
Server.Broadcast(broadcastMessage);
}
else
{
Server.Broadcast(broadcastMessage, configData.BroadcastPrefix);
}
}
}
}
else
{
if (arg.Args[0].ToLower() == "load")
{
//load plugins
loadPlugins(configData.LoadPlugins);
if (configData.BroadcastUnload)
{
foreach (var broadcastMessage in configData.BroadcastMessagesLoad)
{
if (string.IsNullOrEmpty(configData.BroadcastPrefix))
{
Server.Broadcast(broadcastMessage);
}
else
{
Server.Broadcast(broadcastMessage, configData.BroadcastPrefix);
}
}
}
}
}
//10 second delay to allow plugins to load/unload properly before reloading others
timer.Once(configData.ReloadTime, () => reloadPlugins(configData.ReloadPlugins));
}
#endregion Commands
#region Methods
private void reloadPlugins(string[] plugins)
{
foreach (var item in plugins)
{
if (!string.IsNullOrEmpty(item))
{
Puts("Reloading: " + item);
Interface.Oxide.ReloadPlugin(item);
}
}
}
private void loadPlugins(string[] plugins, bool load = true)
{
if (load)
{
//Loading plugins
foreach (var item in plugins)
{
if (!string.IsNullOrEmpty(item))
{
Puts("Loading: " + item);
Interface.Oxide.LoadPlugin(item);
}
}
//exit out of method
return;
}
//unloading
foreach (var item in plugins)
{
if (!string.IsNullOrEmpty(item))
{
Puts("Unloading: " + item);
Interface.Oxide.UnloadPlugin(item);
}
}
}
#endregion Methods
#region ConfigurationFile
private ConfigData configData;
private class ConfigData
{
[JsonProperty("Plugins to load/unload (Case Sensitive)")]
public string[] LoadPlugins = { "TruePVE", "ZoneManager" };
[JsonProperty("Plugins to reload (Case Sensitive)")]
public string[] ReloadPlugins = { "PVxZoneStatus" };
[JsonProperty("Seconds before reloading plugins from reload list (10 default)")]
public int ReloadTime = 10;
[JsonProperty("Broadcast Prefix")]
public string BroadcastPrefix = "ADMIN";
[JsonProperty(PropertyName = "Send broadcasts on unload")]
public bool BroadcastUnload = false;
[JsonProperty("Messages to broadcast on plugin list unload")]
public string[] BroadcastMessagesUnload = { "PURGE IS LIVE!", "PURGE IS LIVE!", "PURGE IS LIVE!" };
[JsonProperty(PropertyName = "Send broadcasts on load")]
public bool BroadcastLoad = false;
[JsonProperty("Messages to broadcast on plugin list load")]
public string[] BroadcastMessagesLoad = { "PURGE IS OVER!", "PURGE IS OVER!", "PURGE IS OVER!" };
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
configData = Config.ReadObject<ConfigData>();
if (configData == null)
{
LoadDefaultConfig();
}
}
catch (Exception ex)
{
PrintError($"The configuration file is corrupted. \n{ex}");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig()
{
PrintWarning("Creating a new configuration file");
configData = new ConfigData();
}
protected override void SaveConfig()
{
Config.WriteObject(configData);
}
#endregion ConfigurationFile
#region Language
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["title1"] = "Purge",
}, this);
}
#endregion Language
}
}