2020-09-30 17:35:35 +02:00
|
|
|
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/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
2020-12-13 16:18:57 +01:00
|
|
|
index 64b662dc9146d0d414a9668d9b93e07aa6665f32..2473eb88ec7be3f4935debe04eeabcc0815b3233 100644
|
2020-09-30 17:35:35 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
2020-11-07 08:02:33 +01:00
|
|
|
@@ -187,6 +187,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
2020-09-30 17:35:35 +02:00
|
|
|
DedicatedServer.LOGGER.error("Unable to load server configuration", e);
|
|
|
|
return false;
|
|
|
|
}
|
2020-12-02 07:35:11 +01:00
|
|
|
+ org.yatopiamc.yatopia.server.YatopiaConfig.registerCommands();
|
2020-09-30 17:35:35 +02:00
|
|
|
// Yatopia end
|
2020-11-07 08:02:33 +01:00
|
|
|
de.minebench.origami.OrigamiConfig.init((java.io.File) options.valueOf("origami-settings"));
|
2020-09-30 17:35:35 +02:00
|
|
|
this.setPVP(dedicatedserverproperties.pvp);
|
2020-12-02 07:35:11 +01:00
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2021-01-21 11:58:52 +01:00
|
|
|
index 3d52621bf068517b2d959c65aea211f93b8d4497..7d0f73c83a7f7f3c6becf3ed4348c6b2938a86b1 100644
|
2020-12-02 07:35:11 +01:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
2020-12-13 16:18:57 +01:00
|
|
|
@@ -921,6 +921,7 @@ public final class CraftServer implements Server {
|
2020-12-02 07:35:11 +01:00
|
|
|
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
|
2020-09-30 17:35:35 +02:00
|
|
|
new file mode 100644
|
2020-12-02 07:35:11 +01:00
|
|
|
index 0000000000000000000000000000000000000000..e6eaa07c57e04bbfba9e4aa8e0e939f85169d0c8
|
2020-09-30 17:35:35 +02:00
|
|
|
--- /dev/null
|
2020-12-02 07:35:11 +01:00
|
|
|
+++ b/src/main/java/org/yatopiamc/yatopia/server/NSPTCommand.java
|
2020-09-30 17:35:35 +02:00
|
|
|
@@ -0,0 +1,59 @@
|
2020-12-02 07:35:11 +01:00
|
|
|
+package org.yatopiamc.yatopia.server;
|
2020-10-01 13:13:08 +02:00
|
|
|
+
|
|
|
|
+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;
|
|
|
|
+ }
|
|
|
|
+}
|
2020-12-02 07:35:11 +01:00
|
|
|
diff --git a/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
|
2021-01-24 16:52:19 +01:00
|
|
|
index 003a024da8ab877895244ff9e4e4ff62288622ff..f6a8f3c4e92455eff806978d503751b6723ea858 100644
|
2020-12-02 07:35:11 +01:00
|
|
|
--- a/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
|
|
|
|
+++ b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
|
2021-01-24 16:52:19 +01:00
|
|
|
@@ -6,11 +6,14 @@ import java.io.IOException;
|
2020-09-30 17:35:35 +02:00
|
|
|
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;
|
|
|
|
|
2021-01-24 16:52:19 +01:00
|
|
|
@@ -24,6 +27,7 @@ public class YatopiaConfig {
|
2020-09-30 17:35:35 +02:00
|
|
|
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) {
|
2021-01-24 16:52:19 +01:00
|
|
|
@@ -39,6 +43,8 @@ public class YatopiaConfig {
|
2020-09-30 17:35:35 +02:00
|
|
|
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);
|
2021-01-24 16:52:19 +01:00
|
|
|
@@ -46,6 +52,12 @@ public class YatopiaConfig {
|
2020-09-30 17:35:35 +02:00
|
|
|
readConfig(YatopiaConfig.class, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public static void registerCommands() {
|
|
|
|
+ for (Map.Entry<String, Command> entry : commands.entrySet()) {
|
2021-01-24 16:52:19 +01:00
|
|
|
+ net.minecraft.server.MinecraftServer.getServer().server.getCommandMap().register(entry.getKey(), "Yatopia", entry.getValue());
|
2020-09-30 17:35:35 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
private static void removeLeftovers() {
|
|
|
|
// this method is only to remove non-used values in the config
|
|
|
|
|