Skip to content

Commit

Permalink
Fix: ComputerTimeOffset Error (#2998)
Browse files Browse the repository at this point in the history
Co-authored-by: Luna <[email protected]
  • Loading branch information
j10a1n15 authored Nov 28, 2024
1 parent 8391213 commit 96a4fae
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ 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)
}
}
}

private fun getNtpOffset(ntpServer: String): Duration? = try {
val client = NTPUDPClient()
val address = InetAddress.getByName(ntpServer)
val timeInfo = client.getTime(address)
val timeInfo = NTPUDPClient().use { client ->
val address = InetAddress.getByName(ntpServer)
client.getTime(address)
}

timeInfo.computeDetails()
timeInfo.offset.milliseconds
Expand Down

0 comments on commit 96a4fae

Please sign in to comment.