Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 09508c0

Browse files
author
audiomaster99
committed
minor changes and css version bump
1 parent f2c46dc commit 09508c0

5 files changed

Lines changed: 18 additions & 33 deletions

File tree

Events.cs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public sealed partial class SpawnProt
1111
public void RegisterEventsListeners()
1212
{
1313
RegisterEventHandler<EventPlayerSpawn>(OnPlayerSpawn, HookMode.Pre);
14-
RegisterEventHandler<EventRoundPrestart>(OnRoundPrestart);
1514
RegisterEventHandler<EventRoundEnd>(OnRoundEnd);
1615
RegisterEventHandler<EventPlayerDeath>(OnPlayerDeath, HookMode.Pre);
1716
RegisterEventHandler<EventWeaponFire>(OnWeaponFire);
@@ -34,27 +33,16 @@ public void RegisterEventsListeners()
3433
RegisterListener<Listeners.OnMapStart>(name =>
3534
{
3635
protectedPlayers.Clear();
37-
AddTimer(1.0f, GetGameRules);
36+
gameRules = null;
3837

3938
AddTimer(1.0f, () =>
4039
{
41-
_freezeTime = ConVar.Find("mp_freezetime")!.GetPrimitiveValue<int>() - 1;
40+
_freezeTime = ConVar.Find("mp_freezetime")!.GetPrimitiveValue<int>();
41+
GetGameRules();
4242
});
4343
});
4444
}
4545

46-
public HookResult OnRoundPrestart(EventRoundPrestart @event, GameEventInfo info)
47-
{
48-
protectedPlayers.Clear();
49-
foreach (var state in _playerStates.Values)
50-
{
51-
state.ShowCenterMessage = false;
52-
state.SpawnTimer?.Kill();
53-
}
54-
55-
return HookResult.Continue;
56-
}
57-
5846
public HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
5947
{
6048
protectedPlayers.Clear();
@@ -71,7 +59,7 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
7159
{
7260
var player = @event.Userid;
7361

74-
if (player is null || player.IsBot() || !_playerStates.TryGetValue(player.Index, out var state))
62+
if (!player.IzGud() || !_playerStates.TryGetValue(player.Index, out var state))
7563
return HookResult.Continue;
7664

7765
protectedPlayers.Remove(player);
@@ -84,12 +72,8 @@ public HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
8472
{
8573
var player = @event.Userid;
8674

87-
if (player is null || player.IsBot() || !player.IzGud() ||
88-
(Config.CTProtOnly && player.Team == CsTeam.Terrorist) ||
89-
IsWarmup)
90-
{
75+
if (!player.IzGud() || (Config.CTProtOnly && player.Team == CsTeam.Terrorist) || IsWarmup)
9176
return HookResult.Continue;
92-
}
9377

9478
StartSpawnProtection(player);
9579

@@ -102,7 +86,7 @@ public static HookResult OnTakeDamage(DynamicHook hook)
10286
var playerPawn = hook.GetParam<CCSPlayerPawn>(0);
10387
var player = playerPawn?.Controller.Value?.As<CCSPlayerController>();
10488

105-
if (player is null || player.IsBot() || !player.IsProtected())
89+
if (!player.IzGud() || !player.IsProtected())
10690
return HookResult.Continue;
10791

10892
hook.SetReturn(false);
@@ -116,7 +100,7 @@ public HookResult OnWeaponFire(EventWeaponFire @event, GameEventInfo info)
116100

117101
CCSPlayerController? player = @event.Userid;
118102

119-
if (player is null || player.IsBot() || !player.IsAlive() || !player.IsProtected())
103+
if (!player.IzGud() || !player.IsProtected())
120104
return HookResult.Continue;
121105

122106
StopSpawnProtection(player, _playerStates[player.Index]);
@@ -128,7 +112,7 @@ public HookResult OnPlayerActivate(EventPlayerActivate @event, GameEventInfo _)
128112
{
129113
CCSPlayerController? player = @event.Userid;
130114

131-
if (player is not null && player.IzGud() && !player.IsBot())
115+
if (player.IzGud())
132116
playerCache.Add(player);
133117

134118
return HookResult.Continue;
@@ -138,7 +122,7 @@ public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo
138122
{
139123
CCSPlayerController? player = @event.Userid;
140124

141-
if (player is null || player.IsBot())
125+
if (!player.IzGud())
142126
return HookResult.Continue;
143127

144128
protectedPlayers.Remove(player);

Extensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace SpawnProtection
22
{
3+
using System.Diagnostics.CodeAnalysis;
34
using CounterStrikeSharp.API.Core;
45
using static SpawnProtection.SpawnProt;
56

@@ -10,13 +11,13 @@ public static bool IsProtected(this CCSPlayerController player)
1011
|| Instance._playerStates.TryGetValue(player.Index, out var playerState)
1112
&& playerState.ProtectionState == ProtectionState.Protected;
1213

13-
public static bool IzGud(this CCSPlayerController? player)
14-
=> player?.IsValid == true && player.PlayerPawn?.IsValid == true;
14+
public static bool IzGud([NotNullWhen(true)] this CCSPlayerController? player)
15+
=> player?.IsValid == true && player.PlayerPawn?.IsValid == true && !player.IsBot();
1516

1617
public static bool IsBot(this CCSPlayerController? player)
1718
=> player?.IsBot == true || player?.IsHLTV == true;
1819

1920
public static bool IsAlive(this CCSPlayerController player)
20-
=> player.Pawn.Value?.LifeState == (byte)LifeState_t.LIFE_ALIVE && player.PlayerPawn.Value?.Health > 0;
21+
=> player.PlayerPawn.Value?.LifeState == (byte)LifeState_t.LIFE_ALIVE && player.PlayerPawn.Value?.Health > 0;
2122
}
2223
}

PlayerState.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace SpawnProtection
55

66
public class PlayerState
77
{
8-
public ProtectionState ProtectionState { get; set; } = ProtectionState.None;
9-
public bool ShowCenterMessage { get; set; }
8+
public ProtectionState ProtectionState { get; set; } = ProtectionState.Protected;
9+
public bool ShowCenterMessage { get; set; } = true;
1010
public float ProtectionTimer { get; set; } = Instance.Config.SpawnProtTime;
1111
public Timer? SpawnTimer { get; set; }
1212
}

Plugin.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void StartSpawnProtection(CCSPlayerController player)
110110
state.ShowCenterMessage = true;
111111
state.ProtectionState = ProtectionState.Protected;
112112
state.ProtectionTimer = Config.SpawnProtTime;
113-
Server.NextFrame(() => HandleTransparentModel(player, true));
113+
Server.NextFrame(() => HandleTransparentModel(player));
114114

115115
AddTimer(IsFreezeTime ? _freezeTime : 0f, () => CreateProtectionTimer(player, state));
116116
}

Utils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ private string GetColorBasedOnProgress(float progress, float brightness = 1.0f)
4747
return $"#{red:X2}{green:X2}{blue:X2}";
4848
}
4949

50-
private void HandleTransparentModel(CCSPlayerController player, bool isTransparent = false)
50+
private void HandleTransparentModel(CCSPlayerController? player, bool isTransparent = false)
5151
{
5252
if (!Config.TransparentModel)
5353
return;
5454

55-
if (player.IsBot() || !player.IsAlive() || player.PlayerPawn is null or { IsValid: false } || player.PlayerPawn.Value is null)
55+
if (!player.IzGud() || !player.IsAlive() || player.PlayerPawn.Value == null)
5656
return;
5757

5858
if (isTransparent)

0 commit comments

Comments
 (0)