Skip to content

Commit

Permalink
Working custom server commands
Browse files Browse the repository at this point in the history
  • Loading branch information
ValMadBox committed Mar 1, 2024
1 parent 5bf966f commit 5d58465
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ public class Discord
public string DiscordPenaltyWebhook { get; set; } = "";
}

public class CustomServerCommandData
{
[JsonPropertyName("Flag")]
public string Flag { get; set; } = "@css/generic";
[JsonPropertyName("DisplayName")]
public string DisplayName { get; set; } = "";
[JsonPropertyName("Command")]
public string Command { get; set; } = "";
}

public class CS2_SimpleAdminConfig : BasePluginConfig
{
public override int Version { get; set; } = 6;
Expand Down Expand Up @@ -54,5 +64,8 @@ public class CS2_SimpleAdminConfig : BasePluginConfig

[JsonPropertyName("WorkshopMaps")]
public List<string> WorkshopMaps { get; set; } = new List<string>();

[JsonPropertyName("CustomServerCommands")]
public List<CustomServerCommandData> CustomServerCommands { get; set; } = new List<CustomServerCommandData>();
}
}
16 changes: 15 additions & 1 deletion Menus/ManageServerMenu.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Menu;
Expand Down Expand Up @@ -34,6 +35,19 @@ public static void OpenMenu(CCSPlayerController admin)

options.Add(new ChatMenuOptionData("Restart Game", () => CS2_SimpleAdmin.RestartGame(admin)));

List<CustomServerCommandData> customCommands = CS2_SimpleAdmin.Instance.Config.CustomServerCommands;
foreach (CustomServerCommandData customCommand in customCommands)
{
if (string.IsNullOrEmpty(customCommand.DisplayName) || string.IsNullOrEmpty(customCommand.Command))
continue;

bool hasRights = AdminManager.PlayerHasPermissions(admin, customCommand.Flag);
if (!hasRights)
continue;

options.Add(new ChatMenuOptionData(customCommand.DisplayName, () => Server.ExecuteCommand(customCommand.Command)));
}

foreach (ChatMenuOptionData menuOptionData in options)
{
string menuName = menuOptionData.name;
Expand All @@ -48,7 +62,7 @@ public static void ChangeMapMenu(CCSPlayerController admin)
BaseMenu menu = AdminMenu.CreateMenu($"Change Map");
List<ChatMenuOptionData> options = new();

List<string> maps = CS2_SimpleAdmin.Instance.Config.DefaultMaps;//Server.GetMapList();
List<string> maps = CS2_SimpleAdmin.Instance.Config.DefaultMaps;
foreach (string map in maps)
{
options.Add(new ChatMenuOptionData(map, () => ExecuteChangeMap(admin, map, false)));
Expand Down

0 comments on commit 5d58465

Please sign in to comment.