Skip to content

Commit de5b8ca

Browse files
committed
refactor: reorganize player role listing systems
Move the admin and VIP listing systems into the Players.Account.Roles module and improve their presentation by using a consistent MessageDialog layout, role formatting, and color scheme.
1 parent 0173bcc commit de5b8ca

4 files changed

Lines changed: 84 additions & 45 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
namespace CTF.Application.Players.Accounts.Roles;
2+
3+
public class AdminListSystem(
4+
IDialogService dialogService,
5+
IEntityManager entityManager) : ISystem
6+
{
7+
[PlayerCommand("admins")]
8+
public void Show(Player player)
9+
{
10+
List<PlayerInfo> admins = entityManager
11+
.GetComponents<Player>()
12+
.Select(player => player.GetRequiredInfo())
13+
.Where(info => info.RoleId >= RoleId.Moderator)
14+
.OrderByDescending(info => info.RoleId)
15+
.ToList();
16+
17+
if (admins.Count == 0)
18+
{
19+
player.SendClientMessage(Color.Red, Messages.NoAdminsConnected);
20+
return;
21+
}
22+
23+
var content = new StringBuilder();
24+
25+
foreach (PlayerInfo admin in admins)
26+
{
27+
Color color = admin.RoleId switch
28+
{
29+
>= RoleId.Admin => Color.Red,
30+
>= RoleId.Moderator => Color.LightGreen,
31+
_ => Color.White
32+
};
33+
34+
content.AppendLine($"{color}[{admin.RoleId}] {Color.White}{admin.Name}");
35+
}
36+
37+
var dialog = new MessageDialog(
38+
caption: $"Admins: {admins.Count}",
39+
content: content.ToString(),
40+
button1: "Close"
41+
);
42+
43+
dialogService.ShowAsync(player, dialog);
44+
}
45+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
namespace CTF.Application.Players.Accounts.Roles;
2+
3+
public class VIPListSystem(
4+
IEntityManager entityManager,
5+
IDialogService dialogService) : ISystem
6+
{
7+
[PlayerCommand("vips")]
8+
public void Show(Player player)
9+
{
10+
List<PlayerInfo> vips = entityManager
11+
.GetComponents<Player>()
12+
.Select(player => player.GetRequiredInfo())
13+
.Where(info => info.RoleId >= RoleId.VIP)
14+
.ToList();
15+
16+
if (vips.Count == 0)
17+
{
18+
player.SendClientMessage(Color.Red, Messages.NoVIPsConnected);
19+
return;
20+
}
21+
22+
var content = new StringBuilder();
23+
Color vipColor = Color.Yellow;
24+
25+
foreach (PlayerInfo vip in vips)
26+
{
27+
content.AppendLine($"{vipColor}[VIP] {Color.White}{vip.Name}");
28+
}
29+
30+
var dialog = new MessageDialog(
31+
caption: $"VIPs: {vips.Count}",
32+
content: content.ToString(),
33+
button1: "Close"
34+
);
35+
36+
dialogService.ShowAsync(player, dialog);
37+
}
38+
}

src/Application/Players/GeneralCommands/Public/PublicCommands.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,51 +40,6 @@ public void Kill(Player player)
4040
player.Health = 0;
4141
}
4242

43-
[PlayerCommand("admins")]
44-
public void ShowAdmins(Player currentPlayer)
45-
{
46-
IEnumerable<PlayerInfo> admins = entityManager
47-
.GetComponents<Player>()
48-
.Select(player => player.GetRequiredInfo())
49-
.Where(playerInfo => playerInfo.RoleId >= RoleId.Moderator)
50-
.OrderByDescending(playerInfo => playerInfo.RoleId);
51-
52-
int count = admins.Count();
53-
if (count == 0)
54-
{
55-
currentPlayer.SendClientMessage(Color.Red, Messages.NoAdminsConnected);
56-
return;
57-
}
58-
var dialog = new ListDialog(caption: $"Admins: {count}", "Close", "");
59-
foreach (PlayerInfo playerInfo in admins)
60-
{
61-
dialog.Add(playerInfo.Name);
62-
}
63-
dialogService.ShowAsync(currentPlayer, dialog);
64-
}
65-
66-
[PlayerCommand("vips")]
67-
public void ShowVIPs(Player currentPlayer)
68-
{
69-
IEnumerable<PlayerInfo> vips = entityManager
70-
.GetComponents<Player>()
71-
.Select(player => player.GetRequiredInfo())
72-
.Where(playerInfo => playerInfo.RoleId >= RoleId.VIP);
73-
74-
int count = vips.Count();
75-
if (count == 0)
76-
{
77-
currentPlayer.SendClientMessage(Color.Red, Messages.NoVIPsConnected);
78-
return;
79-
}
80-
var dialog = new ListDialog(caption: $"VIPs: {count}", "Close", "");
81-
foreach (PlayerInfo playerInfo in vips)
82-
{
83-
dialog.Add(playerInfo.Name);
84-
}
85-
dialogService.ShowAsync(currentPlayer, dialog);
86-
}
87-
8843
[PlayerCommand("report")]
8944
public void ReportPlayer(
9045
Player currentPlayer,

src/Application/Usings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
global using System.Text.Json;
22
global using System.Numerics;
3+
global using System.Text;
34
global using System.Collections;
45
global using System.Globalization;
56
global using System.Text.RegularExpressions;

0 commit comments

Comments
 (0)