mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 08:57:44 +01:00
Updated Upstream (Paper)
Upstream has released updates that appears to apply and compile correctly Paper Changes: a4f066cc Fix method profiler inbalance introduced in a2a9ffe (#3132) c65dcad3 Don't delay chunk unloads during entity ticking bc17ce69 Delay unsafe actions until after entity ticking is done - Fixes #3114 5553e6b3 Disable Sync Events firing Async errors during shutdown e12c51d9 Use better variable for isStopping() API 586ee2bb Remove patch for MC-111480, fixed in 1.14 09a94215 Remove streams from Mob AI System bb5c294e Fix Disabling Asynchronous Chunks 089d8356 Implement Chunk Priority / Urgency System for World Gen fce69af7 Use dedicated thread for main thread blocking chunk loads 588b62e4 Add tick times API and /mspt command (#3102) 11de41c7 Add API MinecraftServer#isStopping (#3129) 942ff3c2 My patches are under MIT (#3130)
This commit is contained in:
103
patches/server/0098-Add-mspt-command.patch
Normal file
103
patches/server/0098-Add-mspt-command.patch
Normal file
@@ -0,0 +1,103 @@
|
||||
From 28c67bdc1d03076db4d750dec7eef75241d74f62 Mon Sep 17 00:00:00 2001
|
||||
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
||||
Date: Fri, 13 Mar 2020 22:23:44 -0500
|
||||
Subject: [PATCH] Add /mspt command
|
||||
|
||||
---
|
||||
.../minecraft/server/CommandDispatcher.java | 1 +
|
||||
.../net/pl3x/purpur/command/MSPTCommand.java | 59 +++++++++++++++++++
|
||||
src/main/resources/purpur.lang | 2 +
|
||||
3 files changed, 62 insertions(+)
|
||||
create mode 100644 src/main/java/net/pl3x/purpur/command/MSPTCommand.java
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/CommandDispatcher.java b/src/main/java/net/minecraft/server/CommandDispatcher.java
|
||||
index 37b1a7947c..c9d1f94100 100644
|
||||
--- a/src/main/java/net/minecraft/server/CommandDispatcher.java
|
||||
+++ b/src/main/java/net/minecraft/server/CommandDispatcher.java
|
||||
@@ -106,6 +106,7 @@ public class CommandDispatcher {
|
||||
CommandIdleTimeout.a(this.b);
|
||||
CommandStop.a(this.b);
|
||||
CommandWhitelist.a(this.b);
|
||||
+ net.pl3x.purpur.command.MSPTCommand.register(getDispatcher()); // Purpur
|
||||
}
|
||||
|
||||
this.b.findAmbiguities((commandnode, commandnode1, commandnode2, collection) -> {
|
||||
diff --git a/src/main/java/net/pl3x/purpur/command/MSPTCommand.java b/src/main/java/net/pl3x/purpur/command/MSPTCommand.java
|
||||
new file mode 100644
|
||||
index 0000000000..c3ffe528d4
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/command/MSPTCommand.java
|
||||
@@ -0,0 +1,59 @@
|
||||
+package net.pl3x.purpur.command;
|
||||
+
|
||||
+import net.minecraft.server.CommandDispatcher;
|
||||
+import net.minecraft.server.CommandListenerWrapper;
|
||||
+import net.minecraft.server.LocaleLanguage;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
+import org.bukkit.ChatColor;
|
||||
+
|
||||
+import java.text.DecimalFormat;
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.Arrays;
|
||||
+import java.util.List;
|
||||
+
|
||||
+public class MSPTCommand {
|
||||
+ private static final DecimalFormat DF = new DecimalFormat("########0.0");
|
||||
+
|
||||
+ public static void register(com.mojang.brigadier.CommandDispatcher<CommandListenerWrapper> dispatcher) {
|
||||
+ dispatcher.register(CommandDispatcher.register("mspt")
|
||||
+ .requires((listener) -> {
|
||||
+ return listener.hasPermission(2);
|
||||
+ })
|
||||
+ .executes((context) -> {
|
||||
+ return execute(context.getSource());
|
||||
+ })
|
||||
+ ).setPermission("bukkit.command.mspt");
|
||||
+ }
|
||||
+
|
||||
+ private static int execute(CommandListenerWrapper sender) {
|
||||
+ MinecraftServer server = MinecraftServer.getServer();
|
||||
+
|
||||
+ List<String> times = new ArrayList<>();
|
||||
+ times.addAll(eval(server.tickTimes5s.getTimes()));
|
||||
+ times.addAll(eval(server.tickTimes10s.getTimes()));
|
||||
+ times.addAll(eval(server.tickTimes60s.getTimes()));
|
||||
+
|
||||
+ sender.sendMessage(LocaleLanguage.translate("commands.purpur.mspt"), false);
|
||||
+ sender.sendMessage(LocaleLanguage.translate("commands.purpur.mspt.times", times.toArray()), false);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ private static List<String> eval(long[] times) {
|
||||
+ long min = Integer.MAX_VALUE;
|
||||
+ long max = 0L;
|
||||
+ long total = 0L;
|
||||
+ for (long value : times) {
|
||||
+ if (value > 0L && value < min) min = value;
|
||||
+ if (value > max) max = value;
|
||||
+ total += value;
|
||||
+ }
|
||||
+ double avgD = ((double) total / (double) times.length) * 1.0E-6D;
|
||||
+ double minD = ((double) min) * 1.0E-6D;
|
||||
+ double maxD = ((double) max) * 1.0E-6D;
|
||||
+ return Arrays.asList(getColor(avgD), getColor(minD), getColor(maxD));
|
||||
+ }
|
||||
+
|
||||
+ private static String getColor(double avg) {
|
||||
+ return ChatColor.COLOR_CHAR + (avg >= 50 ? "c" : avg >= 40 ? "e" : "a") + DF.format(avg);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/resources/purpur.lang b/src/main/resources/purpur.lang
|
||||
index f4694dbcce..151ea90928 100644
|
||||
--- a/src/main/resources/purpur.lang
|
||||
+++ b/src/main/resources/purpur.lang
|
||||
@@ -1,4 +1,6 @@
|
||||
{
|
||||
+ "commands.purpur.mspt": "§6Server tick times §e(§7avg§e/§7min§e/§7max§e)§6 from last 5s§7,§6 10s§7,§6 1m§e:",
|
||||
+ "commands.purpur.mspt.times": "§6◴ %s§7/%s§7/%s§e, %s§7/%s§7/%s§e, %s§7/%s§7/%s",
|
||||
"idle.timeout.broadcast.away": "§e§o%s is now AFK",
|
||||
"idle.timeout.broadcast.back": "§e§o%s is no longer AFK"
|
||||
}
|
||||
--
|
||||
2.24.0
|
||||
|
||||
Reference in New Issue
Block a user