Skip to content

Commit

Permalink
Feat/fire command (#202)
Browse files Browse the repository at this point in the history
Add fire command
  • Loading branch information
MSWS authored Jul 6, 2024
1 parent b86c5af commit 91828fb
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lang/Jailbreak.English/Generic/GenericCommandNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}."
};
}
}
13 changes: 11 additions & 2 deletions lang/Jailbreak.English/Warden/WardenNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,23 @@ public class WardenNotifications : IWardenNotifications, ILanguage<Formatting.La
new SimpleView { PREFIX, $"{ChatColors.LightRed}You are not the warden." };

public IView FIRE_COMMAND_FAILED =>
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!" };
Expand All @@ -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." };
}

}
50 changes: 50 additions & 0 deletions mod/Jailbreak.Warden/Commands/WardenCommandsBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions public/Jailbreak.Formatting/Views/IWardenNotifications.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ public interface IWardenNotifications
/// <returns></returns>
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);
}

0 comments on commit 91828fb

Please sign in to comment.