geforkt von Mirrors/Velocity
Use System.nanoTime in place of System.currentTimeMillis when comparing timestamps. (#1174)
Dieser Commit ist enthalten in:
Ursprung
897ff81915
Commit
408b420af7
@ -20,6 +20,7 @@ package com.velocitypowered.proxy;
|
|||||||
import io.netty.util.ResourceLeakDetector;
|
import io.netty.util.ResourceLeakDetector;
|
||||||
import io.netty.util.ResourceLeakDetector.Level;
|
import io.netty.util.ResourceLeakDetector.Level;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
@ -63,14 +64,14 @@ public class Velocity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.nanoTime();
|
||||||
|
|
||||||
VelocityServer server = new VelocityServer(options);
|
VelocityServer server = new VelocityServer(options);
|
||||||
server.start();
|
server.start();
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> server.shutdown(false),
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> server.shutdown(false),
|
||||||
"Shutdown thread"));
|
"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));
|
logger.info("Done ({}s)!", new DecimalFormat("#.##").format(bootTime));
|
||||||
server.getConsoleCommandSource().start();
|
server.getConsoleCommandSource().start();
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(KeepAlive packet) {
|
public boolean handle(KeepAlive packet) {
|
||||||
serverConn.getPendingPings().put(packet.getRandomId(), System.currentTimeMillis());
|
serverConn.getPendingPings().put(packet.getRandomId(), System.nanoTime());
|
||||||
return false; // forwards on
|
return false; // forwards on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
|
|||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -81,7 +82,7 @@ public class ClientConfigSessionHandler implements MinecraftSessionHandler {
|
|||||||
if (sentTime != null) {
|
if (sentTime != null) {
|
||||||
MinecraftConnection smc = serverConnection.getConnection();
|
MinecraftConnection smc = serverConnection.getConnection();
|
||||||
if (smc != null) {
|
if (smc != null) {
|
||||||
player.setPing(System.currentTimeMillis() - sentTime);
|
player.setPing(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - sentTime));
|
||||||
smc.write(packet);
|
smc.write(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,7 @@ import java.util.Queue;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
@ -177,7 +178,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
if (sentTime != null) {
|
if (sentTime != null) {
|
||||||
MinecraftConnection smc = serverConnection.getConnection();
|
MinecraftConnection smc = serverConnection.getConnection();
|
||||||
if (smc != null) {
|
if (smc != null) {
|
||||||
player.setPing(System.currentTimeMillis() - sentTime);
|
player.setPing(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - sentTime));
|
||||||
smc.write(packet);
|
smc.write(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren