From 82585adc2583d70e18bdeec8260bfe304813b78e Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:09:10 +0100 Subject: [PATCH 1/4] fix maybe Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt b/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt index 59701a38f28b..569bb775fa6b 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt @@ -56,6 +56,7 @@ object ComputerTimeOffset { val client = NTPUDPClient() val address = InetAddress.getByName(ntpServer) val timeInfo = client.getTime(address) + client.close() timeInfo.computeDetails() timeInfo.offset.milliseconds From 256a7d3385e9f5175606f7fc5b60769997376a5d Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Wed, 27 Nov 2024 14:14:36 +0100 Subject: [PATCH 2/4] custom ntp server option Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- .../skyhanni/config/features/dev/DevConfig.java | 9 +++++++++ .../at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DevConfig.java b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DevConfig.java index a0e6e426aed9..ab7d9b83cf26 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/dev/DevConfig.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/dev/DevConfig.java @@ -9,6 +9,7 @@ import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind; import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider; +import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorText; import io.github.notenoughupdates.moulconfig.annotations.ConfigLink; import io.github.notenoughupdates.moulconfig.annotations.ConfigOption; import org.lwjgl.input.Keyboard; @@ -124,6 +125,14 @@ public class DevConfig { @ConfigEditorBoolean public boolean numberFormatOverride = false; + @Expose + @ConfigOption( + name = "NTP Server", + desc = "Change the NTP-Server Address. Default is \"time.google.com\".\n§cONLY CHANGE THIS IF YOU KNOW WHAT YOU'RE DOING!" + ) + @ConfigEditorText + public String ntpServer = "time.google.com"; + @Expose @Category(name = "Minecraft Console", desc = "Minecraft Console Settings") public MinecraftConsoleConfig minecraftConsoles = new MinecraftConsoleConfig(); diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt b/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt index 569bb775fa6b..377ff6cb9784 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt @@ -45,7 +45,7 @@ object ComputerTimeOffset { private fun checkOffset() { val wasOffsetBefore = (offsetMillis?.absoluteValue ?: 0.seconds) > 5.seconds SkyHanniMod.coroutineScope.launch { - offsetMillis = getNtpOffset("time.google.com") + offsetMillis = getNtpOffset(SkyHanniMod.feature.dev.ntpServer) offsetMillis?.let { tryDisplayOffset(wasOffsetBefore) } From f2bf81b665ab9456d2fbaf7c4a06d3c5d0e9fe20 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:48:29 +0100 Subject: [PATCH 3/4] resolve Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> --- build.gradle.kts | 2 +- .../at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e85907187835..4a1a612c256d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -215,7 +215,7 @@ dependencies { implementation("net.hypixel:mod-api:0.3.1") // getting clock offset - shadowImpl("commons-net:commons-net:3.8.0") + shadowImpl("commons-net:commons-net:3.11.1") detektPlugins("org.notenoughupdates:detektrules:1.0.0") detektPlugins(project(":detekt")) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt b/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt index 377ff6cb9784..2770fc5fc0f4 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt @@ -53,10 +53,10 @@ object ComputerTimeOffset { } private fun getNtpOffset(ntpServer: String): Duration? = try { - val client = NTPUDPClient() - val address = InetAddress.getByName(ntpServer) - val timeInfo = client.getTime(address) - client.close() + val timeInfo = NTPUDPClient().use { client -> + val address = InetAddress.getByName(ntpServer) + client.getTime(address) + } timeInfo.computeDetails() timeInfo.offset.milliseconds From c2687896fd1ebacab985b18cad77b43f08d414e4 Mon Sep 17 00:00:00 2001 From: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:48:29 +0100 Subject: [PATCH 4/4] resolve Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com> Co-authored-by: Luna <148620615+lunaynx@users.noreply.github.com --- build.gradle.kts | 2 +- .../at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e85907187835..4a1a612c256d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -215,7 +215,7 @@ dependencies { implementation("net.hypixel:mod-api:0.3.1") // getting clock offset - shadowImpl("commons-net:commons-net:3.8.0") + shadowImpl("commons-net:commons-net:3.11.1") detektPlugins("org.notenoughupdates:detektrules:1.0.0") detektPlugins(project(":detekt")) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt b/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt index 377ff6cb9784..2770fc5fc0f4 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt @@ -53,10 +53,10 @@ object ComputerTimeOffset { } private fun getNtpOffset(ntpServer: String): Duration? = try { - val client = NTPUDPClient() - val address = InetAddress.getByName(ntpServer) - val timeInfo = client.getTime(address) - client.close() + val timeInfo = NTPUDPClient().use { client -> + val address = InetAddress.getByName(ntpServer) + client.getTime(address) + } timeInfo.computeDetails() timeInfo.offset.milliseconds