Yatopia/patches/server/0005-Add-getLastTickMs-api.patch
Bud Gidiere 8a615979b3
fix
2020-08-05 08:36:44 -05:00

59 lines
3.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: tr7zw <tr7zw@live.de>
Date: Fri, 31 Jul 2020 21:19:26 -0500
Subject: [PATCH] Add getLastTickMs api
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 7cc402a4dfaa2a4bb123c897b05c09190cbdd489..8e5284fd39be45055bec1609f6b8dd05229e6b35 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -930,6 +930,8 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
// Paper End
// Spigot End
+ public static long lastTickMs = 0; // Yatopia
+
protected void v() {
try {
long serverStartTime = SystemUtils.getMonotonicNanos(); // Paper
@@ -998,7 +1000,9 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
this.a(gameprofilertick);
//this.methodProfiler.a(); // Akarin - remove caller
//this.methodProfiler.enter("tick"); // Akarin - remove caller
+ long tickStart = System.currentTimeMillis(); // Yatopia
this.a(this::canSleepForTick);
+ lastTickMs = System.currentTimeMillis() - tickStart; // Yatopia
//this.methodProfiler.exitEnter("nextTickWait"); // Akarin - remove caller
this.X = true;
// Purpur start - tps catchup
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 7bb9752edfc906ed968e839e073efd63834254fb..cdc1870b196c7fd9583dc70d856f484721ccfada 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2422,4 +2422,11 @@ public final class CraftServer implements Server {
return getServer().lagging;
}
// Purpur end
+
+ // Yatopia start
+ @Override
+ public long getLastTickMs() {
+ return net.minecraft.server.MinecraftServer.lastTickMs;
+ }
+ // Yatopia end
}
diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
index 3c7b9a6d24e064f9c1ec5fb6d52f42627944d7fa..87812ace9e1327f31693bdfb3fa45ac38766799b 100644
--- a/src/main/java/org/spigotmc/TicksPerSecondCommand.java
+++ b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
@@ -33,7 +33,7 @@ public class TicksPerSecondCommand extends Command
for ( int i = 0; i < tps.length; i++) {
tpsAvg[i] = format( tps[i] );
}
- sender.sendMessage(ChatColor.GOLD + "TPS from last 5s, 1m, 5m, 15m: " + org.apache.commons.lang.StringUtils.join(tpsAvg, ", ")); // Purpur
+ sender.sendMessage(ChatColor.GOLD + "TPS from last 5s, 1m, 5m, 15m: " + org.apache.commons.lang.StringUtils.join(tpsAvg, ", ") + " Last tick time: " + org.bukkit.Bukkit.getLastTickMs() + "ms"); // Yatopia // Purpur
if (args.length > 0 && args[0].equals("mem") && sender.hasPermission("bukkit.command.tpsmemory")) {
sender.sendMessage(ChatColor.GOLD + "Current Memory Usage: " + ChatColor.GREEN + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024)) + "/" + (Runtime.getRuntime().totalMemory() / (1024 * 1024)) + " mb (Max: " + (Runtime.getRuntime().maxMemory() / (1024 * 1024)) + " mb)");
if (!hasShownMemoryWarning) {