-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoadingScreenText.cs
91 lines (80 loc) · 3.76 KB
/
LoadingScreenText.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
using BattleBitAPI.Common;
using BattleBitAPI.Features;
using BBRAPIModules;
using System.Linq;
using System.Threading.Tasks;
namespace BattleBitBaseModules;
[Module("Configure the loading screen text of your server", "1.0.0")]
[RequireModule(typeof(PlaceholderLib))]
public class LoadingScreenText : BattleBitModule
{
[ModuleReference]
public PlaceholderLib PlaceholderLib { get; set; } = null!;
public LoadingScreenTextConfiguration Configuration { get; set; }
public override Task OnConnected()
{
string LoadingText = new PlaceholderLib(Configuration.LoadingScreenText)
.AddParam("serverName", Server.ServerName)
.AddParam("playerCount", Server.AllPlayers.Count())
.AddParam("maxPlayers", Server.MaxPlayerCount)
.AddParam("gamemode", Server.Gamemode)
.AddParam("map", Server.Map)
.Run();
Server.SetLoadingScreenText(LoadingText);
return Task.CompletedTask;
}
public override Task OnPlayerConnected(RunnerPlayer player)
{
int playerCount = Server.AllPlayers.Count();
string LoadingText = new PlaceholderLib(Configuration.LoadingScreenText)
.AddParam("serverName", Server.ServerName)
.AddParam("playerCount", Server.CurrentPlayerCount + " (+" + Server.InQueuePlayerCount + ")")
.AddParam("maxPlayers", Server.MaxPlayerCount)
.AddParam("gamemode", Server.Gamemode)
.AddParam("map", Server.Map)
.Run();
Server.SetLoadingScreenText(LoadingText);
string WelcomeText = new PlaceholderLib(Configuration.WelcomeText)
.AddParam("serverName", Server.ServerName)
.AddParam("playerCount", Server.CurrentPlayerCount + " (+" + Server.InQueuePlayerCount + ")")
.AddParam("maxPlayers", Server.MaxPlayerCount)
.AddParam("gamemode", Server.Gamemode)
.AddParam("map", Server.Map)
.Run();
player.SayToChat(WelcomeText);
return Task.CompletedTask;
}
public override Task OnPlayerDisconnected(RunnerPlayer player)
{
string LoadingText = new PlaceholderLib(Configuration.LoadingScreenText)
.AddParam("serverName", Server.ServerName)
.AddParam("playerCount", Server.CurrentPlayerCount + " (+" + Server.InQueuePlayerCount + ")")
.AddParam("maxPlayers", Server.MaxPlayerCount)
.AddParam("gamemode", Server.Gamemode)
.AddParam("map", Server.Map)
.Run();
Server.SetLoadingScreenText(LoadingText);
return Task.CompletedTask;
}
public override Task OnGameStateChanged(GameState oldState, GameState newState)
{
string LoadingText = new PlaceholderLib(Configuration.LoadingScreenText)
.AddParam("serverName", Server.ServerName)
.AddParam("playerCount", Server.CurrentPlayerCount + " (+" + Server.InQueuePlayerCount + ")")
.AddParam("maxPlayers", Server.MaxPlayerCount)
.AddParam("gamemode", Server.Gamemode)
.AddParam("map", Server.Map)
.Run();
Server.SetLoadingScreenText(LoadingText);
return Task.CompletedTask;
}
}
public class LoadingScreenTextConfiguration : ModuleConfiguration
{
public string LoadingScreenText { get; set; } = "{#ffaaaa}Welcome to {/}{serverName}{#ffaaaa}!\n" +
"We are currently playing {/}{gamemode}{#ffaaaa} on {/}{map}{#ffaaaa} with {/}{playerCount}{#ffaaaa}/{/}{maxPlayers}{#ffaaaa}!" +
"\nEnjoy your stay!";
public string WelcomeText { get; set; } = "{#ffaaaa}Welcome to {/}{serverName}{#ffaaaa}!\n" +
"We are currently playing {/}{gamemode}{#ffaaaa} on {/}{map}{#ffaaaa} with {/}{playerCount}{#ffaaaa}/{/}{maxPlayers}{#ffaaaa}!" +
"\nEnjoy your stay!";
}