From 48ba903f1366db9181e39cf2727d0fa7e774c801 Mon Sep 17 00:00:00 2001 From: Xekep Date: Sat, 28 Feb 2026 10:26:19 +0300 Subject: [PATCH] Fix golf cup packet validation and sync projectile checks --- .../Handlers/LandGolfBallInCupHandler.cs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Handlers/LandGolfBallInCupHandler.cs b/TShockAPI/Handlers/LandGolfBallInCupHandler.cs index 6af3c1331..8b9ddfda5 100644 --- a/TShockAPI/Handlers/LandGolfBallInCupHandler.cs +++ b/TShockAPI/Handlers/LandGolfBallInCupHandler.cs @@ -102,7 +102,7 @@ public void OnReceive(object sender, LandGolfBallInCupEventArgs args) return; } - if (!Main.tile[args.TileX, args.TileY].active() && Main.tile[args.TileX, args.TileY].type != TileID.GolfHole) + if (!Main.tile[args.TileX, args.TileY].active() || Main.tile[args.TileX, args.TileY].type != TileID.GolfHole) { TShock.Log.ConsoleDebug(GetString($"LandGolfBallInCupHandler: Tile at packet position X:{args.TileX} Y:{args.TileY} is not a golf hole! - From {args.Player.Name}")); args.Handled = true; @@ -116,8 +116,22 @@ public void OnReceive(object sender, LandGolfBallInCupEventArgs args) return; } - var usedGolfBall = args.Player.RecentlyCreatedProjectiles.Any(e => GolfBallProjectileIDs.Contains(e.Type)); - var usedGolfClub = args.Player.RecentlyCreatedProjectiles.Any(e => e.Type == ProjectileID.GolfClubHelper); + var usedGolfBall = false; + var usedGolfClub = false; + lock (args.Player.RecentlyCreatedProjectiles) + { + for (int i = 0; i < args.Player.RecentlyCreatedProjectiles.Count; i++) + { + var tracked = args.Player.RecentlyCreatedProjectiles[i]; + if (!usedGolfBall && GolfBallProjectileIDs.Contains(tracked.Type)) + usedGolfBall = true; + if (!usedGolfClub && tracked.Type == ProjectileID.GolfClubHelper) + usedGolfClub = true; + if (usedGolfBall && usedGolfClub) + break; + } + } + if (!usedGolfClub && !usedGolfBall) { TShock.Log.ConsoleDebug(GetString($"GolfPacketHandler: Player did not have create a golf club projectile the last 5 seconds! - From {args.Player.Name}"));