From 91828fbcbde03ecf7ed8a3a44be9e513134bec4f Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 5 Jul 2024 21:58:03 -0700 Subject: [PATCH] Feat/fire command (#202) Add fire command --- .../Generic/GenericCommandNotifications.cs | 9 ++++ .../Warden/WardenNotifications.cs | 13 ++++- .../Commands/WardenCommandsBehavior.cs | 50 +++++++++++++++++++ .../Views/IGenericCommandNotifications.cs | 1 + .../Views/IWardenNotifications.cs | 3 ++ 5 files changed, 74 insertions(+), 2 deletions(-) diff --git a/lang/Jailbreak.English/Generic/GenericCommandNotifications.cs b/lang/Jailbreak.English/Generic/GenericCommandNotifications.cs index 75cb92b6..cce6e2cf 100644 --- a/lang/Jailbreak.English/Generic/GenericCommandNotifications.cs +++ b/lang/Jailbreak.English/Generic/GenericCommandNotifications.cs @@ -51,4 +51,13 @@ public IView InvalidParameter(string parameter, string expected) $"{ChatColors.Red}Invalid parameter '{ChatColors.LightBlue}{parameter}{ChatColors.Red}', expected a(n) {ChatColors.White}{expected}{ChatColors.Red}." }; } + + public IView NoPermissionMessage(string permission) + { + return new SimpleView + { + PREFIX, + $"{ChatColors.Red}You do not have permission to use this command. Required permission: {ChatColors.White}{permission}{ChatColors.Red}." + }; + } } \ No newline at end of file diff --git a/lang/Jailbreak.English/Warden/WardenNotifications.cs b/lang/Jailbreak.English/Warden/WardenNotifications.cs index 7917ef4f..f90ac8ba 100644 --- a/lang/Jailbreak.English/Warden/WardenNotifications.cs +++ b/lang/Jailbreak.English/Warden/WardenNotifications.cs @@ -52,13 +52,23 @@ public class WardenNotifications : IWardenNotifications, ILanguage - new SimpleView { PREFIX, "The fire command has failed to work for some unknown reason..." }; + new SimpleView { PREFIX, "The fire command has failed to work for some unknown reason..." }; public IView PASS_WARDEN(CCSPlayerController player) { return new SimpleView { PREFIX, player, "has resigned from being warden." }; } + public IView FIRE_WARDEN(CCSPlayerController player) + { + return new SimpleView { PREFIX, player, "was fired from being warden." }; + } + + public IView FIRE_WARDEN(CCSPlayerController player, CCSPlayerController admin) + { + return new SimpleView { PREFIX, admin, "has fired", player, "from being warden." }; + } + public IView NEW_WARDEN(CCSPlayerController player) { return new SimpleView { PREFIX, player, "is now the warden!" }; @@ -76,5 +86,4 @@ public IView FIRE_COMMAND_SUCCESS(CCSPlayerController player) { return new SimpleView { PREFIX, player, "has been fired and is no longer the warden." }; } - } \ No newline at end of file diff --git a/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs b/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs index 72a44641..dc2cd124 100644 --- a/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs +++ b/mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs @@ -2,11 +2,13 @@ using CounterStrikeSharp.API; using CounterStrikeSharp.API.Core; using CounterStrikeSharp.API.Core.Attributes.Registration; +using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Utils; using Jailbreak.Formatting.Extensions; using Jailbreak.Formatting.Views; using Jailbreak.Public.Behaviors; +using Jailbreak.Public.Extensions; using Jailbreak.Public.Mod.Warden; using Microsoft.Extensions.DependencyInjection; @@ -59,6 +61,54 @@ public void Command_Pass(CCSPlayerController? player, CommandInfo command) _lastPassCommand[player] = DateTime.Now; } + [ConsoleCommand("css_fire", "Force the warden to pass")] + [CommandHelper(0, "", CommandUsage.CLIENT_ONLY)] + public void Command_Fire(CCSPlayerController? player, CommandInfo command) + { + if (player == null) + return; + + if (!_warden.HasWarden || _warden.Warden == null) + { + _notifications.CURRENT_WARDEN(null).ToPlayerChat(player); + return; + } + + if (!AdminManager.PlayerHasPermissions(player, "@css/ban")) + { + _generics.NoPermissionMessage("@css/ban").ToPlayerChat(player); + return; + } + + // Handle warden pass + _notifications.FIRE_WARDEN(player) + .ToAllChat() + .ToAllCenter(); + + // GetPlayers() returns valid players, no need to error check here. + foreach (var client in Utilities.GetPlayers().Where(p => p.IsReal())) + { + if (AdminManager.PlayerHasPermissions(client, "@css/chat")) + { + _notifications.FIRE_WARDEN(_warden.Warden, player).ToPlayerChat(client); + } + else + { + _notifications.FIRE_WARDEN(_warden.Warden).ToPlayerChat(client); + } + + client.ExecuteClientCommand( + $"play sounds/{_config.WardenPassedSoundName}"); + } + + _notifications.BECOME_NEXT_WARDEN.ToAllChat(); + + if (!_warden.TryRemoveWarden(true)) + Server.PrintToChatAll("[BUG] Couldn't remove warden :^("); + + _lastPassCommand[_warden.Warden] = DateTime.Now; + } + [ConsoleCommand("css_warden", "Become a warden, Join the warden queue, or see information about the current warden.")] [ConsoleCommand("css_w", "Become a warden, Join the warden queue, or see information about the current warden.")] diff --git a/public/Jailbreak.Formatting/Views/IGenericCommandNotifications.cs b/public/Jailbreak.Formatting/Views/IGenericCommandNotifications.cs index a91532dc..08b4670f 100644 --- a/public/Jailbreak.Formatting/Views/IGenericCommandNotifications.cs +++ b/public/Jailbreak.Formatting/Views/IGenericCommandNotifications.cs @@ -8,4 +8,5 @@ public interface IGenericCommandNotifications public IView PlayerFoundMultiple(string query); public IView CommandOnCooldown(DateTime cooldownEndsAt); public IView InvalidParameter(string parameter, string expected); + public IView NoPermissionMessage(string permission); } \ No newline at end of file diff --git a/public/Jailbreak.Formatting/Views/IWardenNotifications.cs b/public/Jailbreak.Formatting/Views/IWardenNotifications.cs index 0b837890..55d5224e 100644 --- a/public/Jailbreak.Formatting/Views/IWardenNotifications.cs +++ b/public/Jailbreak.Formatting/Views/IWardenNotifications.cs @@ -38,4 +38,7 @@ public interface IWardenNotifications /// public IView CURRENT_WARDEN(CCSPlayerController? player); public IView FIRE_COMMAND_SUCCESS(CCSPlayerController player); + + public IView FIRE_WARDEN(CCSPlayerController player); + public IView FIRE_WARDEN(CCSPlayerController player, CCSPlayerController admin); }