- Config upgrade
- Translatable  and customizable menu
- More async
- Minor changes
This commit is contained in:
Dawid Bepierszcz
2024-04-29 00:04:42 +02:00
parent aefa6c6355
commit c321502937
37 changed files with 1078 additions and 701 deletions

View File

@@ -1,7 +1,6 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Menu;
namespace CS2_SimpleAdmin.Menus
{
@@ -9,44 +8,41 @@ namespace CS2_SimpleAdmin.Menus
{
public static void OpenMenu(CCSPlayerController admin)
{
if (admin == null || admin.IsValid == false)
if (admin.IsValid == false)
return;
var localizer = CS2_SimpleAdmin._localizer;
if (AdminManager.PlayerHasPermissions(admin, "@css/generic") == false)
{
// TODO: Localize
admin.PrintToChat("[Simple Admin] You do not have permissions to use this command.");
admin.PrintToChat(localizer?["sa_prefix"] ??
"[SimpleAdmin] " +
(localizer?["sa_no_permission"] ?? "You do not have permissions to use this command")
);
return;
}
BaseMenu menu = AdminMenu.CreateMenu("Custom Commands");
List<ChatMenuOptionData> options = new();
var menu = AdminMenu.CreateMenu(localizer?["sa_menu_custom_commands"] ?? "Custom Commands");
List<ChatMenuOptionData> options = [];
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, () =>
var customCommands = CS2_SimpleAdmin.Instance.Config.CustomServerCommands;
options.AddRange(from customCommand in customCommands
where !string.IsNullOrEmpty(customCommand.DisplayName) && !string.IsNullOrEmpty(customCommand.Command)
let hasRights = AdminManager.PlayerHasPermissions(admin, customCommand.Flag)
where hasRights
select new ChatMenuOptionData(customCommand.DisplayName, () =>
{
Helper.TryLogCommandOnDiscord(admin, customCommand.Command);
if (customCommand.ExecuteOnClient)
admin.ExecuteClientCommand(customCommand.Command);
else
Server.ExecuteCommand(customCommand.Command);
}));
}
foreach (ChatMenuOptionData menuOptionData in options)
foreach (var menuOptionData in options)
{
string menuName = menuOptionData.name;
menu.AddMenuOption(menuName, (_, _) => { menuOptionData.action?.Invoke(); }, menuOptionData.disabled);
var menuName = menuOptionData.Name;
menu.AddMenuOption(menuName, (_, _) => { menuOptionData.Action(); }, menuOptionData.Disabled);
}
AdminMenu.OpenMenu(admin, menu);