mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-18 10:43:23 +00:00
Moved custom commands to its specific menu
This commit is contained in:
@@ -45,6 +45,12 @@ namespace CS2_SimpleAdmin.Menus
|
|||||||
new ChatMenuOptionData("Fun actions", () => FunActionsMenu.OpenMenu(admin)),
|
new ChatMenuOptionData("Fun actions", () => FunActionsMenu.OpenMenu(admin)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
List<CustomServerCommandData> customCommands = CS2_SimpleAdmin.Instance.Config.CustomServerCommands;
|
||||||
|
if (customCommands.Count > 0)
|
||||||
|
{
|
||||||
|
options.Add(new ChatMenuOptionData("Custom Commands", () => CustomCommandsMenu.OpenMenu(admin)));
|
||||||
|
}
|
||||||
|
|
||||||
if (AdminManager.PlayerHasPermissions(admin, "@css/root"))
|
if (AdminManager.PlayerHasPermissions(admin, "@css/root"))
|
||||||
options.Add(new ChatMenuOptionData("Manage Admins", () => ManageAdminsMenu.OpenMenu(admin)));
|
options.Add(new ChatMenuOptionData("Manage Admins", () => ManageAdminsMenu.OpenMenu(admin)));
|
||||||
|
|
||||||
|
|||||||
47
Menus/CustomCommandsMenu.cs
Normal file
47
Menus/CustomCommandsMenu.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
using CounterStrikeSharp.API;
|
||||||
|
using CounterStrikeSharp.API.Core;
|
||||||
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
|
using CounterStrikeSharp.API.Modules.Menu;
|
||||||
|
|
||||||
|
namespace CS2_SimpleAdmin.Menus
|
||||||
|
{
|
||||||
|
public static class CustomCommandsMenu
|
||||||
|
{
|
||||||
|
public static void OpenMenu(CCSPlayerController admin)
|
||||||
|
{
|
||||||
|
if (admin == null || admin.IsValid == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (AdminManager.PlayerHasPermissions(admin, "@css/generic") == false)
|
||||||
|
{
|
||||||
|
// TODO: Localize
|
||||||
|
admin.PrintToChat("[Simple Admin] You do not have permissions to use this command.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseMenu menu = AdminMenu.CreateMenu("Custom Commands");
|
||||||
|
List<ChatMenuOptionData> options = new();
|
||||||
|
|
||||||
|
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;
|
||||||
|
menu.AddMenuOption(menuName, (_, _) => { menuOptionData.action?.Invoke(); }, menuOptionData.disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
AdminMenu.OpenMenu(admin, menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
using CounterStrikeSharp.API;
|
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Admin;
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
using CounterStrikeSharp.API.Modules.Menu;
|
using CounterStrikeSharp.API.Modules.Menu;
|
||||||
@@ -35,19 +34,6 @@ namespace CS2_SimpleAdmin.Menus
|
|||||||
|
|
||||||
options.Add(new ChatMenuOptionData("Restart Game", () => CS2_SimpleAdmin.RestartGame(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)
|
foreach (ChatMenuOptionData menuOptionData in options)
|
||||||
{
|
{
|
||||||
string menuName = menuOptionData.name;
|
string menuName = menuOptionData.name;
|
||||||
|
|||||||
Reference in New Issue
Block a user