mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 00:47:42 +01:00
Move lang asset patch higher in the order
This commit is contained in:
103
patches/server/0106-Add-mspt-command.patch
Normal file
103
patches/server/0106-Add-mspt-command.patch
Normal file
@@ -0,0 +1,103 @@
|
||||
From e690003f267cb1970c3ba1f56f50fd142fabf73a 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
|
||||
|
||||
---
|
||||
.../java/net/pl3x/purpur/PurpurConfig.java | 2 +
|
||||
.../net/pl3x/purpur/command/MSPTCommand.java | 63 +++++++++++++++++++
|
||||
2 files changed, 65 insertions(+)
|
||||
create mode 100644 src/main/java/net/pl3x/purpur/command/MSPTCommand.java
|
||||
|
||||
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
index a18333ad6c..63a91e7b7a 100644
|
||||
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
@@ -2,6 +2,7 @@ package net.pl3x.purpur;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
+import net.pl3x.purpur.command.MSPTCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
@@ -53,6 +54,7 @@ public class PurpurConfig {
|
||||
|
||||
commands = new HashMap<>();
|
||||
commands.put("purpur", new PurpurCommand("purpur"));
|
||||
+ commands.put("mspt", new MSPTCommand("mspt"));
|
||||
|
||||
version = getInt("config-version", 4);
|
||||
set("config-version", 4);
|
||||
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..941dbf0863
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/command/MSPTCommand.java
|
||||
@@ -0,0 +1,63 @@
|
||||
+package net.pl3x.purpur.command;
|
||||
+
|
||||
+import com.google.common.collect.ImmutableList;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
+import org.bukkit.ChatColor;
|
||||
+import org.bukkit.command.CommandSender;
|
||||
+import org.bukkit.command.defaults.BukkitCommand;
|
||||
+
|
||||
+import java.util.List;
|
||||
+
|
||||
+public class MSPTCommand extends BukkitCommand {
|
||||
+ private static final java.text.DecimalFormat DF = new java.text.DecimalFormat("########0.0");
|
||||
+
|
||||
+ public MSPTCommand(String name) {
|
||||
+ super(name);
|
||||
+
|
||||
+ this.description = "Gets the average tick time (mspt)";
|
||||
+ this.usageMessage = "/mspt";
|
||||
+ this.setPermission("bukkit.command.mspt");
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
|
||||
+ return ImmutableList.of();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
||||
+ if (!testPermission(sender)) {
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ MinecraftServer server = MinecraftServer.getServer();
|
||||
+
|
||||
+ sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6Server tick times &e(&7avg&e/&7min&e/&7max&e)&6 from last 5s&7,&6 10s&7,&6 1m&e:"));
|
||||
+ sender.sendMessage(ChatColor.translateAlternateColorCodes('&', String.format("&6\u25F4 %s&e, %s&e, %s",
|
||||
+ eval(server.tickTimes5s.getTimes()),
|
||||
+ eval(server.tickTimes10s.getTimes()),
|
||||
+ eval(server.tickTimes60s.getTimes()))));
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ public static 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 getColor(avgD) + DF.format(avgD) + "&7/" +
|
||||
+ getColor(minD) + DF.format(minD) + "&7/" +
|
||||
+ getColor(maxD) + DF.format(maxD);
|
||||
+ }
|
||||
+
|
||||
+ private static String getColor(double avg) {
|
||||
+ return avg >= 50 ? "&c" : avg >= 40 ? "&e" : "&a";
|
||||
+ }
|
||||
+}
|
||||
--
|
||||
2.24.0
|
||||
|
||||
Reference in New Issue
Block a user