Yatopia/patches/server/0005-Add-getLastTickMs-api.patch
Ivan Pekov b512028dea
Updated Upstream and Sidestream(s) (Tuinity/Purpur)
Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Tuinity Changes:
c9cfdba Updated Upstream (Paper)

Purpur Changes:
d4301d4 Updated Upstream (Paper)
0e1cb93 wandering trader spawn rate config
67a42f6 Despawn rate config options per projectile type
7a1012e Drop "Use-arrow-despawn-rate-for-all-projectiles.patch"
8767574 Fix #56 Fix #50 - Ridable baby and tameable settings
8ec6f6f Fix #46 - Essentials EC overriding Purpur
a919aa3 Updated Upstream (Paper & Tuinity)
2020-09-15 08:23:39 +03:00

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 323d489b1e690500986bc0cbb4c2c93cc193bf70..5274dcde8b06200357b11b77cc72ec415d4e47e4 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 42628d6dbf54977d34442f46c89b771af3af5b11..c80d47409fe02bc261d2dbb0569cdec979939655 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2420,4 +2420,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
}