Skip to content

Commit

Permalink
1.6.5a
Browse files Browse the repository at this point in the history
- Possibility to force menu type by config
- Possibility to reload admins by css command `css_admins_reload`
  • Loading branch information
daffyyyy committed Oct 24, 2024
1 parent b38b9a0 commit 82b8272
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 9 deletions.
4 changes: 2 additions & 2 deletions CS2-SimpleAdmin/CS2-SimpleAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

namespace CS2_SimpleAdmin;

[MinimumApiVersion(276)]
[MinimumApiVersion(279)]
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
{
internal static CS2_SimpleAdmin Instance { get; private set; } = new();

public override string ModuleName => "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)
{
Expand Down
6 changes: 3 additions & 3 deletions CS2-SimpleAdmin/Commands/basecommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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 () =>
{
Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin/Commands/basevotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 3 additions & 1 deletion CS2-SimpleAdmin/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; } =
[
Expand Down Expand Up @@ -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; } = "";
Expand Down
6 changes: 6 additions & 0 deletions CS2-SimpleAdmin/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
28 changes: 28 additions & 0 deletions CS2-SimpleAdmin/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using System.Text.RegularExpressions;
using CounterStrikeSharp.API.Modules.Entities.Constants;
using CS2_SimpleAdmin.Managers;
using MenuManager;

namespace CS2_SimpleAdmin;

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin/Menus/AdminMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.4a
1.6.5a

0 comments on commit 82b8272

Please sign in to comment.