Skip to content

Commit f632281

Browse files
committed
Fixed a bug that no weapons were given due to gamerules mismatch
1 parent 65816e7 commit f632281

File tree

3 files changed

+18
-38
lines changed

3 files changed

+18
-38
lines changed

Modules/Core.cs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,10 @@ public class Core : BasePlugin
1717
public static Core Plugin = null!;
1818

1919
public override string ModuleName => "[Retakes] Weapons Allocator";
20-
public override string ModuleVersion => "1.0.4";
20+
public override string ModuleVersion => "1.0.5";
2121
public override string ModuleAuthor => "Ravid & B3none";
2222
public override string ModuleDescription => "Weapons Allocator plugin for retakes";
2323

24-
private static CCSGameRules? _gameRules;
25-
26-
private static void SetGameRules()
27-
{
28-
var gameRulesEntities = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules");
29-
30-
if (gameRulesEntities.Any())
31-
{
32-
_gameRules = gameRulesEntities.First().GameRules!;
33-
}
34-
}
35-
36-
private static bool WarmupRunning
37-
{
38-
get
39-
{
40-
if (_gameRules is null)
41-
SetGameRules();
42-
43-
return _gameRules is not null && _gameRules.WarmupPeriod;
44-
}
45-
}
46-
4724
public static Config Config = null!;
4825

4926
public static Database Db = null!;
@@ -77,9 +54,18 @@ public override void Unload(bool hotReload)
7754
Utilities.GetPlayers().ForEach(RemovePlayerFromList);
7855
}
7956

80-
public static bool IsLive()
57+
public static CCSGameRules GetGameRules()
8158
{
82-
return !WarmupRunning;
59+
var gameRulesEntities = Utilities.FindAllEntitiesByDesignerName<CCSGameRulesProxy>("cs_gamerules");
60+
var gameRules = gameRulesEntities.First().GameRules;
61+
62+
if(gameRules == null!)
63+
{
64+
ThrowError("Failed to get game rules");
65+
return null!;
66+
}
67+
68+
return gameRules;
8369
}
8470

8571
private static void SQL_ConnectCallback(string connectionString, Exception exception, dynamic data)

Modules/Handlers/Events.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void RegisterEvents()
1717

1818
private static HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventInfo info)
1919
{
20-
if (!IsLive())
20+
if (GetGameRules().WarmupPeriod)
2121
{
2222
return HookResult.Continue;
2323
}
@@ -29,17 +29,16 @@ private static HookResult OnRoundPreStart(EventRoundPrestart @event, GameEventIn
2929

3030
private static HookResult OnPlayerSpawn(EventPlayerSpawn @event, GameEventInfo info)
3131
{
32-
var playerController = @event.Userid;
33-
34-
if (playerController == null! || !playerController.IsValid)
32+
if(GetGameRules().WarmupPeriod)
3533
{
36-
PrintToServer("OnPlayerSpawn: playerController is null or invalid");
3734
return HookResult.Continue;
3835
}
3936

40-
if (!IsLive())
37+
var playerController = @event.Userid;
38+
39+
if (playerController == null! || !playerController.IsValid)
4140
{
42-
PrintToServer("OnPlayerSpawn: not live");
41+
PrintToServer("OnPlayerSpawn: playerController is null or invalid");
4342
return HookResult.Continue;
4443
}
4544

Modules/Models/Player.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ public void CreateSpawnDelay()
9494

9595
private void Timer_GiveWeapons()
9696
{
97-
if (!IsLive())
98-
{
99-
return;
100-
}
101-
10297
WeaponsAllocator.Allocate();
10398
}
10499
}

0 commit comments

Comments
 (0)