mirror of
https://github.com/YatopiaMC/Yatopia.git
synced 2024-11-27 05:05:14 +01:00
e1a085de4c
Fixes #145
72 lines
4.2 KiB
Diff
72 lines
4.2 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 94cc21d445ad501e6ddd5cc5d45718e0c915149c..d2f7130752ec50bcb8fa2797652157ec2e97a285 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -928,6 +928,8 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
// Paper End
|
|
// Spigot End
|
|
|
|
+ public static long lastTickMs = 0; // Yatopia
|
|
+
|
|
protected void w() {
|
|
try {
|
|
long serverStartTime = SystemUtils.getMonotonicNanos(); // Paper
|
|
@@ -996,7 +998,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 8bc7c1598807dc3c34355c347983047d13597670..2d32ab02d7edee9a964dc2d9248c0c769e7dcac8 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
@@ -2417,4 +2417,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..76cf2353754821361a4541c21fc8d5f1a670b0de 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, ", ") + ChatColor.GOLD + " Last tick time: " + format( org.bukkit.Bukkit.getLastTickMs() )); // Purpur // Yatopia
|
|
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) {
|
|
@@ -52,4 +52,12 @@ public class TicksPerSecondCommand extends Command
|
|
return ( ( tps > 18.0 ) ? ChatColor.GREEN : ( tps > 16.0 ) ? ChatColor.YELLOW : ChatColor.RED ).toString()
|
|
+ ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( Math.round( tps * 100.0 ) / 100.0, 20.0 ); // Paper - only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
|
|
}
|
|
+
|
|
+ // Yatopia start
|
|
+ public static String format(long ms)
|
|
+ {
|
|
+ ChatColor startingColor = ms < 40 ? ChatColor.GREEN : ( ms < 50 ) ? ChatColor.YELLOW : ChatColor.RED;
|
|
+ return startingColor.toString() + ms + ChatColor.GOLD + "ms";
|
|
+ }
|
|
+ // Yatopia end
|
|
}
|