Yatopia/patches/server/0039-Add-nspt-command.patch
Simon Gardling 61f261ee2a
Updated Upstream and Sidestream(s) (Paper/Airplane/Purpur/Empirecraft/Origami) (#474)
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.

Paper Changes:
b8020379c Extract Adventure Version into a variable, add reminder to update the linked JD on the homepage (#5422)
809466f2e Fix anchor respawn acting as a bed respawn when using the end portal (#5540)
d219fd642 [Auto] Updated Upstream (Bukkit/CraftBukkit)
db464b099 Implement methods to convert between Component and Brigadier's Message (#5542)
4047cffca Add PlayerBedFailEnterEvent (#4935)
70d697e6e Update Paperpclip
5ed771591 [CI-SKIP] Remove bad null annotation (#5538)
454a4c78e More World API (#3850)
869e02304 Add PlayerDeepSleepEvent (#5525)
fb56fc35e fix non-dummy objectives not updating
dc859a61f [CI-SKIP] [Auto] Rebuild Patches
7d1689f1a  Add missing checkReachable check for shulker boxes (#5453)
ba8eb3d4b Add missing Javadoc for COLORABLE MaterialTag (#5376)
db801cbf3 Fix PlayerItemHeldEvent firing twice (#5534)
14de2b795 fix PigZombieAngerEvent cancellation (fixes #5319) (v2) (#5329)
86d684ad1 Add get-set drop chance to EntityEquipment (#5528)
33fb8cf63 Add consumeFuel to FurnaceBurnEvent (#5532)
9957f4630 Fix duplicating /give items on item drop cancel (#5536)
d94882043 Fix legacyComposer not using AsyncChatEvent messages (#5509)
053bd82cc Don't print spawn load time when not loading spawn (#5467)
a6d78caae Add isDeeplySleeping to HumanEntity (#5470)
711b7a80b Expose more Adventure serializers through PaperComponents (#5443)
3f63bde0c Set Area Effect Cloud Rotation (#5462)
3523f0fda Remove useless check on player interact cancellation (#5448)
6574d1aa8 fix #5526 - use correct type when sending message to clients
dbfa833ec don't throw when loading TE with invalid keys
a9525a6f7 Do not schedule poi task for each block write on chunk gen

Airplane Changes:
f5fb024 Temporarily revert patch
3c728a7 Oops, these 2 too
37a93e5 Your daily dose of 1-3% optimization patches
bbd689a Remove useless check
d8bdbc5 Reduce allocations for fire spreading
41051fd Redo reduction of entity chunk ticking check patch
31272d8 Flare Update
8f32713 Remove criterion patch
0fed2df Various patches that need to be reorganized later
f78856b Updated Upstream (Tuinity)
f7d6382 Flare Update
71d0799 Update gradle configuration
0f79774 Updated Upstream (Tuinity)

Purpur Changes:
3dce975 Updated Upstream (Paper & Airplane) (#298)
eb07368 Run GitHub Actions for pull requests
e97d062 Updated Upstream (Paper, Tuinity, & Airplane)

Empirecraft Changes:
2a021ede Updated Paper
e963bb2c Add Paper MojangAPI to pom
6f5bf24e Updated Paper

Origami Changes:
73ecdf1 Update Paper
73a3735 Item and exp merge improvements
2021-04-27 12:40:55 -04:00

145 lines
6.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Wed, 30 Sep 2020 18:05:45 +0300
Subject: [PATCH] Add nspt command
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index bb8022ace764bbfcc434c193c7fa97c5e1da4000..7644c58b4c3353d293f86e20b54e55972704246a 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -235,6 +235,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
DedicatedServer.LOGGER.error("Unable to load server configuration", e);
return false;
}
+ org.yatopiamc.yatopia.server.YatopiaConfig.registerCommands();
// Yatopia end
de.minebench.origami.OrigamiConfig.init((java.io.File) options.valueOf("origami-settings"));
this.setPVP(dedicatedserverproperties.pvp);
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index bf7d1480609d4cfc79c772d3b80255e0138404d8..e35a976951f36201204008edff63ad6ee356805b 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -924,6 +924,7 @@ public final class CraftServer implements Server {
org.spigotmc.SpigotConfig.registerCommands(); // Spigot
com.destroystokyo.paper.PaperConfig.registerCommands(); // Paper
net.pl3x.purpur.PurpurConfig.registerCommands(); // Purpur
+ org.yatopiamc.yatopia.server.YatopiaConfig.registerCommands(); // Yatopia
overrideAllCommandBlockCommands = commandsConfiguration.getStringList("command-block-overrides").contains("*");
ignoreVanillaPermissions = commandsConfiguration.getBoolean("ignore-vanilla-permissions");
diff --git a/src/main/java/org/yatopiamc/yatopia/server/NSPTCommand.java b/src/main/java/org/yatopiamc/yatopia/server/NSPTCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..e6eaa07c57e04bbfba9e4aa8e0e939f85169d0c8
--- /dev/null
+++ b/src/main/java/org/yatopiamc/yatopia/server/NSPTCommand.java
@@ -0,0 +1,59 @@
+package org.yatopiamc.yatopia.server;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import net.minecraft.server.MinecraftServer;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+
+public class NSPTCommand extends Command {
+
+ public NSPTCommand(String name) {
+ super(name);
+ this.description = "View server tick times in nanoseconds";
+ this.usageMessage = "/nspt";
+ this.setPermission("bukkit.command.nspt");
+ }
+
+ @Override
+ public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public boolean execute(CommandSender sender, String commandLabel, String[] args) {
+ if (!testPermission(sender)) return true;
+
+ 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("§6Server tick NS times §e(§7avg§e/§7min§e/§7max§e)§6 from last 5s§7,§6 10s§7,§6 1m§e:");
+ sender.sendMessage(String.format("§6◴ %s§7/%s§7/%s§e, %s§7/%s§7/%s§e, %s§7/%s§7/%s", times.toArray()));
+ return true;
+ }
+
+ 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);
+ return Arrays.asList(getColor(avgD), getColor(min), getColor(max));
+ }
+
+ private static String getColor(double avg) {
+ return ChatColor.COLOR_CHAR + (avg >= 5E+7 ? "c" : avg >= (4E+7) ? "e" : "a") + avg;
+ }
+}
diff --git a/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
index 003a024da8ab877895244ff9e4e4ff62288622ff..f6a8f3c4e92455eff806978d503751b6723ea858 100644
--- a/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
+++ b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
@@ -6,11 +6,14 @@ import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
+import org.bukkit.command.Command;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -24,6 +27,7 @@ public class YatopiaConfig {
public static YamlConfiguration config;
public static int version; // since we're remapping sidestreams' configs we need this public
public static boolean verbose; // since we're remapping sidestreams' configs we need this public
+ private static Map<String, Command> commands;
/*========================================================================*/
public static void init(File configFile) {
@@ -39,6 +43,8 @@ public class YatopiaConfig {
config.options().header(HEADER);
config.options().copyDefaults(true);
verbose = getBoolean("verbose", false);
+ commands = new HashMap<>();
+ commands.put("nspt", new NSPTCommand("nspt"));
version = getInt("config-version", 1);
set("config-version", 1);
@@ -46,6 +52,12 @@ public class YatopiaConfig {
readConfig(YatopiaConfig.class, null);
}
+ public static void registerCommands() {
+ for (Map.Entry<String, Command> entry : commands.entrySet()) {
+ net.minecraft.server.MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "Yatopia", entry.getValue());
+ }
+ }
+
private static void removeLeftovers() {
// this method is only to remove non-used values in the config