From e305ee3d6c1372810cf0da40c3a94d635e5a9bb9 Mon Sep 17 00:00:00 2001 From: Minecraft Admin Date: Wed, 4 Feb 2026 21:59:38 +0400 Subject: [PATCH 1/4] Fix time length application --- NTimeManager.cs | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/NTimeManager.cs b/NTimeManager.cs index d995b38..c62648c 100644 --- a/NTimeManager.cs +++ b/NTimeManager.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using Oxide.Core; using Oxide.Core.Plugins; using UnityEngine; @@ -66,7 +67,15 @@ private void ApplyDurations() new[] { "NightLengthInMinutes", "NightLength", "nightLengthInMinutes" }, _config.NightDurationMinutes); - if (!dayApplied || !nightApplied) + if (dayApplied || nightApplied) + { + TryRefreshCycle(sky.Cycle); + } + + var envDayApplied = TrySetEnvLength("env.daylength", _config.DayDurationMinutes); + var envNightApplied = TrySetEnvLength("env.nightlength", _config.NightDurationMinutes); + + if ((!dayApplied || !nightApplied) && (!envDayApplied || !envNightApplied)) { PrintWarning("Could not apply day/night lengths via TOD cycle parameters."); } @@ -205,5 +214,40 @@ private static bool TrySetCycleValue(object cycle, string[] memberNames, float v return false; } + + private static void TryRefreshCycle(object cycle) + { + if (cycle == null) + { + return; + } + + var cycleType = cycle.GetType(); + var refreshMethod = cycleType.GetMethod("Refresh"); + if (refreshMethod != null) + { + refreshMethod.Invoke(cycle, null); + return; + } + + var updateMethod = cycleType.GetMethod("Update"); + if (updateMethod != null) + { + updateMethod.Invoke(cycle, null); + } + } + + private static bool TrySetEnvLength(string command, float value) + { + try + { + ConsoleSystem.Run.Server.Quiet(command, value.ToString(CultureInfo.InvariantCulture)); + return true; + } + catch (Exception) + { + return false; + } + } } } From f8d11b4aa7d6440cf1ca8dc1e81b9fc0603d63c3 Mon Sep 17 00:00:00 2001 From: Minecraft Admin Date: Wed, 4 Feb 2026 22:02:00 +0400 Subject: [PATCH 2/4] Fix env length console call --- NTimeManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NTimeManager.cs b/NTimeManager.cs index c62648c..7e2ac9c 100644 --- a/NTimeManager.cs +++ b/NTimeManager.cs @@ -241,7 +241,8 @@ private static bool TrySetEnvLength(string command, float value) { try { - ConsoleSystem.Run.Server.Quiet(command, value.ToString(CultureInfo.InvariantCulture)); + ConsoleSystem.Run(ConsoleSystem.Option.Server, command, + value.ToString(CultureInfo.InvariantCulture)); return true; } catch (Exception) From 4ad5f3bad4c3fc6ba1c3c4f1a6284445aa4bc680 Mon Sep 17 00:00:00 2001 From: Minecraft Admin Date: Wed, 4 Feb 2026 22:14:34 +0400 Subject: [PATCH 3/4] Avoid env command spam --- NTimeManager.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/NTimeManager.cs b/NTimeManager.cs index 7e2ac9c..4a0a840 100644 --- a/NTimeManager.cs +++ b/NTimeManager.cs @@ -239,6 +239,11 @@ private static void TryRefreshCycle(object cycle) private static bool TrySetEnvLength(string command, float value) { + if (!HasConsoleCommand(command)) + { + return false; + } + try { ConsoleSystem.Run(ConsoleSystem.Option.Server, command, @@ -250,5 +255,30 @@ private static bool TrySetEnvLength(string command, float value) return false; } } + + private static bool HasConsoleCommand(string command) + { + var indexProperty = typeof(ConsoleSystem).GetProperty("Index"); + if (indexProperty == null) + { + return false; + } + + var index = indexProperty.GetValue(null); + if (index == null) + { + return false; + } + + var indexType = index.GetType(); + var findMethod = indexType.GetMethod("FindCommand", new[] { typeof(string) }) + ?? indexType.GetMethod("GetCommand", new[] { typeof(string) }); + if (findMethod == null) + { + return false; + } + + return findMethod.Invoke(index, new object[] { command }) != null; + } } } From 60e7dca16a0294fc12b71f19192fb98754905c67 Mon Sep 17 00:00:00 2001 From: Minecraft Admin Date: Wed, 4 Feb 2026 22:17:29 +0400 Subject: [PATCH 4/4] Suppress warning when env commands missing --- NTimeManager.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/NTimeManager.cs b/NTimeManager.cs index 4a0a840..061c062 100644 --- a/NTimeManager.cs +++ b/NTimeManager.cs @@ -72,10 +72,13 @@ private void ApplyDurations() TryRefreshCycle(sky.Cycle); } - var envDayApplied = TrySetEnvLength("env.daylength", _config.DayDurationMinutes); - var envNightApplied = TrySetEnvLength("env.nightlength", _config.NightDurationMinutes); + var envDayAvailable = HasConsoleCommand("env.daylength"); + var envNightAvailable = HasConsoleCommand("env.nightlength"); + var envDayApplied = envDayAvailable && TrySetEnvLength("env.daylength", _config.DayDurationMinutes); + var envNightApplied = envNightAvailable && TrySetEnvLength("env.nightlength", _config.NightDurationMinutes); - if ((!dayApplied || !nightApplied) && (!envDayApplied || !envNightApplied)) + if ((!dayApplied || !nightApplied) + && ((envDayAvailable && !envDayApplied) || (envNightAvailable && !envNightApplied))) { PrintWarning("Could not apply day/night lengths via TOD cycle parameters."); }