Skip to content

Commit

Permalink
add chat error message when ntp fails, reduce false errors
Browse files Browse the repository at this point in the history
Signed-off-by: J10a1n15 <45315647+j10a1n15@users.noreply.github.com>
  • Loading branch information
j10a1n15 committed Oct 1, 2024
1 parent 761d383 commit 00f84c0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main/java/at/hannibal2/skyhanni/utils/ComputerTimeOffset.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.test.command.ErrorManager
import at.hannibal2.skyhanni.utils.TimeUtils.format
import kotlinx.coroutines.launch
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
Expand Down Expand Up @@ -58,15 +59,16 @@ object ComputerTimeOffset {
timeInfo.computeDetails()
timeInfo.offset.milliseconds
} catch (e: Exception) {
e.printStackTrace()
if (LorenzUtils.inSkyBlock && config) ErrorManager.logErrorWithData(e, "Failed to get NTP offset")
else e.printStackTrace()
null
}

var lastSystemTime = System.currentTimeMillis()
var lastDetectedOffset = 1.seconds
private var lastSystemTime = System.currentTimeMillis()
private var lastDetectedOffset = 1.seconds

private fun startMonitoringTimeChanges() {
thread(start = true) {
thread {
while (true) {
Thread.sleep(1000)
detectTimeChange()
Expand All @@ -82,8 +84,8 @@ object ComputerTimeOffset {
val expectedDuration = 1.seconds
val deviation = timeDifference - expectedDuration

if (deviation.absoluteValue > 100.milliseconds && config) {
ChatUtils.chat("Offset changed from ${lastDetectedOffset.format()} to ${deviation.format()}")
if (deviation.absoluteValue > 1.seconds && config) {
ChatUtils.chat("Time Offset changed from ${lastDetectedOffset.format()} to ${deviation.format()}")
}
lastDetectedOffset = deviation
}
Expand Down

0 comments on commit 00f84c0

Please sign in to comment.