From 82b82722a618c461c26bd9082ac28ea0a86be1a4 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Thu, 24 Oct 2024 13:39:11 +0200 Subject: [PATCH] 1.6.5a - Possibility to force menu type by config - Possibility to reload admins by css command `css_admins_reload` --- CS2-SimpleAdmin/CS2-SimpleAdmin.cs | 4 ++-- CS2-SimpleAdmin/Commands/basecommands.cs | 6 ++--- CS2-SimpleAdmin/Commands/basevotes.cs | 2 +- CS2-SimpleAdmin/Config.cs | 4 +++- CS2-SimpleAdmin/Events.cs | 6 +++++ CS2-SimpleAdmin/Helper.cs | 28 ++++++++++++++++++++++++ CS2-SimpleAdmin/Menus/AdminMenu.cs | 2 +- CS2-SimpleAdmin/VERSION | 2 +- 8 files changed, 45 insertions(+), 9 deletions(-) diff --git a/CS2-SimpleAdmin/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin/CS2-SimpleAdmin.cs index 81a7a05..e6a2f04 100644 --- a/CS2-SimpleAdmin/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin/CS2-SimpleAdmin.cs @@ -11,7 +11,7 @@ namespace CS2_SimpleAdmin; -[MinimumApiVersion(276)] +[MinimumApiVersion(279)] public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig { internal static CS2_SimpleAdmin Instance { get; private set; } = new(); @@ -19,7 +19,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)"); public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)"; public override string ModuleAuthor => "daffyy & Dliix66"; - public override string ModuleVersion => "1.6.4a"; + public override string ModuleVersion => "1.6.5a"; public override void Load(bool hotReload) { diff --git a/CS2-SimpleAdmin/Commands/basecommands.cs b/CS2-SimpleAdmin/Commands/basecommands.cs index 02d29b4..4fcd745 100644 --- a/CS2-SimpleAdmin/Commands/basecommands.cs +++ b/CS2-SimpleAdmin/Commands/basecommands.cs @@ -494,13 +494,13 @@ public void OnDisconnectedCommand(CCSPlayerController? caller, CommandInfo comma { if (_localizer == null || caller == null) return; - var disconnectedMenu = MenuApi?.NewMenu(_localizer["sa_menu_disconnected_title"]); + var disconnectedMenu = Helper.CreateMenu(_localizer["sa_menu_disconnected_title"]); DisconnectedPlayers.ForEach(player => { disconnectedMenu?.AddMenuOption(player.Name, (_, _) => { - var disconnectedMenuAction = MenuApi?.NewMenu(_localizer["sa_menu_disconnected_action_title"]); + var disconnectedMenuAction = Helper.CreateMenu(_localizer["sa_menu_disconnected_action_title"]); disconnectedMenuAction?.AddMenuOption(_localizer["sa_ban"], (_, _) => { DurationMenu.OpenMenu(caller, _localizer["sa_ban"], player, (_, _, duration) => @@ -564,7 +564,7 @@ public void OnWarnsCommand(CCSPlayerController? caller, CommandInfo command) var userId = player.UserId.Value; - IMenu? warnsMenu = MenuApi?.NewMenu(_localizer["sa_admin_warns_menu_title", player.PlayerName]); + IMenu? warnsMenu = Helper.CreateMenu(_localizer["sa_admin_warns_menu_title", player.PlayerName]); Task.Run(async () => { diff --git a/CS2-SimpleAdmin/Commands/basevotes.cs b/CS2-SimpleAdmin/Commands/basevotes.cs index 374c8d8..68908d7 100644 --- a/CS2-SimpleAdmin/Commands/basevotes.cs +++ b/CS2-SimpleAdmin/Commands/basevotes.cs @@ -33,7 +33,7 @@ public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command) { using (new WithTemporaryCulture(player.GetLanguage())) { - IMenu? voteMenu = MenuApi?.NewMenu(_localizer["sa_admin_vote_menu_title", question]); + IMenu? voteMenu = Helper.CreateMenu(_localizer["sa_admin_vote_menu_title", question]); if (voteMenu == null) return; //ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]); diff --git a/CS2-SimpleAdmin/Config.cs b/CS2-SimpleAdmin/Config.cs index df40481..bf492b3 100644 --- a/CS2-SimpleAdmin/Config.cs +++ b/CS2-SimpleAdmin/Config.cs @@ -108,6 +108,8 @@ public class CustomServerCommandData public class MenuConfig { + [JsonPropertyName("MenuType")] public string MenuType { get; set; } = "selectable"; + [JsonPropertyName("Durations")] public DurationItem[] Durations { get; set; } = [ @@ -223,7 +225,7 @@ public class OtherSettings public class CS2_SimpleAdminConfig : BasePluginConfig { - [JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 22; + [JsonPropertyName("ConfigVersion")] public override int Version { get; set; } = 23; [JsonPropertyName("DatabaseHost")] public string DatabaseHost { get; set; } = ""; diff --git a/CS2-SimpleAdmin/Events.cs b/CS2-SimpleAdmin/Events.cs index e92329f..132c3b8 100644 --- a/CS2-SimpleAdmin/Events.cs +++ b/CS2-SimpleAdmin/Events.cs @@ -161,6 +161,12 @@ private HookResult OnCommandSayNew(CCSPlayerController? player, CommandInfo info var command = info.GetArg(0).ToLower(); + if (command == "css_admins_reload") + { + AddTimer(1.0f, () => ReloadAdmins(null)); + return HookResult.Continue; + } + if (!command.Contains("say")) return HookResult.Continue; diff --git a/CS2-SimpleAdmin/Helper.cs b/CS2-SimpleAdmin/Helper.cs index 238360a..11fac5f 100644 --- a/CS2-SimpleAdmin/Helper.cs +++ b/CS2-SimpleAdmin/Helper.cs @@ -20,6 +20,7 @@ using System.Text.RegularExpressions; using CounterStrikeSharp.API.Modules.Entities.Constants; using CS2_SimpleAdmin.Managers; +using MenuManager; namespace CS2_SimpleAdmin; @@ -516,6 +517,33 @@ public static void TryLogCommandOnDiscord(CCSPlayerController? caller, string co CS2_SimpleAdmin._localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandString])); } + + public static IMenu? CreateMenu(string title) + { + var menuType = CS2_SimpleAdmin.Instance.Config.MenuConfigs.MenuType.ToLower(); + + var menu = menuType switch + { + _ when menuType.Equals("selectable", StringComparison.CurrentCultureIgnoreCase) => + CS2_SimpleAdmin.MenuApi?.NewMenu(title), + + _ when menuType.Equals("dynamic", StringComparison.CurrentCultureIgnoreCase) => + CS2_SimpleAdmin.MenuApi?.NewMenuForcetype(title, MenuType.ButtonMenu), + + _ when menuType.Equals("center", StringComparison.CurrentCultureIgnoreCase) => + CS2_SimpleAdmin.MenuApi?.NewMenuForcetype(title, MenuType.CenterMenu), + + _ when menuType.Equals("chat", StringComparison.CurrentCultureIgnoreCase) => + CS2_SimpleAdmin.MenuApi?.NewMenuForcetype(title, MenuType.ChatMenu), + + _ when menuType.Equals("console", StringComparison.CurrentCultureIgnoreCase) => + CS2_SimpleAdmin.MenuApi?.NewMenuForcetype(title, MenuType.ConsoleMenu), + + _ => CS2_SimpleAdmin.MenuApi?.NewMenu(title) + }; + + return menu; + } } public static class PluginInfo diff --git a/CS2-SimpleAdmin/Menus/AdminMenu.cs b/CS2-SimpleAdmin/Menus/AdminMenu.cs index ad78c0c..8757351 100644 --- a/CS2-SimpleAdmin/Menus/AdminMenu.cs +++ b/CS2-SimpleAdmin/Menus/AdminMenu.cs @@ -8,7 +8,7 @@ public static class AdminMenu { public static IMenu? CreateMenu(string title) { - return CS2_SimpleAdmin.MenuApi?.NewMenu(title); + return Helper.CreateMenu(title); // return CS2_SimpleAdmin.Instance.Config.UseChatMenu ? new ChatMenu(title) : new CenterHtmlMenu(title, CS2_SimpleAdmin.Instance); } diff --git a/CS2-SimpleAdmin/VERSION b/CS2-SimpleAdmin/VERSION index 9ff7676..6842fcb 100644 --- a/CS2-SimpleAdmin/VERSION +++ b/CS2-SimpleAdmin/VERSION @@ -1 +1 @@ -1.6.4a \ No newline at end of file +1.6.5a \ No newline at end of file