From 03cd3317c3ee27282439122a5eb6ee0f79c1db7b Mon Sep 17 00:00:00 2001 From: Xekep Date: Fri, 27 Feb 2026 06:02:08 +0300 Subject: [PATCH] Cache second-update config lookups in hot path --- TShockAPI/TShock.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 28cf03c1f..fd4fb343f 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -1096,11 +1096,12 @@ private void OnUpdate(EventArgs args) /// OnSecondUpdate - Called effectively every second for all time based checks. private void OnSecondUpdate() { - DisableFlags flags = Config.Settings.DisableSecondUpdateLogs ? DisableFlags.WriteToConsole : DisableFlags.WriteToLogAndConsole; + var settings = Config.Settings; + DisableFlags flags = settings.DisableSecondUpdateLogs ? DisableFlags.WriteToConsole : DisableFlags.WriteToLogAndConsole; - if (Config.Settings.ForceTime != "normal") + if (settings.ForceTime != "normal") { - switch (Config.Settings.ForceTime) + switch (settings.ForceTime) { case "day": TSPlayer.Server.SetTime(true, 27000.0); @@ -1117,7 +1118,7 @@ private void OnSecondUpdate() { if (player.TilesDestroyed != null) { - if (player.TileKillThreshold >= Config.Settings.TileKillThreshold) + if (player.TileKillThreshold >= settings.TileKillThreshold) { player.Disable(GetString("Reached TileKill threshold."), flags); TSPlayer.Server.RevertTiles(player.TilesDestroyed); @@ -1134,7 +1135,7 @@ private void OnSecondUpdate() if (player.TilesCreated != null) { - if (player.TilePlaceThreshold >= Config.Settings.TilePlaceThreshold) + if (player.TilePlaceThreshold >= settings.TilePlaceThreshold) { player.Disable(GetString("Reached TilePlace threshold"), flags); lock (player.TilesCreated) @@ -1178,7 +1179,7 @@ private void OnSecondUpdate() } } - if (player.TileLiquidThreshold >= Config.Settings.TileLiquidThreshold) + if (player.TileLiquidThreshold >= settings.TileLiquidThreshold) { player.Disable(GetString("Reached TileLiquid threshold"), flags); } @@ -1187,7 +1188,7 @@ private void OnSecondUpdate() player.TileLiquidThreshold = 0; } - if (player.ProjectileThreshold >= Config.Settings.ProjectileThreshold) + if (player.ProjectileThreshold >= settings.ProjectileThreshold) { player.Disable(GetString("Reached projectile threshold"), flags); } @@ -1196,7 +1197,7 @@ private void OnSecondUpdate() player.ProjectileThreshold = 0; } - if (player.PaintThreshold >= Config.Settings.TilePaintThreshold) + if (player.PaintThreshold >= settings.TilePaintThreshold) { player.Disable(GetString("Reached paint threshold"), flags); } @@ -1205,7 +1206,7 @@ private void OnSecondUpdate() player.PaintThreshold = 0; } - if (player.HealOtherThreshold >= TShock.Config.Settings.HealOtherThreshold) + if (player.HealOtherThreshold >= settings.HealOtherThreshold) { player.Disable(GetString("Reached HealOtherPlayer threshold"), flags); }