Skip to content

Commit c5231c0

Browse files
committed
Added Permission and Servercmd Function
1 parent a9daf35 commit c5231c0

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

CustomCommands/CustomCommands.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using CounterStrikeSharp.API;
22
using CounterStrikeSharp.API.Core;
33
using CounterStrikeSharp.API.Core.Attributes;
4-
using CounterStrikeSharp.API.Core.Attributes.Registration;
54
using CustomCommands.Model;
65
using Microsoft.Extensions.Logging;
76
using System.Text.Json;

CustomCommands/Functions.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,37 @@ private void AddCommands(Commands com)
3636
AddCommand(aliases[i], com.Description, (player, info) =>
3737
{
3838
if (player == null) return;
39-
RequiresPermissions(player, com.Permissions);
39+
if (!RequiresPermissions(player, com.Permissions))
40+
return;
41+
4042
TriggerMessage(player, com);
4143
ExecuteServerCommands(com);
4244
});
4345
}
4446
}
4547

48+
private bool RequiresPermissions(CCSPlayerController player, PermissionsElement permissions)
49+
{
50+
if (!permissions.ReguiresAllPermissions)
51+
{
52+
foreach (var permission in permissions.PermissionList)
53+
{
54+
if (AdminManager.PlayerHasPermissions(player, new string[]{permission})) return true;
55+
}
56+
PrintToChat(Receiver.Client, player, "You don't have the required permissions to execute this command");
57+
return false;
58+
}
59+
else
60+
{
61+
if (!AdminManager.PlayerHasPermissions(player, permissions.PermissionList.ToArray()))
62+
{
63+
PrintToChat(Receiver.Client, player, "You don't have the required permissions to execute this command");
64+
return false;
65+
}
66+
return true;
67+
}
68+
}
69+
4670
private void ExecuteServerCommands(Commands cmd)
4771
{
4872
if (cmd.ServerCommands.Count == 0) return;

CustomCommands/Model/CenterElement.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
using CounterStrikeSharp.API;
2-
using CounterStrikeSharp.API.Core;
3-
using CounterStrikeSharp.API.Core.Attributes;
4-
using CounterStrikeSharp.API.Core.Attributes.Registration;
5-
using CustomCommands.Model;
6-
using Microsoft.Extensions.Logging;
7-
using System.Text.Json;
81

92
namespace CustomCommands.Model;
103
public class CenterClientElement

CustomCommands/Model/CommandsConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class Commands
1313
}
1414
public class PermissionsElement
1515
{
16-
public bool ReguiresPermissionOr { get; set; } = false;
16+
public bool ReguiresAllPermissions { get; set; } = false;
1717
public List<string> PermissionList { get; set; } = new();
1818
}
1919
public class CenterElement

0 commit comments

Comments
 (0)