mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: 12dec20 Bump paerweight to 1.1.7 e33ed89 Get short commit ref using a more proper method 7d6147d Remove now unneeded patch due to paperweight 1.1.7 e72fa41 Update task dependency for includeMappings so the new task isn't skipped 0ad5526 Trim whitspace off of git hash (oops) Tuinity Changes: e878ba9 Update paper 2bd2849 Bring back fix codec spam patch
209 lines
7.9 KiB
Diff
209 lines
7.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
|
Date: Sat, 12 Dec 2020 21:19:05 -0600
|
|
Subject: [PATCH] Implement TPSBar
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
|
|
index f164106a957c24bdb71bde85d82948a64613fd91..bef1f6ca54fc6c1741b54b8e071a90eb5e3a36f3 100644
|
|
--- a/src/main/java/net/minecraft/commands/Commands.java
|
|
+++ b/src/main/java/net/minecraft/commands/Commands.java
|
|
@@ -201,6 +201,7 @@ public class Commands {
|
|
net.pl3x.purpur.command.CreditsCommand.register(this.dispatcher); // Purpur
|
|
net.pl3x.purpur.command.DemoCommand.register(this.dispatcher); // Purpur
|
|
net.pl3x.purpur.command.PingCommand.register(this.dispatcher); // Purpur
|
|
+ net.pl3x.purpur.command.TPSBarCommand.register(this.dispatcher); // Purpur
|
|
}
|
|
|
|
if (environment.includeIntegrated) {
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 9017d3626f4982a41d34d65758de4844e5502a9c..108dadb24607ea42cf857879386c34c9bb72dbee 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -1111,6 +1111,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
this.safeShutdown(flag, false);
|
|
}
|
|
public void safeShutdown(boolean flag, boolean isRestarting) {
|
|
+ net.pl3x.purpur.task.TPSBarTask.stop(); // Purpur
|
|
this.isRestarting = isRestarting;
|
|
this.hasLoggedStop = true; // Paper
|
|
if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper
|
|
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
index 6e67ea018cd6f362bba104f542c52438b455ccab..66d2559e5bd8630c6cbca0fe8d0eb1f756c388df 100644
|
|
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
|
|
@@ -347,6 +347,8 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
|
DedicatedServer.LOGGER.info("JMX monitoring enabled");
|
|
}
|
|
|
|
+ net.pl3x.purpur.task.TPSBarTask.start(); // Purpur
|
|
+
|
|
return true;
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 3508c809d2840a07fa06a37b177a73a0671b633a..340297eaa566480997aba5537c73134ec8b5111c 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -586,6 +586,8 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
public net.kyori.adventure.text.Component disconnect(ServerPlayer entityplayer) { // Paper - return Component
|
|
+ net.pl3x.purpur.task.TPSBarTask.removePlayer(entityplayer.getBukkitEntity()); // Purpur
|
|
+
|
|
ServerLevel worldserver = entityplayer.getLevel();
|
|
|
|
entityplayer.awardStat(Stats.LEAVE_GAME);
|
|
diff --git a/src/main/java/net/pl3x/purpur/command/TPSBarCommand.java b/src/main/java/net/pl3x/purpur/command/TPSBarCommand.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..2803a1b95121fbff3066fd2d1abaf8723386781f
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/pl3x/purpur/command/TPSBarCommand.java
|
|
@@ -0,0 +1,24 @@
|
|
+package net.pl3x.purpur.command;
|
|
+
|
|
+import com.mojang.brigadier.CommandDispatcher;
|
|
+import net.minecraft.commands.CommandSourceStack;
|
|
+import net.minecraft.commands.Commands;
|
|
+import net.minecraft.server.level.ServerPlayer;
|
|
+import net.pl3x.purpur.task.TPSBarTask;
|
|
+
|
|
+public class TPSBarCommand {
|
|
+ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
|
+ dispatcher.register(Commands.literal("tpsbar")
|
|
+ .requires(listener -> listener.hasPermission(2))
|
|
+ .executes(context -> execute(context.getSource(), context.getSource().getPlayerOrException()))
|
|
+ ).setPermission("bukkit.command.tpsbar");
|
|
+ }
|
|
+
|
|
+ private static int execute(CommandSourceStack source, ServerPlayer player) {
|
|
+ if (player != null) {
|
|
+ TPSBarTask.togglePlayer(player.getBukkitEntity());
|
|
+ return 1;
|
|
+ }
|
|
+ return 0;
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/pl3x/purpur/task/TPSBarTask.java b/src/main/java/net/pl3x/purpur/task/TPSBarTask.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..a9d71d2b769b8e4e0f5039e997fc5ebc1cc9bfbb
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/pl3x/purpur/task/TPSBarTask.java
|
|
@@ -0,0 +1,116 @@
|
|
+package net.pl3x.purpur.task;
|
|
+
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.ChatColor;
|
|
+import org.bukkit.NamespacedKey;
|
|
+import org.bukkit.boss.BarColor;
|
|
+import org.bukkit.boss.BarStyle;
|
|
+import org.bukkit.boss.BossBar;
|
|
+import org.bukkit.craftbukkit.scheduler.MinecraftInternalPlugin;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.bukkit.scheduler.BukkitRunnable;
|
|
+
|
|
+public class TPSBarTask extends BukkitRunnable {
|
|
+ private static TPSBarTask instance;
|
|
+ private final NamespacedKey key;
|
|
+ private BossBar bossbar;
|
|
+
|
|
+ private TPSBarTask() {
|
|
+ this.key = new NamespacedKey("purpur", "tpsbar");
|
|
+ }
|
|
+
|
|
+ private static TPSBarTask instance() {
|
|
+ if (instance == null) {
|
|
+ instance = new TPSBarTask();
|
|
+ }
|
|
+ return instance;
|
|
+ }
|
|
+
|
|
+ private BossBar bossbar() {
|
|
+ if (bossbar == null) {
|
|
+ bossbar = Bukkit.getBossBar(key);
|
|
+ if (bossbar == null) {
|
|
+ bossbar = Bukkit.createBossBar(key, "TPS: 20.0", BarColor.RED, BarStyle.SEGMENTED_20);
|
|
+ }
|
|
+ bossbar.setVisible(true);
|
|
+ bossbar.setProgress(1.0D);
|
|
+ }
|
|
+ return bossbar;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void run() {
|
|
+ BossBar bossbar = bossbar();
|
|
+ if (bossbar.getPlayers().isEmpty()) {
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ double tps = Bukkit.getTPS()[0];
|
|
+ if (tps > 20.0D) {
|
|
+ tps = 20.0D;
|
|
+ } else if (tps < 0.0D) {
|
|
+ tps = 0.0D;
|
|
+ }
|
|
+
|
|
+ bossbar.setVisible(true);
|
|
+ bossbar.setProgress(Math.max(Math.min(tps / 20.0D, 1.0D), 0.0D));
|
|
+
|
|
+ String tpsColor;
|
|
+ if (tps >= 18) {
|
|
+ tpsColor = "&2";
|
|
+ bossbar.setColor(BarColor.GREEN);
|
|
+ } else if (tps >= 15) {
|
|
+ tpsColor = "&e";
|
|
+ bossbar.setColor(BarColor.YELLOW);
|
|
+ } else {
|
|
+ tpsColor = "&4";
|
|
+ bossbar.setColor(BarColor.RED);
|
|
+ }
|
|
+
|
|
+ double mspt = Bukkit.getAverageTickTime();
|
|
+ String msptColor;
|
|
+ if (mspt < 40) {
|
|
+ msptColor = "&2";
|
|
+ } else if (mspt < 50) {
|
|
+ msptColor = "&e";
|
|
+ } else {
|
|
+ msptColor = "&4";
|
|
+ }
|
|
+
|
|
+ bossbar.setTitle(ChatColor.translateAlternateColorCodes('&', "&eTPS&3: " + tpsColor + String.format("%.2f", tps) + " &eMSPT&3: " + msptColor + String.format("%.3f", mspt)));
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void cancel() {
|
|
+ super.cancel();
|
|
+ BossBar bossbar = bossbar();
|
|
+ bossbar.setVisible(false);
|
|
+ bossbar.removeAll();
|
|
+ Bukkit.removeBossBar(key);
|
|
+ }
|
|
+
|
|
+ public static void removePlayer(Player player) {
|
|
+ instance().bossbar().removePlayer(player);
|
|
+ }
|
|
+
|
|
+ public static void togglePlayer(Player player) {
|
|
+ BossBar bossbar = instance().bossbar();
|
|
+ if (bossbar.getPlayers().contains(player)) {
|
|
+ bossbar.removePlayer(player);
|
|
+ } else {
|
|
+ bossbar.addPlayer(player);
|
|
+ instance.run();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static void start() {
|
|
+ stop();
|
|
+ instance().runTaskTimerAsynchronously(new MinecraftInternalPlugin(), 20L, 20L);
|
|
+ }
|
|
+
|
|
+ public static void stop() {
|
|
+ if (instance != null) {
|
|
+ instance.cancel();
|
|
+ }
|
|
+ }
|
|
+}
|