3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-24 15:20:35 +01:00

Use System.nanoTime in place of System.currentTimeMillis when comparing timestamps. (#1174)

Dieser Commit ist enthalten in:
0xAda 2024-01-04 17:35:03 +00:00 committet von GitHub
Ursprung 897ff81915
Commit 408b420af7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
4 geänderte Dateien mit 8 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -20,6 +20,7 @@ package com.velocitypowered.proxy;
import io.netty.util.ResourceLeakDetector;
import io.netty.util.ResourceLeakDetector.Level;
import java.text.DecimalFormat;
import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -63,14 +64,14 @@ public class Velocity {
return;
}
long startTime = System.currentTimeMillis();
long startTime = System.nanoTime();
VelocityServer server = new VelocityServer(options);
server.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> server.shutdown(false),
"Shutdown thread"));
double bootTime = (System.currentTimeMillis() - startTime) / 1000d;
double bootTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) / 1000d;
logger.info("Done ({}s)!", new DecimalFormat("#.##").format(bootTime));
server.getConsoleCommandSource().start();

Datei anzeigen

@ -137,7 +137,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
@Override
public boolean handle(KeepAlive packet) {
serverConn.getPendingPings().put(packet.getRandomId(), System.currentTimeMillis());
serverConn.getPendingPings().put(packet.getRandomId(), System.nanoTime());
return false; // forwards on
}

Datei anzeigen

@ -36,6 +36,7 @@ import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.apache.logging.log4j.LogManager;
@ -81,7 +82,7 @@ public class ClientConfigSessionHandler implements MinecraftSessionHandler {
if (sentTime != null) {
MinecraftConnection smc = serverConnection.getConnection();
if (smc != null) {
player.setPing(System.currentTimeMillis() - sentTime);
player.setPing(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - sentTime));
smc.write(packet);
}
}

Datei anzeigen

@ -81,6 +81,7 @@ import java.util.Queue;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.apache.logging.log4j.LogManager;
@ -177,7 +178,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
if (sentTime != null) {
MinecraftConnection smc = serverConnection.getConnection();
if (smc != null) {
player.setPing(System.currentTimeMillis() - sentTime);
player.setPing(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - sentTime));
smc.write(packet);
}
}