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: bca97a8f7 replace spaces in world key (touches #5397) de94f6485 Refactor chat message composition (#5396) e27f334bb [CI-SKIP] Fix makemcdevsrc.sh for nms relocations (#5389) ae15e85da Updated Upstream (CraftBukkit) 26fe0ac5a Only set despawnTimer for Wandering Traders spawned by MobSpawnerTrader (#5391) b748eb7b8 Fix VanillaMobGoalTest#testBukkitMap (#5390) 18dbbb578 [Auto] Updated Upstream (CraftBukkit) fac9cc5d5 [CI-SKIP] Ignore .gitignore 087aa70e7 Deprecate ItemStack#setLore(List<String>) and ItemStack#getLore, add Component based alternatives 9889c651c apply fixup c310f0a61 Updated Upstream (Bukkit/CraftBukkit) f17560ab0 wtf is this t file -jmp 347f3a9b8 fix compile 700e9e6a5 rebase cf4dc464a Revert de5f4e469...c270abe96 6870db613 script & POM fix 743c6533c Replace ** with * (BSD/macOS) 376d7b097 Don't remove the .java fcb3fd42a Fix macOS/BSD support 8cfc05249 Link correctly ba1031ca7 Rename work dir c8d844ab7 Actually fix preloading this time e62aa5e3e Fix class preloading 1c03cf898 It's mojang math, not minecraft math 1034873df Apply fixups 39b125771 Use revision file 956150da7 Welcome to 1.16.5-R0.2 ccb217c01 Change cache keys 0d217001c more work f6d820f07 It compiles 0f78e9525 More work 1718f61bf Updated Upstream (CraftBukkit/Spigot) b28d46114 Update scripts for NMS repackaging Tuinity Changes: 9bdcb9b8e Delete work dir when running jar 6351d7ca7 Update Upstream (Paper) 932c199a6 Generate md-dev correctly bf3e73778 Make packet limiter work from IDE 1686f3861 Fix packet limiter config f40f7b425 Update README.md styling (#264) da1c3ace5 GH Actions Changes (#213) 5f325ecf1 Update Upstream (Paper) 0f83fe48d Update Upstream (Paper) Airplane Changes: f94d39947 Merge pull request #18 from notOM3GA/upstream/nms-repackage 0fc622631 Force build for Flare update 08439d6a9 Update Upstream (Tuinity)
197 lines
7.5 KiB
Diff
197 lines
7.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: BillyGalbreath <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/CommandDispatcher.java b/src/main/java/net/minecraft/commands/CommandDispatcher.java
|
|
index a551636c2c59e68a5abb1cd5611c1d5c7e36f514..b7663a3d64ae5202abb93eabba6ec013bae96334 100644
|
|
--- a/src/main/java/net/minecraft/commands/CommandDispatcher.java
|
|
+++ b/src/main/java/net/minecraft/commands/CommandDispatcher.java
|
|
@@ -193,6 +193,7 @@ public class CommandDispatcher {
|
|
CommandWhitelist.a(this.b);
|
|
net.pl3x.purpur.command.DemoCommand.register(getDispatcher()); // Purpur
|
|
net.pl3x.purpur.command.PingCommand.register(getDispatcher()); // Purpur
|
|
+ net.pl3x.purpur.command.TPSBarCommand.register(getDispatcher()); // Purpur
|
|
}
|
|
|
|
if (commanddispatcher_servertype.d) {
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 5de12553875af626fa597ca440e52682624e35c8..e8146dad220330bdcc46e563172b40a66931d17c 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -584,6 +584,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
this.serverConnection.acceptConnections();
|
|
// CraftBukkit end
|
|
|
|
+ net.pl3x.purpur.task.TPSBarTask.start(); // Purpur
|
|
}
|
|
|
|
protected void updateWorldSettings() {}
|
|
@@ -979,6 +980,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
this.safeShutdown(flag, false);
|
|
}
|
|
public void safeShutdown(boolean flag, boolean isRestarting) {
|
|
+ net.pl3x.purpur.task.TPSBarTask.stop(); // Purpur
|
|
this.isRunning = false;
|
|
this.isRestarting = isRestarting;
|
|
this.hasLoggedStop = true; // Paper
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index fbc8f7746fc92def73c244b3c12da990741d4bd5..3b70d3e3cf7cb17c075f8b758ba7967f99325223 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -597,6 +597,8 @@ public abstract class PlayerList {
|
|
if (entityplayer.didPlayerJoinEvent) cserver.getPluginManager().callEvent(playerQuitEvent); // Paper - if we disconnected before join ever fired, don't fire quit
|
|
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
|
|
|
|
+ net.pl3x.purpur.task.TPSBarTask.removePlayer(cserver.getPlayer(entityplayer)); // Purpur
|
|
+
|
|
if (server.isMainThread()) entityplayer.playerTick(); // SPIGOT-924 // Paper - don't tick during emergency shutdowns (Watchdog)
|
|
// CraftBukkit end
|
|
|
|
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..807f5709af7fd9497633ecfc9e932f0dfd4df231
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/pl3x/purpur/command/TPSBarCommand.java
|
|
@@ -0,0 +1,27 @@
|
|
+package net.pl3x.purpur.command;
|
|
+
|
|
+import net.minecraft.commands.CommandDispatcher;
|
|
+import net.minecraft.commands.CommandListenerWrapper;
|
|
+import net.minecraft.server.level.EntityPlayer;
|
|
+import net.pl3x.purpur.task.TPSBarTask;
|
|
+
|
|
+public class TPSBarCommand {
|
|
+ public static void register(com.mojang.brigadier.CommandDispatcher<CommandListenerWrapper> dispatcher) {
|
|
+ dispatcher.register(CommandDispatcher.literal("tpsbar")
|
|
+ .requires((listener) -> {
|
|
+ return listener.hasPermission(2);
|
|
+ })
|
|
+ .executes((context) -> {
|
|
+ return execute(context.getSource(), context.getSource().getPlayerOrException());
|
|
+ })
|
|
+ ).setPermission("bukkit.command.tpsbar");
|
|
+ }
|
|
+
|
|
+ private static int execute(CommandListenerWrapper sender, EntityPlayer 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..170f01516aab72e5b192695a73602ff656ef4ca5
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/pl3x/purpur/task/TPSBarTask.java
|
|
@@ -0,0 +1,106 @@
|
|
+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 final NamespacedKey key;
|
|
+ private final BossBar bossbar;
|
|
+ private static TPSBarTask instance;
|
|
+
|
|
+ public TPSBarTask() {
|
|
+ instance = this;
|
|
+
|
|
+ this.key = new NamespacedKey("purpur", "tpsbar");
|
|
+
|
|
+ BossBar 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);
|
|
+
|
|
+ this.bossbar = bossbar;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void run() {
|
|
+ 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.setVisible(false);
|
|
+ bossbar.removeAll();
|
|
+ Bukkit.removeBossBar(key);
|
|
+ }
|
|
+
|
|
+ public static void removePlayer(Player player) {
|
|
+ instance.bossbar.removePlayer(player);
|
|
+ }
|
|
+
|
|
+ public static void togglePlayer(Player player) {
|
|
+ if (instance.bossbar.getPlayers().contains(player)) {
|
|
+ instance.bossbar.removePlayer(player);
|
|
+ } else {
|
|
+ instance.bossbar.addPlayer(player);
|
|
+ instance.run();
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static void start() {
|
|
+ stop();
|
|
+ instance = new TPSBarTask();
|
|
+ instance.runTaskTimerAsynchronously(new MinecraftInternalPlugin(), 20L, 20L);
|
|
+ }
|
|
+
|
|
+ public static void stop() {
|
|
+ if (instance != null) {
|
|
+ instance.cancel();
|
|
+ }
|
|
+ }
|
|
+}
|