mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Update /mspt command to brigadier and lang asset
This commit is contained in:
@@ -1,83 +1,74 @@
|
||||
From e690003f267cb1970c3ba1f56f50fd142fabf73a Mon Sep 17 00:00:00 2001
|
||||
From 0d62cef2d76283db36e227544c3820f89a04cf3f 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(+)
|
||||
.../minecraft/server/CommandDispatcher.java | 1 +
|
||||
.../net/pl3x/purpur/command/MSPTCommand.java | 59 +++++++++++++++++++
|
||||
.../assets/minecraft/lang/en_us.json | 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/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;
|
||||
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
|
||||
}
|
||||
|
||||
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);
|
||||
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..941dbf0863
|
||||
index 0000000000..e3b75f9c41
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/pl3x/purpur/command/MSPTCommand.java
|
||||
@@ -0,0 +1,63 @@
|
||||
@@ -0,0 +1,59 @@
|
||||
+package net.pl3x.purpur.command;
|
||||
+
|
||||
+import com.google.common.collect.ImmutableList;
|
||||
+
|
||||
+import net.minecraft.server.ChatMessage;
|
||||
+import net.minecraft.server.CommandDispatcher;
|
||||
+import net.minecraft.server.CommandListenerWrapper;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
+import org.bukkit.ChatColor;
|
||||
+import org.bukkit.command.CommandSender;
|
||||
+import org.bukkit.command.defaults.BukkitCommand;
|
||||
+
|
||||
+import java.text.DecimalFormat;
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.Arrays;
|
||||
+import java.util.List;
|
||||
+
|
||||
+public class MSPTCommand extends BukkitCommand {
|
||||
+ private static final java.text.DecimalFormat DF = new java.text.DecimalFormat("########0.0");
|
||||
+public class MSPTCommand {
|
||||
+ private static final DecimalFormat DF = new 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");
|
||||
+ public static void register(com.mojang.brigadier.CommandDispatcher<CommandListenerWrapper> dispatcher) {
|
||||
+ dispatcher.register(CommandDispatcher.register("mspt")
|
||||
+ .requires((listener) -> {
|
||||
+ return listener.hasPermission(2, "bukkit.command.mspt");
|
||||
+ })
|
||||
+ .executes((context) -> {
|
||||
+ return execute(context.getSource());
|
||||
+ }));
|
||||
+ }
|
||||
+
|
||||
+ @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;
|
||||
+ }
|
||||
+
|
||||
+ private static int execute(CommandListenerWrapper sender) {
|
||||
+ 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;
|
||||
+ 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(new ChatMessage("commands.purpur.mspt"), false);
|
||||
+ sender.sendMessage(new ChatMessage("commands.purpur.mspt.times", times.toArray()), false);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ public static String eval(long[] times) {
|
||||
+ private static List<String> eval(long[] times) {
|
||||
+ long min = Integer.MAX_VALUE;
|
||||
+ long max = 0L;
|
||||
+ long total = 0L;
|
||||
@@ -89,15 +80,26 @@ index 0000000000..941dbf0863
|
||||
+ 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);
|
||||
+ return Arrays.asList(getColor(avgD), getColor(minD), getColor(maxD));
|
||||
+ }
|
||||
+
|
||||
+ private static String getColor(double avg) {
|
||||
+ return avg >= 50 ? "&c" : avg >= 40 ? "&e" : "&a";
|
||||
+ return ChatColor.COLOR_CHAR + (avg >= 50 ? "c" : avg >= 40 ? "e" : "a") + DF.format(avg);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/resources/assets/minecraft/lang/en_us.json b/src/main/resources/assets/minecraft/lang/en_us.json
|
||||
index ae0b45fe41..09816cedfc 100644
|
||||
--- a/src/main/resources/assets/minecraft/lang/en_us.json
|
||||
+++ b/src/main/resources/assets/minecraft/lang/en_us.json
|
||||
@@ -4071,6 +4071,8 @@
|
||||
"commands.spectate.success.started": "Now spectating %s",
|
||||
"commands.spectate.not_spectator": "%s is not in spectator mode",
|
||||
"commands.spectate.self": "Cannot spectate yourself",
|
||||
+ "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",
|
||||
"argument.range.empty": "Expected value or range of values",
|
||||
"argument.range.ints": "Only whole numbers allowed, not decimals",
|
||||
"argument.range.swapped": "Min cannot be bigger than max",
|
||||
--
|
||||
2.24.0
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
From 0fa2b2131a54e8622238ab538933a0454a27b4d4 Mon Sep 17 00:00:00 2001
|
||||
From ca4d608c6e987a44f467fae90f5bf036763ad3a4 Mon Sep 17 00:00:00 2001
|
||||
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
||||
Date: Fri, 13 Mar 2020 22:29:10 -0500
|
||||
Subject: [PATCH] Add /ping command
|
||||
@@ -7,10 +7,9 @@ Subject: [PATCH] Add /ping command
|
||||
.../net/minecraft/server/ArgumentEntity.java | 2 ++
|
||||
.../minecraft/server/CommandDispatcher.java | 5 ++-
|
||||
.../server/CommandListenerWrapper.java | 1 +
|
||||
.../java/net/pl3x/purpur/PurpurConfig.java | 1 +
|
||||
.../net/pl3x/purpur/command/PingCommand.java | 34 +++++++++++++++++++
|
||||
.../assets/minecraft/lang/en_us.json | 1 +
|
||||
6 files changed, 43 insertions(+), 1 deletion(-)
|
||||
5 files changed, 42 insertions(+), 1 deletion(-)
|
||||
create mode 100644 src/main/java/net/pl3x/purpur/command/PingCommand.java
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/ArgumentEntity.java b/src/main/java/net/minecraft/server/ArgumentEntity.java
|
||||
@@ -31,7 +30,7 @@ index 39a6a9ac00..5568649b7e 100644
|
||||
List<EntityPlayer> list = ((EntitySelector) commandcontext.getArgument(s, EntitySelector.class)).d((CommandListenerWrapper) commandcontext.getSource());
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/CommandDispatcher.java b/src/main/java/net/minecraft/server/CommandDispatcher.java
|
||||
index 37b1a7947c..b38a5223cb 100644
|
||||
index c9d1f94100..3b15f953bc 100644
|
||||
--- a/src/main/java/net/minecraft/server/CommandDispatcher.java
|
||||
+++ b/src/main/java/net/minecraft/server/CommandDispatcher.java
|
||||
@@ -30,7 +30,7 @@ import org.bukkit.event.server.ServerCommandEvent;
|
||||
@@ -43,15 +42,15 @@ index 37b1a7947c..b38a5223cb 100644
|
||||
|
||||
// CraftBukkit start
|
||||
public final CommandDispatcher init(boolean flag) {
|
||||
@@ -106,6 +106,7 @@ public class CommandDispatcher {
|
||||
CommandIdleTimeout.a(this.b);
|
||||
@@ -107,6 +107,7 @@ public class CommandDispatcher {
|
||||
CommandStop.a(this.b);
|
||||
CommandWhitelist.a(this.b);
|
||||
net.pl3x.purpur.command.MSPTCommand.register(getDispatcher()); // Purpur
|
||||
+ net.pl3x.purpur.command.PingCommand.register(getDispatcher()); // Purpur
|
||||
}
|
||||
|
||||
this.b.findAmbiguities((commandnode, commandnode1, commandnode2, collection) -> {
|
||||
@@ -315,10 +316,12 @@ public class CommandDispatcher {
|
||||
@@ -316,10 +317,12 @@ public class CommandDispatcher {
|
||||
|
||||
}
|
||||
|
||||
@@ -76,18 +75,6 @@ index 0b23a0548d..ab0cf8b561 100644
|
||||
public EntityPlayer h() throws CommandSyntaxException {
|
||||
if (!(this.k instanceof EntityPlayer)) {
|
||||
throw CommandListenerWrapper.a.create();
|
||||
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
index 63a91e7b7a..f9f83e5b9a 100644
|
||||
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
@@ -3,6 +3,7 @@ package net.pl3x.purpur;
|
||||
import com.google.common.base.Throwables;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.pl3x.purpur.command.MSPTCommand;
|
||||
+import net.pl3x.purpur.command.PingCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
diff --git a/src/main/java/net/pl3x/purpur/command/PingCommand.java b/src/main/java/net/pl3x/purpur/command/PingCommand.java
|
||||
new file mode 100644
|
||||
index 0000000000..3aea2a76db
|
||||
@@ -129,13 +116,13 @@ index 0000000000..3aea2a76db
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/resources/assets/minecraft/lang/en_us.json b/src/main/resources/assets/minecraft/lang/en_us.json
|
||||
index ae0b45fe41..2d7d38d2fb 100644
|
||||
index 09816cedfc..e6b0c86b03 100644
|
||||
--- a/src/main/resources/assets/minecraft/lang/en_us.json
|
||||
+++ b/src/main/resources/assets/minecraft/lang/en_us.json
|
||||
@@ -4071,6 +4071,7 @@
|
||||
"commands.spectate.success.started": "Now spectating %s",
|
||||
"commands.spectate.not_spectator": "%s is not in spectator mode",
|
||||
@@ -4073,6 +4073,7 @@
|
||||
"commands.spectate.self": "Cannot spectate yourself",
|
||||
"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",
|
||||
+ "commands.purpur.ping": "§a%s's ping is %sms",
|
||||
"argument.range.empty": "Expected value or range of values",
|
||||
"argument.range.ints": "Only whole numbers allowed, not decimals",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
From 2ef2f6347e1e49d46ed569889ec5fbcfaaa29d62 Mon Sep 17 00:00:00 2001
|
||||
From db58bb38aaaae12c17ffdd206d0016448209d7d5 Mon Sep 17 00:00:00 2001
|
||||
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
||||
Date: Sat, 21 Mar 2020 11:47:39 -0500
|
||||
Subject: [PATCH] Configurable server mod name
|
||||
@@ -22,10 +22,10 @@ index 5d28185248..c5319ff0f5 100644
|
||||
|
||||
public CrashReport b(CrashReport crashreport) {
|
||||
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
index f9f83e5b9a..942f91059d 100644
|
||||
index a18333ad6c..90a44a539c 100644
|
||||
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
||||
@@ -204,6 +204,11 @@ public class PurpurConfig {
|
||||
@@ -201,6 +201,11 @@ public class PurpurConfig {
|
||||
recalculatePermsOnWorldChange = getBoolean("settings.recalculate-perms-on-world-change", recalculatePermsOnWorldChange);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
From beb5ae19e6d8056090d8fec450566a2df1392c77 Mon Sep 17 00:00:00 2001
|
||||
From ebec2174c178ca46126aeb055da04d7f4e64f383 Mon Sep 17 00:00:00 2001
|
||||
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
||||
Date: Thu, 26 Mar 2020 12:48:02 -0500
|
||||
Subject: [PATCH] Disable mojang profiler
|
||||
@@ -160,7 +160,7 @@ index d1af8e9a92..9da9f54d18 100644
|
||||
|
||||
// Paper start
|
||||
diff --git a/src/main/resources/assets/minecraft/lang/en_us.json b/src/main/resources/assets/minecraft/lang/en_us.json
|
||||
index 2d7d38d2fb..c5d6a73d01 100644
|
||||
index e6b0c86b03..4311098415 100644
|
||||
--- a/src/main/resources/assets/minecraft/lang/en_us.json
|
||||
+++ b/src/main/resources/assets/minecraft/lang/en_us.json
|
||||
@@ -4071,6 +4071,7 @@
|
||||
@@ -168,9 +168,9 @@ index 2d7d38d2fb..c5d6a73d01 100644
|
||||
"commands.spectate.not_spectator": "%s is not in spectator mode",
|
||||
"commands.spectate.self": "Cannot spectate yourself",
|
||||
+ "commands.purpur.debug.disabled": "The debug profiler is disabled",
|
||||
"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",
|
||||
"commands.purpur.ping": "§a%s's ping is %sms",
|
||||
"argument.range.empty": "Expected value or range of values",
|
||||
"argument.range.ints": "Only whole numbers allowed, not decimals",
|
||||
--
|
||||
2.24.0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user