diff --git a/CustomCommands/Commands.json b/CustomCommands/Commands.json index fbc63e4..a45da57 100644 --- a/CustomCommands/Commands.json +++ b/CustomCommands/Commands.json @@ -27,15 +27,16 @@ "sv_cheats 1", "sv_falldamage_scale 0", "sv_party_mode 1", - "mp_freezetime 2.5", - "mp_round_restart_delay 2.5", + "mp_freezetime 1", + "mp_round_restart_delay 2", "cl_ragdoll_gravity 0", "sv_accelerate 10", "sv_airaccelerate 1400", - "sv_gravity 800.0" + "sv_gravity 800.0", + "say hello" ], "Permission": { - "ReguiresPermissionOr": false, + "ReguiresAllPermissions": false, "PermissionList": [ "@css/cvar", "@custom/permission", diff --git a/CustomCommands/CustomCommands.cs b/CustomCommands/CustomCommands.cs index 865ce55..45bbf27 100644 --- a/CustomCommands/CustomCommands.cs +++ b/CustomCommands/CustomCommands.cs @@ -1,7 +1,6 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes; -using CounterStrikeSharp.API.Core.Attributes.Registration; using CustomCommands.Model; using Microsoft.Extensions.Logging; using System.Text.Json; diff --git a/CustomCommands/Functions.cs b/CustomCommands/Functions.cs index 45b7422..d15ff5c 100644 --- a/CustomCommands/Functions.cs +++ b/CustomCommands/Functions.cs @@ -1,6 +1,7 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Modules.Admin; +using CounterStrikeSharp.API.Modules.Entities.Constants; using CustomCommands.Model; namespace CustomCommands; @@ -27,6 +28,7 @@ private void RegisterListeners() }); } + private void AddCommands(Commands com) { string[] aliases = com.Command.Split(','); @@ -36,13 +38,40 @@ private void AddCommands(Commands com) AddCommand(aliases[i], com.Description, (player, info) => { if (player == null) return; - RequiresPermissions(player, com.Permissions); + + if (com.Permission.PermissionList.Count >= 1) + if (!RequiresPermissions(player, com.Permission)) + return; + TriggerMessage(player, com); ExecuteServerCommands(com); }); } } + private bool RequiresPermissions(CCSPlayerController player, Permission permissions) + { + if (!permissions.ReguiresAllPermissions) + { + foreach (var permission in permissions.PermissionList) + { + if (AdminManager.PlayerHasPermissions(player, new string[]{permission})) + return true; + } + PrintToChat(Receiver.Client, player, "You don't have the required permissions to execute this command"); + return false; + } + else + { + if (!AdminManager.PlayerHasPermissions(player, permissions.PermissionList.ToArray())) + { + PrintToChat(Receiver.Client, player, "You don't have the required permissions to execute this command"); + return false; + } + return true; + } + } + private void ExecuteServerCommands(Commands cmd) { if (cmd.ServerCommands.Count == 0) return; diff --git a/CustomCommands/Model/CenterElement.cs b/CustomCommands/Model/CenterElement.cs index 03648ad..c442f67 100644 --- a/CustomCommands/Model/CenterElement.cs +++ b/CustomCommands/Model/CenterElement.cs @@ -1,10 +1,3 @@ -using CounterStrikeSharp.API; -using CounterStrikeSharp.API.Core; -using CounterStrikeSharp.API.Core.Attributes; -using CounterStrikeSharp.API.Core.Attributes.Registration; -using CustomCommands.Model; -using Microsoft.Extensions.Logging; -using System.Text.Json; namespace CustomCommands.Model; public class CenterClientElement diff --git a/CustomCommands/Model/CommandsConfig.cs b/CustomCommands/Model/CommandsConfig.cs index d32ebbb..b896081 100644 --- a/CustomCommands/Model/CommandsConfig.cs +++ b/CustomCommands/Model/CommandsConfig.cs @@ -9,11 +9,11 @@ public class Commands public CenterElement CenterMessage { get; set; } = new(); public required Sender PrintTo { get; set; } = Sender.ClientChat; public List ServerCommands { get; set; } = new(); - public PermissionsElement Permissions { get; set; } = new(); + public Permission Permission { get; set; } = new(); } -public class PermissionsElement +public class Permission { - public bool ReguiresPermissionOr { get; set; } = false; + public bool ReguiresAllPermissions { get; set; } = false; public List PermissionList { get; set; } = new(); } public class CenterElement diff --git a/README.md b/README.md index 907602c..23a90a6 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ -## Custom Commands Plugin +# Custom Commands Plugin Readme -Create your custom commands in ./plugins/CustomCommands/Commands.json +## Overview -#### Example +The Custom Commands Plugin allows you to create and customize commands for your server. These commands can display messages, perform server-side actions, and more. The configuration for these commands is stored in the `Commands.json` file located in the `./plugins/CustomCommands/` directory. + +## Example Configuration ```json [ @@ -10,9 +12,6 @@ Create your custom commands in ./plugins/CustomCommands/Commands.json "Title": "Discord", "Command": "discord", "Message": "{PREFIX}{GREEN}Discord: \n ", - "CenterMessage": "", - "CenterMessageTime": 1, - "PrintTo": 0, "Description": "Command for Discord" }, { @@ -23,54 +22,89 @@ Create your custom commands in ./plugins/CustomCommands/Commands.json "CenterMessageTime": 2, "PrintTo": 7, "Description": "Command for SteamGroup" + }, + { + "Title": "Enable Surf", + "Command": "surf", + "Message": "Surf is now enabled", + "PrintTo": 0, + "Description": "Command for enabling Surf gamemode", + "ServerCommands": [ + "sv_cheats 1", + "sv_falldamage_scale 0", + "sv_party_mode 1", + "mp_freezetime 2.5", + "mp_round_restart_delay 2.5", + "cl_ragdoll_gravity 0", + "sv_accelerate 10", + "sv_airaccelerate 1400", + "sv_gravity 800.0" + ], + "Permission": { + "RequiresPermissionOr": false, + "PermissionList": [ + "@css/cvar", + "@custom/permission", + "#css/simple-admin" + ] + } } ] ``` -**Title**: Just the title for your +## Configuration Details + +### Title + +Just the title for your command. Can be anything or empty. + +### Command + +Specify the commands as a string, e.g., "discord" or "steam,steamgroup,group". Players can use `!discord` or `/discord` in the chat or css_discord in the console. + +### Message + +The message you want to send. You can use color codes like {GREEN} for green text. + +### CenterMessage + +The center message. For special formating use HTML + +### PrintTo + +Specifies where the message should be shown: + +- **0**: Client Chat +- **1**: All Chat +- **2**: Client Center +- **3**: All Center +- **4**: Client Chat & Client Center +- **5**: Client Chat & All Center +- **6**: All Chat & Client Center +- **7**: All Chat & All Center + +### Description -**Command:** just type the name. !`` and /`` will work normally +A description of what the command does. This will be shown when do css_help -**Message**: The message you want to send. +### ServerCommands -Colors: +An array of server commands to be executed when the command is triggered. Useful for actions like enabling specific game modes. -* {DEFAULT} -* {RED} -* {LIGHTPURPLE} -* {GREEN} -* {LIME} -* {LIGHTGREEN} -* {LIGHTRED} -* {GRAY} -* {LIGHTOLIVE} -* {OLIVE} -* {LIGHTBLUE} -* {BLUE} -* {PURPLE} -* {GRAYBLUE} +### Permission -**CenterMessage**: The Center Message. HTML works as well. +Defines if the command requires specific permissions to execute: -**PrintTo**: Where the message should be shown +- **ReguiresAllPermissions** + - Set to true = The player needs all permissions in PermissionsList + - Set to false = The player only needs one of the permissions in PermissionsList +- **PermissionList**: A list of permission flags or groups required to execute the command. [More Explenation](https://docs.cssharp.dev/docs/admin-framework/defining-admins.html) -| Desc | Nr | -| --------------------------- | -- | -| Client Chat | 0 | -| All Chat | 1 | -| Client Center | 2 | -| All Center | 3 | -| Client Chat & Client Center | 4 | -| Client Chat & All Center | 5 | -| All Chat & Client Center | 6 | -| All Chat & All Center | 7 | +### Colorlist -**Description**: What the Description for the command should be +{DEFAULT}, {RED}, {LIGHTPURPLE}, {GREEN}, {LIME}, +{LIGHTGREEN}, {LIGHTRED}, {GRAY}, {LIGHTOLIVE}, +{OLIVE}, {LIGHTBLUE}, {BLUE}, {PURPLE}, {GRAYBLUE} -## Roadmap -* [ ] Send Server Commands -* [ ] Set permissions -* [ ] On Off toggle -* [ ] Allow Args