-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPurge.cs
157 lines (138 loc) · 5.48 KB
/
Purge.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
//████████╗ █████╗ ██████╗███╗ ███╗ █████╗ ███╗ ██╗
//╚══██╔══╝██╔══██╗██╔════╝████╗ ████║ ██╔══██╗████╗ ██║
// ██║ ███████║██║ ██╔████╔██║ ███████║██╔██╗ ██║
// ██║ ██╔══██║██║ ██║╚██╔╝██║ ██╔══██║██║╚██╗██║
// ██║ ██║ ██║╚██████╗██║ ╚═╝ ██║ ██║ ██║██║ ╚████║
// ╚═╝ ╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝
using System;
using System.Collections.Generic;
using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Core.Libraries.Covalence;
using Rust;
using UnityEngine;
using Oxide.Game.Rust.Cui;
namespace Oxide.Plugins
{
[Info("Purge", "Tacman", "0.0.5")]
[Description("A plugin to unload specified plugins")]
public class Purge : CovalencePlugin
{
private const string PurgePermission = "purge.use";
private const int CooldownSeconds = 3000000;
private readonly Dictionary<string, DateTime> _commandCooldowns = new Dictionary<string, DateTime>();
private List<string> _pluginsToUnload;
private bool _isPurgeActive = false;
private void Init()
{
permission.RegisterPermission(PurgePermission, this);
LoadConfigValues();
}
protected override void LoadDefaultConfig()
{
Config["PluginsToUnload"] = new List<string>
{
"TruePVE",
"LootDefender",
"PreventLooting"
};
}
private void LoadConfigValues()
{
_pluginsToUnload = Config.Get<List<string>>("PluginsToUnload");
}
[Command("purge")]
private void PurgeCommand(IPlayer player, string command, string[] args)
{
if (!player.HasPermission(PurgePermission))
{
player.Message("You don't have permission to use this command.");
return;
}
DateTime currentTime = DateTime.UtcNow;
if (_commandCooldowns.TryGetValue(player.Id, out DateTime lastUsage))
{
double remainingCooldown = CooldownSeconds - (currentTime - lastUsage).TotalSeconds;
if (remainingCooldown > 0)
{
player.Message($"Command is on cooldown. Please wait {Math.Ceiling(remainingCooldown)} seconds before using it again.");
return;
}
}
if (_pluginsToUnload == null)
{
Puts("Plugins to unload field is empty, nothing has been unloaded");
player.Reply("There are no plugins set to unload, is this intentional?");
return;
}
foreach (string pluginName in _pluginsToUnload)
{
string consoleCmd = $"o.unload {pluginName}";
ConsoleSystem.Run(ConsoleSystem.Option.Server, consoleCmd);
}
player.Message("Unloading specified plugins...");
server.Broadcast("Purge has begun, PVP is now active!");
ShowPurgeUI();
_isPurgeActive = true;
_commandCooldowns[player.Id] = currentTime;
}
private void ShowPurgeUI()
{
var elements = new CuiElementContainer();
var panel = new CuiButton
{
Button =
{
Command = string.Empty,
Color = "0 0 0 0",
},
RectTransform =
{
AnchorMin = "0.45 0.85",
AnchorMax = "0.55 0.95"
},
Text = { Text = string.Empty }
};
elements.Add(panel, "Hud", "PurgePanel");
var label = new CuiLabel
{
RectTransform =
{
AnchorMin = "0 0",
AnchorMax = "1 1"
},
Text =
{
Text = "Purge Active!! PVP Enabled!!!",
FontSize = 12,
Align = TextAnchor.MiddleCenter,
Color = "1 0 0 1"
}
};
elements.Add(label, "PurgePanel");
foreach (var player in BasePlayer.activePlayerList)
{
CuiHelper.AddUi(player, elements);
}
}
private void OnPlayerConnected(BasePlayer player)
{
if (player != null && _isPurgeActive)
{
ShowPurgeUI();
}
}
private void OnPlayerDisconnected(BasePlayer player)
{
CuiHelper.DestroyUi(player, "PurgePanel");
}
private void Unload()
{
foreach (var player in BasePlayer.activePlayerList)
{
CuiHelper.DestroyUi(player, "PurgePanel");
_isPurgeActive = false;
}
}
}
}