Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions CustomCommands/Commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion CustomCommands/CustomCommands.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
31 changes: 30 additions & 1 deletion CustomCommands/Functions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -27,6 +28,7 @@ private void RegisterListeners()

});
}

private void AddCommands(Commands com)
{
string[] aliases = com.Command.Split(',');
Expand All @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions CustomCommands/Model/CenterElement.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions CustomCommands/Model/CommandsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public class Commands
public CenterElement CenterMessage { get; set; } = new();
public required Sender PrintTo { get; set; } = Sender.ClientChat;
public List<string> 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<string> PermissionList { get; set; } = new();
}
public class CenterElement
Expand Down
118 changes: 76 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
## 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
[
{
"Title": "Discord",
"Command": "discord",
"Message": "{PREFIX}{GREEN}Discord: \n <link>",
"CenterMessage": "",
"CenterMessageTime": 1,
"PrintTo": 0,
"Description": "Command for Discord"
},
{
Expand All @@ -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. !`<command>` and /`<command>` 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