This commit is contained in:
Isaac
2025-05-16 12:50:29 -07:00
committed by GitHub
2 changed files with 27 additions and 19 deletions

View File

@@ -60,7 +60,7 @@ public class GunToss(BasePlugin plugin, ILastRequestManager manager,
if (bothThrewTick > 0)
Plugin.AddTimer(5, () => {
if (State != LRState.ACTIVE) return;
Guard.SetHealth(Math.Min(Guard.Health, 100));
Guard.SetHealth(Math.Min(Guard.PlayerPawn.Value!.Health, 100));
Guard.SetArmor(Math.Min(Guard.PawnArmor, 100));
});
}

View File

@@ -1,11 +1,9 @@
using CounterStrikeSharp.API;
using System;
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;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Utils;
using Jailbreak.Formatting.Extensions;
using Jailbreak.Formatting.Views;
@@ -14,7 +12,6 @@ using Jailbreak.Public.Behaviors;
using Jailbreak.Public.Mod.Mute;
using Jailbreak.Public.Mod.Warden;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
using Jailbreak.Formatting.Base;
using Jailbreak.Formatting.Core;
using Jailbreak.Formatting.Objects;
@@ -51,11 +48,13 @@ public class CountdownCommandBehavior(IWardenService warden, IMuteService mute,
if (command.ArgCount == 2) {
if (!int.TryParse(command.GetArg(1), out countdownDuration)) {
generics.InvalidParameter(command.GetArg(1), "number");
command.ReplyToCommand("Expected a number parameter.");
return;
}
if (countdownDuration <= 0) {
generics.InvalidParameter(command.GetArg(1), "number greater than 0");
command.ReplyToCommand("Expected a number greater than 0.");
return;
}
}
@@ -63,28 +62,33 @@ public class CountdownCommandBehavior(IWardenService warden, IMuteService mute,
if (countdownDuration < CV_WARDEN_MIN_COUNTDOWN.Value) {
generics.InvalidParameter(command.GetArg(1),
$"number greater than or equal to {CV_WARDEN_MIN_COUNTDOWN.Value}");
command.ReplyToCommand($"Expected a number greater than or equal to {CV_WARDEN_MIN_COUNTDOWN.Value}");
return;
}
if (countdownDuration > CV_WARDEN_MAX_COUNTDOWN.Value) {
generics.InvalidParameter(command.GetArg(1),
$"number less than or equal to {CV_WARDEN_MAX_COUNTDOWN.Value}");
command.ReplyToCommand($"Expected a number less than or equal to {CV_WARDEN_MAX_COUNTDOWN.Value}");
return;
}
//
// Attempt to enact peace
bool success = EnactPeace(executor);
// Check perm and enact peace
bool success = PermCheckAndEnactPeace(executor);
if (!success) return;
// Inform players of countdown
StartCountDown(countdownDuration);
// Create callbacks each second to notify players of countdown time remaining / completion of countdown
// Create callbacks each second less than 5 or divisible by 5 to notify players of countdown time remaining / completion of countdown
for (int i = countdownDuration; i > 0; --i) {
int current = i; // lambda capture
Server.RunOnTick(Server.TickCount + (64 * (countdownDuration - current)),
() => PrintCountdownToPlayers(current));
if (current <= 5 || current % 5 == 0) {
Server.RunOnTick(Server.TickCount + (64 * (countdownDuration - current)),
() => PrintCountdownToPlayers(current));
}
}
Server.RunOnTick(Server.TickCount + (64 * countdownDuration), () => PrintGoToPlayers());
}
@@ -92,7 +96,7 @@ public class CountdownCommandBehavior(IWardenService warden, IMuteService mute,
// Is this okay?
// Feels like bad encapsulation
private static readonly FormatObject PREFIX =
new HiddenFormatObject($" {ChatColors.Red}Countdown>") {
new HiddenFormatObject($" {ChatColors.DarkBlue}Countdown>") {
Plain = false, Panorama = false, Chat = true
};
@@ -101,7 +105,7 @@ public class CountdownCommandBehavior(IWardenService warden, IMuteService mute,
}
private void PrintCountdownToPlayers(int seconds) {
new SimpleView { PREFIX, "Countdown: " + seconds }.ToAllChat();
new SimpleView { PREFIX, seconds.ToString() }.ToAllChat();
// var players = Utilities.GetPlayers();
// foreach (var player in players) {
@@ -119,8 +123,8 @@ public class CountdownCommandBehavior(IWardenService warden, IMuteService mute,
}
//
// Attempt to enact a period of peace for players to focus on the countdown
private bool EnactPeace(CCSPlayerController? executor) {
// Check permissions and attempt to enact a period of peace for players to focus on the countdown
private bool PermCheckAndEnactPeace(CCSPlayerController? executor) {
var fromWarden = executor != null && warden.IsWarden(executor);
if (executor == null
@@ -133,7 +137,6 @@ public class CountdownCommandBehavior(IWardenService warden, IMuteService mute,
if (!fromWarden
&& AdminManager.PlayerHasPermissions(executor, "@css/chat")) {
wardenLocale.NotWarden.ToChat(executor);
mute.PeaceMute(MuteReason.ADMIN);
lastCountdown = DateTime.Now;
return true;
@@ -145,8 +148,13 @@ public class CountdownCommandBehavior(IWardenService warden, IMuteService mute,
return false;
}
mute.PeaceMute(fromWarden ? MuteReason.WARDEN_INVOKED : MuteReason.ADMIN);
lastCountdown = DateTime.Now;
return true;
if (fromWarden) {
mute.PeaceMute(fromWarden ? MuteReason.WARDEN_INVOKED : MuteReason.ADMIN);
lastCountdown = DateTime.Now;
return true;
} else {
wardenLocale.NotWarden.ToChat(executor);
}
return false;
}
}