Skip to content

Commit 78df369

Browse files
authored
v1.1.6
feat: players with admin flag are not shown in the list of names or counted in case they are in the spectator team or none (to be compatible with /hide command of simpleadmin); you can enable or disable this logic by setting `DontCountAdmins` to false
2 parents 0fb5477 + 9383d33 commit 78df369

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

Config.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public class BaseConfigs : BasePluginConfig
4141
[JsonPropertyName("CommandCooldownSeconds")]
4242
public int CommandCooldownSeconds { get; set; } = 120;
4343

44+
[JsonPropertyName("DontCountAdmins")]
45+
public bool DontCountAdmins { get; set; } = false;
46+
47+
[JsonPropertyName("AdminBypassFlag")]
48+
public string AdminBypassFlag { get; set; } = "@css/generic";
49+
4450
[JsonPropertyName("Command")]
4551
public List<string> Command { get; set; } = new List<string> { "css_need", ".need" };
4652

NeedSystem.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using CounterStrikeSharp.API.Modules.Commands;
77
using CounterStrikeSharp.API.Modules.Cvars;
88
using CounterStrikeSharp.API.Core.Attributes;
9+
using CounterStrikeSharp.API.Modules.Utils;
10+
using CounterStrikeSharp.API.Modules.Admin;
911

1012
namespace NeedSystem;
1113

@@ -17,7 +19,7 @@ public class NeedSystemBase : BasePlugin, IPluginConfig<BaseConfigs>
1719
private Translator _translator;
1820

1921
public override string ModuleName => "NeedSystem";
20-
public override string ModuleVersion => "1.1.5";
22+
public override string ModuleVersion => "1.1.6";
2123
public override string ModuleAuthor => "luca.uy";
2224
public override string ModuleDescription => "Allows players to send a message to discord requesting players.";
2325

@@ -146,7 +148,25 @@ private bool CheckCommandCooldown(out int secondsRemaining)
146148
public int GetNumberOfPlayers()
147149
{
148150
var players = Utilities.GetPlayers();
149-
return players.Count(p => !p.IsBot && !p.IsHLTV);
151+
return players.Where(p => !p.IsBot && !p.IsHLTV && ShouldShowPlayerInList(p)).Count();
152+
}
153+
154+
private bool ShouldShowPlayerInList(CCSPlayerController player)
155+
{
156+
if (!Config.DontCountAdmins || string.IsNullOrEmpty(Config.AdminBypassFlag))
157+
return true;
158+
159+
try
160+
{
161+
if (!AdminManager.PlayerHasPermissions(player, Config.AdminBypassFlag))
162+
return true;
163+
164+
return player.Team == CsTeam.Terrorist || player.Team == CsTeam.CounterTerrorist;
165+
}
166+
catch
167+
{
168+
return true;
169+
}
150170
}
151171

152172
private int ConvertHexToColor(string hex)
@@ -172,6 +192,7 @@ public void NeedCommand(CCSPlayerController? caller, string clientName)
172192
{
173193
var players = Utilities.GetPlayers()
174194
.Where(p => !p.IsBot && !p.IsHLTV && p.Connected == PlayerConnectedState.PlayerConnected)
195+
.Where(ShouldShowPlayerInList)
175196
.Select(p => new { p.PlayerName, p.SteamID })
176197
.ToList();
177198

@@ -294,7 +315,7 @@ private async Task SendEmbedToDiscord(object embed)
294315

295316
var payload = new
296317
{
297-
content = content,
318+
content,
298319
embeds = new[] { embed }
299320
};
300321

0 commit comments

Comments
 (0)