-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrHelp.cs
More file actions
280 lines (235 loc) · 10.5 KB
/
rHelp.cs
File metadata and controls
280 lines (235 loc) · 10.5 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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Oxide.Plugins
{
[Info("rHelp", "Ftuoil Xelrash", "0.0.43")]
[Description("Displays help information and server commands on join and via !help command")]
public class rHelp : RustPlugin
{
#region Configuration
private ConfigData config;
private Dictionary<string, DateTime> playerCooldowns = new Dictionary<string, DateTime>();
public class ConfigData
{
[JsonProperty("Settings")] public PluginSettings Settings;
}
public class PluginSettings
{
[JsonProperty("Enable !help Command")] public bool EnableHelpCommand = true;
[JsonProperty("Command Cooldown (minutes)")] public float CommandCooldown = 5f;
[JsonProperty("Show Help Command Info in Join Message")] public bool ShowHelpInJoin = true;
[JsonProperty("Join Message Delay (seconds)")] public float JoinMessageDelay = 1f;
[JsonProperty("Join Message")] public List<string> JoinMessage;
[JsonProperty("Join Message Color")] public string JoinMessageColor = "00FFFF"; // Dark Blue
[JsonProperty("Send Join Message to Console")] public bool SendJoinToConsole = false;
[JsonProperty("Help Message - Title")] public string HelpMessageTitle = "Player Commands Guide";
[JsonProperty("Help Message Color")] public string HelpMessageColor = "FFFF00"; // Yellow
[JsonProperty("Send Help Message to Console")] public bool SendHelpToConsole = false;
[JsonProperty("Help Message - Content")] public List<string> HelpMessageContent;
}
private List<string> GetDefaultJoinMessage()
{
return new List<string>
{
"Welcome to the server {player}!",
"Type !help to see available commands and features available on {server}."
};
}
private List<string> GetDefaultHelpContent()
{
return new List<string>
{
"",
"ECONOMICS:",
"/balance - Check your current Economics balance",
"",
"POPULATION:",
"!pop - Show server statistics in chat",
" Online/sleeping players count",
"",
"RAIDABLE BASES:",
"/buyraid - Buy a private Raidable Base!",
"",
"SCHEDULED RESTARTS & WIPES:",
"!restart - Shows servers next scheduled restart in chat",
"!wipe(COMING SOON!) - Shows servers next scheduled wipe date/time in chat",
"",
"SIGN ARTIST:",
"/sil <url> - Load image from URL onto sign you're looking at",
" Example: /sil https://example.com/image.jpg",
" Add raw for raw format",
"/silt <message> - Create text on signs",
" Example: /silt Hello World",
"/silrestore - Restore sign to original texture",
"",
"PLAYER STATS:",
"/stats - Check your current player stats",
""
};
}
protected override void LoadDefaultConfig()
{
config = new ConfigData();
config.Settings = new PluginSettings();
config.Settings.JoinMessage = GetDefaultJoinMessage();
config.Settings.HelpMessageContent = GetDefaultHelpContent();
SaveConfig();
Puts("Default configuration created.");
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<ConfigData>();
if (config == null || config.Settings == null)
{
LoadDefaultConfig();
return;
}
if (config.Settings.JoinMessage == null)
config.Settings.JoinMessage = GetDefaultJoinMessage();
if (config.Settings.HelpMessageContent == null)
config.Settings.HelpMessageContent = GetDefaultHelpContent();
}
catch (Exception ex)
{
PrintError($"Error loading configuration: {ex.Message}");
LoadDefaultConfig();
}
}
protected override void SaveConfig()
{
Config.WriteObject(config);
}
#endregion
#region Hooks
private void Init()
{
LoadConfig();
}
private void OnUserConnected(IPlayer player)
{
if (!config.Settings.EnableHelpCommand)
return;
BasePlayer basePlayer = player.Object as BasePlayer;
if (basePlayer == null)
return;
// Replace placeholders in join message
string serverName = ConVar.Server.hostname ?? "Unknown Server";
int onlinePlayers = BasePlayer.activePlayerList.Count;
int maxPlayers = ConVar.Server.maxplayers;
int sleepingPlayers = BasePlayer.sleepingPlayerList.Count;
// Build the full join message from all lines
string fullJoinMessage = "";
string consoleJoinMessage = "";
foreach (var line in config.Settings.JoinMessage)
{
string processedLine = line
.Replace("{player}", player.Name)
.Replace("{server}", serverName)
.Replace("{online_players}", onlinePlayers.ToString())
.Replace("{max_players}", maxPlayers.ToString())
.Replace("{sleeping_players}", sleepingPlayers.ToString())
.Replace("{player_count}", $"{onlinePlayers}/{maxPlayers}");
fullJoinMessage += processedLine + "\n";
consoleJoinMessage += processedLine + "\n";
}
// Remove trailing newline
fullJoinMessage = fullJoinMessage.TrimEnd();
consoleJoinMessage = consoleJoinMessage.TrimEnd();
// Add color to message for chat
string coloredMessage = $"<color=#{config.Settings.JoinMessageColor}>{fullJoinMessage}</color>";
// Send to chat as one message
basePlayer.ChatMessage(coloredMessage);
// Send to console if enabled (plain text, no colors)
if (config.Settings.SendJoinToConsole)
{
basePlayer.ConsoleMessage(consoleJoinMessage);
}
}
private object OnPlayerChat(BasePlayer player, string message, ConVar.Chat.ChatChannel channel)
{
if (player == null || string.IsNullOrEmpty(message))
return null;
if (message.ToLower() == "!help")
{
HandleHelpCommand(player);
return true; // suppress from public chat
}
return null;
}
[ChatCommand("help")]
private void HelpSlashCommand(BasePlayer player, string command, string[] args)
{
HandleHelpCommand(player);
}
#endregion
#region Help Command
private void HandleHelpCommand(BasePlayer player)
{
if (!config.Settings.EnableHelpCommand)
{
player.ChatMessage("The !help command is currently disabled.");
return;
}
var now = DateTime.Now;
string playerId = player.UserIDString;
if (playerCooldowns.TryGetValue(playerId, out DateTime lastUse))
{
var timeSinceLastUse = now - lastUse;
if (timeSinceLastUse.TotalMinutes < config.Settings.CommandCooldown)
{
var remainingTime = TimeSpan.FromMinutes(config.Settings.CommandCooldown) - timeSinceLastUse;
player.ChatMessage($"Help command is on cooldown. Try again in {GetCooldownTime(remainingTime)}.");
return;
}
}
playerCooldowns[playerId] = now;
// Get placeholder values for help message
string serverName = ConVar.Server.hostname ?? "Unknown Server";
int onlinePlayers = BasePlayer.activePlayerList.Count;
int maxPlayers = ConVar.Server.maxplayers;
int sleepingPlayers = BasePlayer.sleepingPlayerList.Count;
// Process content lines with placeholder replacement
var processedContent = new List<string>();
foreach (var line in config.Settings.HelpMessageContent)
{
string processedLine = line
.Replace("{player}", player.displayName)
.Replace("{server}", serverName)
.Replace("{online_players}", onlinePlayers.ToString())
.Replace("{max_players}", maxPlayers.ToString())
.Replace("{sleeping_players}", sleepingPlayers.ToString())
.Replace("{player_count}", $"{onlinePlayers}/{maxPlayers}");
processedContent.Add(processedLine);
}
// Build help message
string headerLine = "=".PadRight(config.Settings.HelpMessageTitle.Length, '=');
string helpMessage = config.Settings.HelpMessageTitle + "\n" + headerLine + "\n\n" + string.Join("\n", processedContent);
string consoleHelpMessage = config.Settings.HelpMessageTitle + "\n" + headerLine + "\n\n" + string.Join("\n", processedContent);
// Add color for chat
string coloredHelpMessage = $"<color=#{config.Settings.HelpMessageColor}>{helpMessage}</color>";
// Send to chat as one message
player.ChatMessage(coloredHelpMessage);
// Send to console if enabled (plain text, no colors)
if (config.Settings.SendHelpToConsole)
{
player.ConsoleMessage(consoleHelpMessage);
}
}
private string GetCooldownTime(TimeSpan timeSpan)
{
if (timeSpan.TotalSeconds < 60)
return $"{(int)timeSpan.TotalSeconds} seconds";
else if (timeSpan.TotalMinutes < 60)
return $"{(int)timeSpan.TotalMinutes} minute{((int)timeSpan.TotalMinutes != 1 ? "s" : "")}";
else
return $"{(int)timeSpan.TotalHours} hour{((int)timeSpan.TotalHours != 1 ? "s" : "")}";
}
#endregion
}
}