mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-21 15:59:26 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@abc49bf Begin update to 1.20.5 PaperMC/Paper@f2c45ed do some work PaperMC/Paper@00c14f2 Move logging patches after adventure PaperMC/Paper@ef057bb work on Adventure patch PaperMC/Paper@380c4d2 Add plugin remapping patches PaperMC/Paper@7cdf804 Work PaperMC/Paper@dd6ce09 Fix reflection diff and order wrt commodore diff PaperMC/Paper@598a1cb Apply shadow removal patch PaperMC/Paper@ffccfd5 Apply timings PaperMC/Paper@eb41348 33 PaperMC/Paper@9cac5b6 Fix continueServerUpdate with 2-line subjects PaperMC/Paper@2eeed9e 41 PaperMC/Paper@d07c487 Don't use defaultToolchain method for run tasks PaperMC/Paper@f2350fe Set mercury sourceCompat PaperMC/Paper@5cfd92b Fix api compile PaperMC/Paper@862d004 work on some API stuff PaperMC/Paper@d6a3c0c fix 2 of our javadoc errors PaperMC/Paper@487555b update PaperMC/Paper@0225537 Update upstream PaperMC/Paper@906f906 Patches! PaperMC/Paper@8244815 221 PaperMC/Paper@309ebc1 253 PaperMC/Paper@1d7d7e9 301 PaperMC/Paper@9079c90 354 PaperMC/Paper@cc46148 405 PaperMC/Paper@5be858e Patches! PaperMC/Paper@2d9d0d8 Patches! PaperMC/Paper@a403a8d Patches!!!!!!! PaperMC/Paper@21afc0a Patches!!!!!!! PaperMC/Paper@1de0dc8 666 plus 1 PaperMC/Paper@4e654f2 More patch work PaperMC/Paper@e832328 Check for existing am session before running continueServerUpdate PaperMC/Paper@fc5c0da 683 PaperMC/Paper@90095cd 694 PaperMC/Paper@71ae391 more work (721) PaperMC/Paper@22227cc more more work (757) PaperMC/Paper@4d9e824 more more work (806) PaperMC/Paper@9617829 Restore original formatting for MC-252817 patch PaperMC/Paper@0518559 Update reflection rewriter to 0.0.1 release PaperMC/Paper@e0a245d Patches!!!!!!! PaperMC/Paper@1104431 955 PaperMC/Paper@1df7e21 Apply more API-implementing patches PaperMC/Paper@b733809 Drop conduit api patch (upstream implemented same api with same method signatures) PaperMC/Paper@c95db4f adventure 4.17.0-SNAPSHOT PaperMC/Paper@bb1351c some work on adventure PaperMC/Paper@1444b36 work on adventure PaperMC/Paper@ce0e78c compile fixes PaperMC/Paper@25f7c68 compile fixes PaperMC/Paper@690b1cd compile fixes PaperMC/Paper@b673721 compile fixes PaperMC/Paper@6a87d14 dataconverter PaperMC/Paper@ec9f7e3 starlight PaperMC/Paper@e9eec78 chunk system PaperMC/Paper@f6ea373 Patches PaperMC/Paper@ec4ada8 Apply and move up non-optimization patches PaperMC/Paper@c9907c6 More patches PaperMC/Paper@2debcaf More more patches, including hopper optimization patch PaperMC/Paper@6da0d8c (Almost) all patches applied PaperMC/Paper@345b5c1 Patches!!!!!!! (we are done) PaperMC/Paper@4590038 Fix properly resend patches PaperMC/Paper@457e2c8 pass more stuff PaperMC/Paper@b8da9ac item meta patch work PaperMC/Paper@ccf158a update smithing recipe copy data components API PaperMC/Paper@653f043 readd fix bee aging patch PaperMC/Paper@bab31b6 Update Enchantment damage increase API PaperMC/Paper@f4c7639 Un-jankify root user detection PaperMC/Paper@9c58056 Some more compilation fixes PaperMC/Paper@b984f66 Missing FQN in CraftPotionBrewer getter PaperMC/Paper@768befe Remove patch renaming scripts PaperMC/Paper@04a25c2 Fix WorldCreator#keepSpawnLoaded PaperMC/Paper@820f999 Fixes for cb pkg ver PaperMC/Paper@ca9001a compile fixes PaperMC/Paper@d01f6b2 Fix more compile issues PaperMC/Paper@8d3759d More more compile fixes PaperMC/Paper@ed79038 More compile fixes PaperMC/Paper@2641c02 Updated Upstream (Bukkit/CraftBukkit) PaperMC/Paper@68aea43 Fixup damage source change PaperMC/Paper@3062eb2 address my own comments PaperMC/Paper@e85e1ec fixup sus effect entry patches PaperMC/Paper@10e6143 fixup adventure's book meta handling PaperMC/Paper@a244281 Replace VanillaGradle use and update generated API PaperMC/Paper@31ad90b some more compile fixes PaperMC/Paper@d2ef062 generator fix PaperMC/Paper@7c6411b compile fixes PaperMC/Paper@867eb90 compile fixes PaperMC/Paper@62b96c5 compile fixes PaperMC/Paper@c5c2a5f hunk system fixes PaperMC/Paper@bcdf1f9 fixup loom pattern select event patch PaperMC/Paper@43d110e fix issue with item default attribute API PaperMC/Paper@2997fd6 plugin manager updates PaperMC/Paper@7e9da43 support patch versions in api-version PaperMC/Paper@813cfbf Fix compile issues PaperMC/Paper@478a971 Fix light setting in protochunk PaperMC/Paper@8b28f9f Fix accumulated total ticking chunks not being updated PaperMC/Paper@00dac83 Drop old decompile fix PaperMC/Paper@f6fae41 fix chat_type issue PaperMC/Paper@cc81668 fix some issues on the todo list PaperMC/Paper@44e68c3 fix some more issues PaperMC/Paper@1bc278b Update patched spigot decompiler to fix inconsistency based on processing order PaperMC/Paper@19ac9d4 remove no longer needed patches and fix tests PaperMC/Paper@e856d17 Update paper plugin check in PluginRemapper PaperMC/Paper@882ea0a fix adventure translations PaperMC/Paper@4c53ace fix exact choice recipes PaperMC/Paper@464cc81 fix custom potion mixes PaperMC/Paper@ff77f82 paperweight 1.6.0 PaperMC/Paper@6a4974b Remove shadow from build classpath PaperMC/Paper@c38f96b deprecate our ItemRarity API PaperMC/Paper@ba8512a fix javadocs for SpawnerEntry$Equipment API PaperMC/Paper@f1fc1b3 readd old UUID format patch PaperMC/Paper@5485043 Don't tell people to build the reobf jar PaperMC/Paper@2f19f0f fix enchantment order issue PaperMC/Paper@80bd015 fix adventure converters not using RegistryOps PaperMC/Paper@68e23db add back missing call to profile fill events PaperMC/Paper@9bac389 more fixes PaperMC/Paper@81f4405 add back hunk to async SavedData IO PaperMC/Paper@91b5de6 bunch of fixes and improvements PaperMC/Paper@f85d423 improve dumpitem and pgive commands PaperMC/Paper@5731f34 Restore Handle Large Packets Disconnecting Client Patch PaperMC/Paper@f037f08 Unify plugin remapping debug flags PaperMC/Paper@c82766d fix item flags PaperMC/Paper@f933c35 Update DataConverter to 1.20.6-rc1 PaperMC/Paper@55b1a87 fix PotionEffectType#getEffectAttributes PaperMC/Paper@0b1b1fe fix helmet damage reduction inconsistencies PaperMC/Paper@e2552ee Start cleaning up plugin remapping patches PaperMC/Paper@711dbd7 Bump adventure ansi serializer PaperMC/Paper@af97400 update generator PaperMC/Paper@b7e148a Move obfhelper/stack deobf diff into original patch PaperMC/Paper@a390119 Move cb version definition to gradle patch PaperMC/Paper@20af7a7 remove funny diff PaperMC/Paper@b3ea907 more ItemFlag fixes PaperMC/Paper@53d8edd properly check for experimental stuff in generator PaperMC/Paper@a771940 Revert to vanilla handling of LivingEntity#actuallyHurt (#10463) PaperMC/Paper@06cae13 Update jdk version and distribution in actions PaperMC/Paper@dd571d8 Fix bad diff in build gradle file PaperMC/Paper@d02bb81 proper migration to gamerules for keep spawn loaded distance PaperMC/Paper@aeb3f37 update paperweight to 1.6.1 PaperMC/Paper@75c22d5 Bump tiny-remapper PaperMC/Paper@8454786 Bump tiny-remapper (real) PaperMC/Paper@d99d84a Temporarily comment out adventure jd links PaperMC/Paper@83767f9 Use JetBrains runtime for run tasks PaperMC/Paper@4ad6022 improve checking handled tags in itemmeta (#9470) PaperMC/Paper@8ce62b3 Fix issue with hopppers PaperMC/Paper@7e3d5b5 bump paperweight to 1.6.2 to fix spurious build failure from scanJar OOM PaperMC/Paper@d964c15 fix last test issue PaperMC/Paper@3e90a19 Updated Upstream (Bukkit/CraftBukkit) PaperMC/Paper@d93c6f9 remove calls to DoNotUse methods PaperMC/Paper@f187fd6 Only scan `org.bukkit.craftbukkit.inventory` in `MetaHandledTagsTest` PaperMC/Paper@a3c4dc9 Fix the incorrect codec usage in the Style convert (#10465) PaperMC/Paper@e16263c Fix firework meta NPE PaperMC/Paper@306b203 more fixes for ItemMeta relating to components PaperMC/Paper@1a03cc9 Fix test compilation PaperMC/Paper@6e31f38 Fix book meta lacking resolved tag from older versions (Fixes #10470) PaperMC/Paper@37b3891 Fix another missing book meta tag PaperMC/Paper@c4a1cd1 Fix issue with empty lists in adventure predicates PaperMC/Paper@9d6e7e3 Don't hard fail on plugin remap error PaperMC/Paper@4491ac0 respect hard list size limits in ItemMeta PaperMC/Paper@aed7dca Fix overly strong name validation in player heads PaperMC/Paper@0f4d328 final missing validation for data components PaperMC/Paper@52ff3b7 Add itemName components (Resolves #10467) (#10471) PaperMC/Paper@ba673a3 [ci skip] Feature requests are now in GitHub Discussions (#10606) PaperMC/Paper@0f3e324 [ci skip] Fix discussion template file name (#10607) PaperMC/Paper@82a8012 [ci skip] adjust projects workflow for label changes PaperMC/Paper@61c9c07 Fix CraftMetaBlockState adding extra tags PaperMC/Paper@7f2d531 Rewrite reflection in library loader jars (#10608) PaperMC/Paper@05308fc Remap plugin libraries with namespace set to spigot (#10610) PaperMC/Paper@69a971a Reset component prototype on itemtype change PaperMC/Paper@f9397e1 Fix incorrect Commodore mapping of sweeping enchant PaperMC/Paper@8f7ac62 Validate manifest provided mapping namespace (#10612) PaperMC/Paper@fbe3c00 [ci skip] update projects workflow configuration PaperMC/Paper@44ee092 1.20.6 (#10623) PaperMC/Paper@812ccb9 fix spawnChunkRadius gamerule resetting PaperMC/Paper@25e44bc fix dumpitem command nbt format PaperMC/Paper@3fdd094 Fix sealed package check in BytecodeModifyingURLClassLoader (#10627) PaperMC/Paper@937a67a Add initial size cap to component map PaperMC/Paper@4ea67ab [ci skip] Remove trailing comma in projects action PaperMC/Paper@8c058f8 Update paperweight to 1.6.3 (#10626) PaperMC/Paper@fa6013d Fixes beds not exploding in the nether PaperMC/Paper@3e0eb4a Updated Upstream (CraftBukkit) (#10624) PaperMC/Paper@4cfd9e2 Expose canReach to mob pathfinding API (#10636) PaperMC/Paper@b8c454c Add damage check for mending (#10631) PaperMC/Paper@310b47b Update Java version references, add note on var usages PaperMC/Paper@faa7aa2 Add GameMode#isInvulnerable (#10633) PaperMC/Paper@18c201b Add EquipmentSlot#getOppositeHand (#10632) PaperMC/Paper@544ce20 Expose #hasColor to leather armor (#10638) PaperMC/Paper@59fe7cc default save-empty-scoreboard-teams to vanilla PaperMC/Paper@0db72ac Fix can_place_on conversion and size check for item containers PaperMC/Paper@156675c Fix lodestone compass target conversion PaperMC/Paper@5632210 add RegistryAccess for managing registries (#10154) PaperMC/Paper@6fcca46 Add missing step in V3818 PaperMC/Paper@7401313 fix shear drops for wolf and bogged PaperMC/Paper@7ae2c67 Keep components using single items in creative (#10664) PaperMC/Paper@b13c7db Add missing experimental field and annotations (#10653) PaperMC/Paper@9d8d38d Updated Upstream (CraftBukkit) (#10646) PaperMC/Paper@0e43d3c Added API to get player's proxy address (#10400) PaperMC/Paper@54c5ecb Add missing SpigotConfig logCommands check (#10659) PaperMC/Paper@816ea9e [ci skip] Update old particle reference in javadoc (#10652) PaperMC/Paper@716dfd8 Fix EntityLoadCrossbowEvent (#10645) PaperMC/Paper@21d91ce Prevent profile lookups when unnecessary (#10651) PaperMC/Paper@2a6a5fe Add a way to check whether the chest is blocked (#10635) PaperMC/Paper@ac3a547 Fix BlockStateMeta (#10647)
503 lines
23 KiB
Diff
503 lines
23 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Sun, 19 Sep 2021 01:10:02 +0100
|
|
Subject: [PATCH] TPS Graph Command
|
|
|
|
|
|
diff --git a/src/main/java/me/samsuik/sakura/command/SakuraCommands.java b/src/main/java/me/samsuik/sakura/command/SakuraCommands.java
|
|
index 22676ec7a7ae9494b198e5e65e6be6d32e0feb85..6edc5195c3b496a12b17b2b9b528505d37ffdb12 100644
|
|
--- a/src/main/java/me/samsuik/sakura/command/SakuraCommands.java
|
|
+++ b/src/main/java/me/samsuik/sakura/command/SakuraCommands.java
|
|
@@ -4,6 +4,7 @@ import io.papermc.paper.command.PaperPluginsCommand;
|
|
import me.samsuik.sakura.command.subcommands.ConfigCommand;
|
|
import me.samsuik.sakura.command.subcommands.FPSCommand;
|
|
import me.samsuik.sakura.command.subcommands.VisualCommand;
|
|
+import me.samsuik.sakura.command.subcommands.TPSCommand;
|
|
import me.samsuik.sakura.player.visibility.Visibility;
|
|
import net.minecraft.server.MinecraftServer;
|
|
import org.bukkit.command.Command;
|
|
@@ -21,6 +22,7 @@ public final class SakuraCommands {
|
|
COMMANDS.put("tntvisibility", new VisualCommand(Visibility.Setting.TNT_VISIBILITY, "tnttoggle"));
|
|
COMMANDS.put("sandvisibility", new VisualCommand(Visibility.Setting.SAND_VISIBILITY, "sandtoggle"));
|
|
COMMANDS.put("minimal", new VisualCommand(Visibility.Setting.MINIMAL, "minimaltnt", "tntlag"));
|
|
+ COMMANDS.put("tps", new TPSCommand("tps"));
|
|
}
|
|
|
|
public static void registerCommands(final MinecraftServer server) {
|
|
diff --git a/src/main/java/me/samsuik/sakura/command/subcommands/TPSCommand.java b/src/main/java/me/samsuik/sakura/command/subcommands/TPSCommand.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..7bd4c5696911730170320060c273f3a7f6a610be
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/command/subcommands/TPSCommand.java
|
|
@@ -0,0 +1,67 @@
|
|
+package me.samsuik.sakura.command.subcommands;
|
|
+
|
|
+import me.samsuik.sakura.command.BaseSubCommand;
|
|
+import me.samsuik.sakura.utils.tps.TPSGraph;
|
|
+import me.samsuik.sakura.utils.tps.TickTracking;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.format.NamedTextColor;
|
|
+import net.kyori.adventure.text.format.TextDecoration;
|
|
+import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
+import net.kyori.adventure.text.minimessage.tag.Tag;
|
|
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
+import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.minecraft.util.Mth;
|
|
+import org.bukkit.command.CommandSender;
|
|
+
|
|
+public final class TPSCommand extends BaseSubCommand {
|
|
+
|
|
+ public TPSCommand(String name) {
|
|
+ super(name);
|
|
+ this.description = "Gets the current ticks per second for the server";
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void execute(CommandSender sender, String[] args) {
|
|
+ var tracking = MinecraftServer.tickTracking;
|
|
+
|
|
+ var average = tracking.averageTps(10) * 1.75;
|
|
+ int lines = 10;
|
|
+
|
|
+ try {
|
|
+ average = Double.parseDouble(args[0]);
|
|
+ lines = Mth.clamp(Integer.parseInt(args[1]), 1, 18);
|
|
+ } catch (NumberFormatException | ArrayIndexOutOfBoundsException ignored) {}
|
|
+
|
|
+ sender.sendMessage(Component.text(".", NamedTextColor.DARK_PURPLE));
|
|
+ sender.sendMessage(createInformationComponent(tracking));
|
|
+
|
|
+ // Create the graph
|
|
+ var graph = new TPSGraph(tracking, lines, 75, average);
|
|
+ graph.map();
|
|
+
|
|
+ // Send the graph to the user
|
|
+ for (var component : graph.components()) {
|
|
+ sender.sendMessage(Component.text("| ", NamedTextColor.DARK_PURPLE).append(component));
|
|
+ }
|
|
+
|
|
+ sender.sendMessage(Component.text("| ", NamedTextColor.DARK_PURPLE).append(Component.text(" ".repeat(75), NamedTextColor.GRAY, TextDecoration.STRIKETHROUGH)));
|
|
+ sender.sendMessage(Component.text("'", NamedTextColor.DARK_PURPLE));
|
|
+ }
|
|
+
|
|
+ private Component createInformationComponent(TickTracking tracking) {
|
|
+ return MiniMessage.miniMessage().deserialize("<dark_purple>| <gray>-------------- <dark_gray>( <white>Now</white>: <tps>, <white>Mem</white>: <memory><gray>%</gray> ) </dark_gray>---------------",
|
|
+ Placeholder.component("tps", Component.text("%.1f".formatted(tracking.averageTps(1)), TPSGraph.colour(tracking.averageTps(1) / 20.0))),
|
|
+ Placeholder.component("memory", Component.text("%.1f".formatted(memoryUsage() * 100), TPSGraph.colour(1.0 - memoryUsage())))
|
|
+ );
|
|
+ }
|
|
+
|
|
+ private double memoryUsage() {
|
|
+ Runtime runtime = Runtime.getRuntime();
|
|
+ double free = runtime.freeMemory();
|
|
+ double max = runtime.maxMemory();
|
|
+ double alloc = runtime.totalMemory();
|
|
+ return (alloc - free) / max;
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/me/samsuik/sakura/utils/tps/TPSGraph.java b/src/main/java/me/samsuik/sakura/utils/tps/TPSGraph.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..fa5d0c046d979901dd302ee3973df27442172add
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/utils/tps/TPSGraph.java
|
|
@@ -0,0 +1,255 @@
|
|
+package me.samsuik.sakura.utils.tps;
|
|
+
|
|
+import me.samsuik.sakura.utils.tps.TickTracking.Point;
|
|
+import net.kyori.adventure.text.Component;
|
|
+import net.kyori.adventure.text.TextComponent;
|
|
+import net.kyori.adventure.text.event.HoverEvent;
|
|
+import net.kyori.adventure.text.format.NamedTextColor;
|
|
+import net.kyori.adventure.text.format.TextColor;
|
|
+import net.kyori.adventure.text.format.TextDecoration;
|
|
+import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
|
+import net.minecraft.util.Mth;
|
|
+
|
|
+public final class TPSGraph {
|
|
+
|
|
+ private final Parts[][] parts;
|
|
+ private final TickTracking tracked;
|
|
+ private final int lines;
|
|
+ private final int length;
|
|
+ private final double ceiling;
|
|
+
|
|
+ public TPSGraph(TickTracking tracked, int lines, int length, double ceiling) {
|
|
+ this.parts = new Parts[lines][length];
|
|
+ this.tracked = tracked;
|
|
+ this.length = length;
|
|
+ this.lines = lines;
|
|
+ this.ceiling = ceiling;
|
|
+ }
|
|
+
|
|
+ public void map() {
|
|
+ // Create the background
|
|
+ for (var line = 0; line < lines; ++line) {
|
|
+ for (var column = 0; column < length; ++column) {
|
|
+ parts[line][column] = Parts.BACKGROUND;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // Create normal points on the graph
|
|
+ for (var column = 0; column < length; ++column) {
|
|
+ var tps = tracked.point(column).tps();
|
|
+ // Likely the server has just started
|
|
+ if (tps == 0.0) break;
|
|
+ // Create normal point for column
|
|
+ var line = getLine(tps);
|
|
+ var lineParts = parts[line];
|
|
+ lineParts[column] = Parts.NORMAL;
|
|
+ }
|
|
+
|
|
+ // Create spikes on the graph, what is a spike?
|
|
+ // By spike I am referring to a situation where
|
|
+ // the normal point would be "moving" more than
|
|
+ // 2 lines, which looks terrible.
|
|
+ for (var column = 0; column < length; ++column) {
|
|
+ var nextTps = tracked.point(column + 1).tps();
|
|
+ // Likely the server has just started
|
|
+ if (nextTps == 0.0) break;
|
|
+ var curr = getLine(tracked.point(column).tps());
|
|
+ var prev = getLine(tracked.point(Math.max(column - 1, 0)).tps());
|
|
+ var next = getLine(nextTps);
|
|
+ var min = Math.min(curr, next);
|
|
+ var max = Math.max(curr, next);
|
|
+
|
|
+ if (max - min < 2) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ // Create vertical parts between the two points
|
|
+ for (var line = min; line < max; ++line) {
|
|
+ parts[line][column] = Parts.VERTICAL;
|
|
+ }
|
|
+
|
|
+ parts[min][column] = Parts.TOP;
|
|
+ parts[max][column] = Parts.BOTTOM;
|
|
+
|
|
+ if (column + 1 < length) {
|
|
+ // dodgy hack because the previous value can change +/- 1
|
|
+ // causing the spike to not correctly line up.
|
|
+ // this isn't a problem in the other direction
|
|
+ if (prev == curr + 1 && next < curr) {
|
|
+ parts[max][column] = Parts.SPIKE_TOP_RIGHT;
|
|
+ }
|
|
+
|
|
+ if (min == next) {
|
|
+ parts[min][column] = Parts.SPIKE_BOTTOM_LEFT; // '!
|
|
+ } else if (prev <= min) { // has to be <= due to the issue I noted above
|
|
+ parts[min][column] = Parts.SPIKE_BOTTOM_RIGHT; // !'
|
|
+ }
|
|
+
|
|
+ // cone on the top of a spike
|
|
+ if (max == curr && Math.abs(next - max) > 1 && Math.abs(prev - max) > 1 && prev < max) {
|
|
+ parts[max][column - 1] = Parts.SPIKE_TOP_LEFT;
|
|
+ parts[max][column] = Parts.SPIKE_TOP_RIGHT;
|
|
+ }
|
|
+
|
|
+ // cone on the bottom of a spike
|
|
+ if (min == curr && Math.abs(next - min) > 1 && Math.abs(prev - min) > 1 && prev > min) {
|
|
+ parts[min][column - 1] = Parts.SPIKE_BOTTOM_LEFT;
|
|
+ parts[min][column] = Parts.SPIKE_BOTTOM_RIGHT;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // Create special points on the graph, this
|
|
+ // is to handle slopes and slight differences
|
|
+ // that show up, anything else should be too
|
|
+ // extreme and get treated as a spike instead.
|
|
+ for (var column = 0; column < length; ++column) {
|
|
+ var tps = tracked.point(column).tps();
|
|
+ // Likely the server has just started
|
|
+ if (tps == 0.0) continue;
|
|
+ var curr = getLine(tps);
|
|
+ var prev = getLine(tracked.point(Math.max(column - 1, 0)).tps());
|
|
+ var next = getLine(tracked.point(column + 1).tps());
|
|
+
|
|
+ // Ignore spikes, it'd mess up and be a waste of time
|
|
+ if (Math.abs(curr - next) >= 2) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ // SANITY: positive = rising, negative = declining
|
|
+ var direction = next - prev;
|
|
+ var change = Math.abs(direction);
|
|
+
|
|
+ if (change >= 2 && Math.max(next, prev) == curr + 1) {
|
|
+ // Create slopes, only requirement is that the highest point
|
|
+ // and the current are one line away from one another.
|
|
+ if (direction < 0) {
|
|
+ parts[curr][column] = Parts.DECLINING;
|
|
+ } else {
|
|
+ parts[curr][column] = Parts.RISING;
|
|
+ }
|
|
+ } else if (Math.abs(curr - next) == 1 || direction == 0) {
|
|
+ // if we have no direction always do this as a special case for slight dips and rises
|
|
+ if (curr < next) {
|
|
+ parts[curr][column] = Parts.TOP;
|
|
+ } else if (curr > next) {
|
|
+ parts[curr][column] = Parts.BOTTOM;
|
|
+ }
|
|
+ } else if (Math.abs(curr - prev) == 1) {
|
|
+ if (prev > curr) {
|
|
+ parts[curr][column] = Parts.TOP;
|
|
+ } else if (prev < curr) {
|
|
+ parts[curr][column] = Parts.BOTTOM;
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private int getLine(double tps) {
|
|
+ var per = (ceiling / 10); // How many lines 1 tick should display
|
|
+ var line = (int) (tps / per);
|
|
+ return Mth.clamp(line, 0, lines - 1);
|
|
+ }
|
|
+
|
|
+ public Component[] components() {
|
|
+ // Create graph component array
|
|
+ var graph = new TextComponent.Builder[lines];
|
|
+
|
|
+ // Initialise graph components
|
|
+ for (var line = 0; line < graph.length; ++line) {
|
|
+ graph[line] = Component.text();
|
|
+ }
|
|
+
|
|
+ // Write the graph
|
|
+ for (var line = 0; line < parts.length; line++) {
|
|
+ writeLine(graph[line], parts[parts.length - line - 1]);
|
|
+ }
|
|
+
|
|
+ // Create built component array
|
|
+ var parts = new Component[graph.length];
|
|
+
|
|
+ // Store built components
|
|
+ for (var i = 0; i < graph.length; i++) {
|
|
+ parts[i] = graph[i].build();
|
|
+ }
|
|
+
|
|
+ return parts;
|
|
+ }
|
|
+
|
|
+ private void writeLine(TextComponent.Builder builder, Parts[] lineParts) {
|
|
+ for (var column = 0; column < lineParts.length; column++) {
|
|
+ var point = tracked.point(column);
|
|
+ var part = lineParts[column];
|
|
+
|
|
+ var colour = colour(point.tps() / 20.0);
|
|
+ var component = part.getPart();
|
|
+
|
|
+ if (part != Parts.BACKGROUND) {
|
|
+ component = component.color(colour);
|
|
+ }
|
|
+
|
|
+ // Display information from the current point
|
|
+ builder.append(appendHoverEvent(component, point, colour));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private Component appendHoverEvent(Component in, Point point, TextColor colour) {
|
|
+ return in.hoverEvent(HoverEvent.showText(MiniMessage.miniMessage().deserialize("""
|
|
+ TPS: <tps>
|
|
+ MS: (<ms>, <highest>)
|
|
+ Chunks: <chunks>
|
|
+ Entities: <entities>""",
|
|
+ Placeholder.component("tps", Component.text("%.1f".formatted(point.tps()), colour)),
|
|
+ Placeholder.component("ms", Component.text("%.1f".formatted(point.mspt()), colour)),
|
|
+ Placeholder.component("highest", Component.text("%.1f".formatted(point.highest()), colour)),
|
|
+ Placeholder.unparsed("chunks", String.valueOf(point.chunks())),
|
|
+ Placeholder.unparsed("entities", String.valueOf(point.entities()))
|
|
+ )));
|
|
+ }
|
|
+
|
|
+ public static TextColor colour(double percentage) {
|
|
+ if (percentage > 0.75) return shift(percentage, 1.0, 0.75, NamedTextColor.GREEN, NamedTextColor.YELLOW);
|
|
+ if (percentage > 0.6) return shift(percentage, 0.75, 0.6, NamedTextColor.YELLOW, NamedTextColor.GOLD);
|
|
+ if (percentage > 0.4) return shift(percentage, 0.6, 0.4, NamedTextColor.GOLD, NamedTextColor.RED);
|
|
+ if (percentage > 0.2) return shift(percentage, 0.4, 0.2, NamedTextColor.RED, NamedTextColor.DARK_GRAY);
|
|
+ return shift(percentage, 0.2, 0.0, NamedTextColor.DARK_GRAY, NamedTextColor.BLACK);
|
|
+ }
|
|
+
|
|
+ private static TextColor shift(double percentage, double from, double to, TextColor fromColour, TextColor toColour) {
|
|
+ var f = (float) ((percentage - from) / (to - from));
|
|
+ return TextColor.lerp(Math.max(f, 0.0f), fromColour, toColour);
|
|
+ }
|
|
+
|
|
+ public static double format(double num, int decimals) {
|
|
+ var pow = Math.pow(10, decimals);
|
|
+ return Math.round(num * pow) / pow;
|
|
+ }
|
|
+
|
|
+ private enum Parts {
|
|
+ // Adventure doesn't have a Component.text(String, TextDecoration)
|
|
+ BACKGROUND(Component.text("::", NamedTextColor.BLACK)),
|
|
+ NORMAL(Component.text(" ").decorate(TextDecoration.STRIKETHROUGH)),
|
|
+ VERTICAL(Component.text("||")),
|
|
+ RISING(Component.text(".").decorate(TextDecoration.STRIKETHROUGH).append(Component.text("'").decoration(TextDecoration.STRIKETHROUGH, false))),
|
|
+ DECLINING(Component.text("'").append(Component.text(".").decorate(TextDecoration.STRIKETHROUGH))),
|
|
+ SPIKE_TOP_LEFT(Component.text(".!")),
|
|
+ SPIKE_TOP_RIGHT(Component.text("!.")),
|
|
+ SPIKE_BOTTOM_LEFT(Component.text("'!")),
|
|
+ SPIKE_BOTTOM_RIGHT(Component.text("!'")),
|
|
+ TOP(Component.text("''")),
|
|
+ BOTTOM(Component.text("..")),
|
|
+ ;
|
|
+
|
|
+ private final Component part;
|
|
+
|
|
+ Parts(Component component) {
|
|
+ part = component;
|
|
+ }
|
|
+
|
|
+ public Component getPart() {
|
|
+ return part;
|
|
+ }
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/me/samsuik/sakura/utils/tps/TickTracking.java b/src/main/java/me/samsuik/sakura/utils/tps/TickTracking.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..6903863ad293a335a8ed1aeaa06fccb408593373
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/samsuik/sakura/utils/tps/TickTracking.java
|
|
@@ -0,0 +1,53 @@
|
|
+package me.samsuik.sakura.utils.tps;
|
|
+
|
|
+import net.minecraft.server.level.ServerLevel;
|
|
+
|
|
+import java.util.ArrayList;
|
|
+import java.util.Arrays;
|
|
+import java.util.Collection;
|
|
+import java.util.List;
|
|
+import java.util.stream.IntStream;
|
|
+
|
|
+public final class TickTracking {
|
|
+
|
|
+ private final List<Point> history = new ArrayList<>();
|
|
+ private final double[] msptSamples = new double[20];
|
|
+
|
|
+ public TickTracking(int samples) {
|
|
+ for (int i = 0; i < samples; ++i) {
|
|
+ history.add(new Point(0.0, 0.0,0.0, 0, 0));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ Point point(int at) {
|
|
+ return history.get(at);
|
|
+ }
|
|
+
|
|
+ public double averageTps(int samples) {
|
|
+ return IntStream.range(0, samples)
|
|
+ .mapToDouble(i -> history.get(i).tps)
|
|
+ .average()
|
|
+ .orElse(0.0);
|
|
+ }
|
|
+
|
|
+ public void secondSample(Collection<ServerLevel> server, double tps) {
|
|
+ history.remove(history.size() - 1);
|
|
+
|
|
+ int entities = server.stream().mapToInt((world) -> world.entityTickList.entities.size()).sum();
|
|
+ int loaded = server.stream().mapToInt((world) -> world.chunkSource.getInternallyLoadedChunks()).sum();
|
|
+
|
|
+ double mspt = Arrays.stream(msptSamples).average().orElse(0.0);
|
|
+ double max = Arrays.stream(msptSamples).max().orElse(0.0);
|
|
+
|
|
+ history.add(0, new Point(tps, mspt, max, entities, loaded));
|
|
+ }
|
|
+
|
|
+ public void tickSample(long mspt) {
|
|
+ for (int i = msptSamples.length - 2; i >= 0; --i)
|
|
+ msptSamples[i + 1] = msptSamples[i];
|
|
+ msptSamples[0] = mspt;
|
|
+ }
|
|
+
|
|
+ public record Point(double tps, double mspt, double highest, int entities, int chunks) {}
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 6e6ca00b20072e65370a47d38dded747fc0eb7c9..783367f380ad2a21418d102fbb6bc49a71148ee8 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1134,6 +1134,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
}
|
|
}
|
|
private static final java.math.BigDecimal TPS_BASE = new java.math.BigDecimal(1E9).multiply(new java.math.BigDecimal(SAMPLE_INTERVAL));
|
|
+ public static final me.samsuik.sakura.utils.tps.TickTracking tickTracking = new me.samsuik.sakura.utils.tps.TickTracking(120); // Sakura - tps graph command
|
|
// Paper end
|
|
// Spigot End
|
|
|
|
@@ -1212,6 +1213,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
if (++MinecraftServer.currentTick % MinecraftServer.SAMPLE_INTERVAL == 0) {
|
|
final long diff = currentTime - tickSection;
|
|
final java.math.BigDecimal currentTps = TPS_BASE.divide(new java.math.BigDecimal(diff), 30, java.math.RoundingMode.HALF_UP);
|
|
+ tickTracking.secondSample(levels.values(), currentTps.doubleValue()); // Sakura
|
|
tps1.add(currentTps, diff);
|
|
tps5.add(currentTps, diff);
|
|
tps15.add(currentTps, diff);
|
|
@@ -1240,6 +1242,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
this.tickServer(flag ? () -> {
|
|
return false;
|
|
} : this::haveTime);
|
|
+ tickTracking.tickSample((System.nanoTime() - currentTime) / 1_000_000L); // Sakura
|
|
this.profiler.popPush("nextTickWait");
|
|
this.mayHaveDelayedTasks = true;
|
|
this.delayedTasksMaxNextTickTimeNanos = Math.max(Util.getNanos() + i, this.nextTickTimeNanos);
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
index b99f50604bafecbc68835974c9ed0caa91911a40..c912615ded011741f81c72739639e631f331710e 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
@@ -90,6 +90,11 @@ public class ServerChunkCache extends ChunkSource {
|
|
this.clearCache();
|
|
}
|
|
|
|
+ // Sakura start - tps graph command
|
|
+ public final int getInternallyLoadedChunks() {
|
|
+ return loadedChunkMap.size();
|
|
+ }
|
|
+ // Sakura end - tps graph command
|
|
// CraftBukkit start - properly implement isChunkLoaded
|
|
public boolean isChunkLoaded(int chunkX, int chunkZ) {
|
|
ChunkHolder chunk = this.chunkMap.getUpdatingChunkIfPresent(ChunkPos.asLong(chunkX, chunkZ));
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index bb1b891d917ed41ce5da6c2c9f470c5f49eff34a..b97217662434b67a62f7247c2b5187749f207880 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -197,7 +197,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
private final MinecraftServer server;
|
|
public final PrimaryLevelData serverLevelData; // CraftBukkit - type
|
|
private int lastSpawnChunkRadius;
|
|
- final EntityTickList entityTickList;
|
|
+ public final EntityTickList entityTickList; // Sakura - package-private -> public
|
|
//public final PersistentEntitySectionManager<Entity> entityManager; // Paper - rewrite chunk system
|
|
private final GameEventDispatcher gameEventDispatcher;
|
|
public boolean noSave;
|
|
diff --git a/src/main/java/net/minecraft/world/level/entity/EntityTickList.java b/src/main/java/net/minecraft/world/level/entity/EntityTickList.java
|
|
index 83a39f900551e39d5af6f17a339a386ddee4feef..172c8d9cc94ed6ddfd3f785ca97a6e6ebb58d2d9 100644
|
|
--- a/src/main/java/net/minecraft/world/level/entity/EntityTickList.java
|
|
+++ b/src/main/java/net/minecraft/world/level/entity/EntityTickList.java
|
|
@@ -9,7 +9,7 @@ import javax.annotation.Nullable;
|
|
import net.minecraft.world.entity.Entity;
|
|
|
|
public class EntityTickList {
|
|
- private final io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<Entity> entities = new io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<>(true); // Paper - rewrite this, always keep this updated - why would we EVER tick an entity that's not ticking?
|
|
+ public final io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<Entity> entities = new io.papermc.paper.util.maplist.IteratorSafeOrderedReferenceSet<>(true); // Sakura - tps graph // Paper - rewrite this, always keep this updated - why would we EVER tick an entity that's not ticking?
|
|
|
|
private void ensureActiveIsNotIterated() {
|
|
// Paper - replace with better logic, do not delay removals
|
|
diff --git a/src/main/java/org/spigotmc/SpigotConfig.java b/src/main/java/org/spigotmc/SpigotConfig.java
|
|
index 6c2a3813e7d63d57f07a8fa2edbb9d231221d818..a7333afe790be4ca876cb15c5f32a085dd13c3bb 100644
|
|
--- a/src/main/java/org/spigotmc/SpigotConfig.java
|
|
+++ b/src/main/java/org/spigotmc/SpigotConfig.java
|
|
@@ -283,7 +283,7 @@ public class SpigotConfig
|
|
|
|
private static void tpsCommand()
|
|
{
|
|
- SpigotConfig.commands.put( "tps", new TicksPerSecondCommand( "tps" ) );
|
|
+ // SpigotConfig.commands.put( "tps", new TicksPerSecondCommand( "tps" ) ); // Sakura - TPS Graph
|
|
}
|
|
|
|
public static int playerSample;
|