This repository has been archived by the owner on May 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Welcome.cs
74 lines (63 loc) · 1.84 KB
/
Welcome.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
using Oxide.Core;
using System;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Oxide.Plugins
{
[Info("Welcome", "Auro", "1.0.0")]
[Description("Sends a welcome message to players")]
public class Welcome : RustPlugin
{
void OnPlayerConnected(BasePlayer player)
{
player.ChatMessage(config.welcomeMessage.Replace("{players}", BasePlayer.activePlayerList.Count.ToString()));
}
private static ConfigData config;
private class ConfigData
{
[JsonProperty(PropertyName = "Welcome Message")]
public string welcomeMessage;
}
private ConfigData GetDefaultConfig()
{
return new ConfigData
{
welcomeMessage = "Welcome to the Server",
};
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<ConfigData>();
if (config == null)
{
LoadDefaultConfig();
}
}
catch
{
PrintError("Configuration file is corrupt! Check your config file at https://jsonlint.com/");
timer.Every(10f, () =>
{
PrintError("Configuration file is corrupt! Check your config file at https://jsonlint.com/");
});
LoadDefaultConfig();
return;
}
SaveConfig();
}
protected override void LoadDefaultConfig()
{
config = GetDefaultConfig();
}
protected override void SaveConfig()
{
Config.WriteObject(config);
}
}
}