Implement TPSBar

This commit is contained in:
William Blake Galbreath
2025-01-10 00:52:43 -08:00
committed by granny
parent 55eb63b89c
commit 42bf7db018
14 changed files with 402 additions and 486 deletions

View File

@@ -1,467 +0,0 @@
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/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java
index 719fbce359f8c2c52ee4e9da3dfe9566f58c0346..f01fff591efc92267d96084660f9e9688bd65795 100644
--- a/net/minecraft/commands/Commands.java
+++ b/net/minecraft/commands/Commands.java
@@ -258,6 +258,7 @@ public class Commands {
org.purpurmc.purpur.command.CreditsCommand.register(this.dispatcher); // Purpur
org.purpurmc.purpur.command.DemoCommand.register(this.dispatcher); // Purpur
org.purpurmc.purpur.command.PingCommand.register(this.dispatcher); // Purpur
+ org.purpurmc.purpur.command.TPSBarCommand.register(this.dispatcher); // Purpur
}
if (environment.includeIntegrated) {
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index d55390d725f8798becb0b7b04485c99611e0e527..7ce4148a1fcd221bf22f4ad02a2fc32e007fa1da 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1158,6 +1158,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.safeShutdown(waitForShutdown, false);
}
public void safeShutdown(boolean waitForShutdown, boolean isRestarting) {
+ org.purpurmc.purpur.task.BossBarTask.stopAll(); // Purpur
this.isRestarting = isRestarting;
this.hasLoggedStop = true; // Paper - Debugging
if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper - Debugging
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index 59a8007add25bf947b87eef3ece55bca192ba358..6252001c03230f35c5ec7354faa3720e407dee6c 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -374,6 +374,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
DedicatedServer.LOGGER.info("JMX monitoring enabled");
}
+ org.purpurmc.purpur.task.BossBarTask.startAll(); // Purpur
return true;
}
}
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index 51e58f447cc07224b2d9bbeff3719a719931a40c..303c9b2c6f1a62e40c5657248b727c14bb9c613a 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -328,6 +328,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
public @Nullable String clientBrandName = null; // Paper - Brand support
public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event
public boolean purpurClient = false; // Purpur - Purpur client support
+ private boolean tpsBar = false; // Purpur
// Paper start - rewrite chunk system
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
@@ -690,6 +691,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
});
}
+ if (nbt.contains("Purpur.TPSBar")) { this.tpsBar = nbt.getBoolean("Purpur.TPSBar"); } // Purpur
}
@Override
@@ -742,6 +744,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
}
this.saveEnderPearls(nbt);
+ nbt.putBoolean("Purpur.TPSBar", this.tpsBar); // Purpur
}
private void saveParentVehicle(CompoundTag nbt) {
@@ -3420,5 +3423,13 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player imple
this.server.getPlayerList().respawn(this, true, RemovalReason.KILLED, org.bukkit.event.player.PlayerRespawnEvent.RespawnReason.DEATH, to);
}
}
+
+ public boolean tpsBar() {
+ return this.tpsBar;
+ }
+
+ public void tpsBar(boolean tpsBar) {
+ this.tpsBar = tpsBar;
+ }
// Purpur end
}
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 8596e1c016c51a840b8c0c6a8d5c8e0893c4f1c7..0969a713df3150b0b2d2dd2d595e5f49e491f8af 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -419,6 +419,7 @@ public abstract class PlayerList {
scoreboard.addPlayerToTeam(player.getScoreboardName(), collideRuleTeam);
}
// Paper end - Configurable player collision
+ org.purpurmc.purpur.task.BossBarTask.addToAll(player); // Purpur
PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", player.getName().getString(), s1, player.getId(), worldserver1.serverLevelData.getLevelName(), player.getX(), player.getY(), player.getZ());
// Paper start - Send empty chunk, so players aren't stuck in the world loading screen with our chunk system not sending chunks when dead
if (player.isDeadOrDying()) {
@@ -540,6 +541,7 @@ public abstract class PlayerList {
}
public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer, net.kyori.adventure.text.Component leaveMessage) {
// Paper end - Fix kick event leave message not being sent
+ org.purpurmc.purpur.task.BossBarTask.removeFromAll(entityplayer.getBukkitEntity()); // Purpur
ServerLevel worldserver = entityplayer.serverLevel();
entityplayer.awardStat(Stats.LEAVE_GAME);
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
index 5feee7c130e71731051e610aeb0e8c3341bddb2e..6c7b7d6c6aff3dfd4bcc307c004513cf23f44a4d 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -185,6 +185,7 @@ public class PurpurConfig {
public static String creditsCommandOutput = "<green>%s has been shown the end credits";
public static String demoCommandOutput = "<green>%s has been shown the demo screen";
public static String pingCommandOutput = "<green>%s's ping is %sms";
+ public static String tpsbarCommandOutput = "<green>Tpsbar toggled <onoff> for <target>";
private static void messages() {
cannotRideMob = getString("settings.messages.cannot-ride-mob", cannotRideMob);
afkBroadcastAway = getString("settings.messages.afk-broadcast-away", afkBroadcastAway);
@@ -195,6 +196,7 @@ public class PurpurConfig {
creditsCommandOutput = getString("settings.messages.credits-command-output", creditsCommandOutput);
demoCommandOutput = getString("settings.messages.demo-command-output", demoCommandOutput);
pingCommandOutput = getString("settings.messages.ping-command-output", pingCommandOutput);
+ tpsbarCommandOutput = getString("settings.messages.tpsbar-command-output", tpsbarCommandOutput);
}
public static String serverModName = io.papermc.paper.ServerBuildInfo.buildInfo().brandName();
@@ -217,6 +219,29 @@ public class PurpurConfig {
disableGiveCommandDrops = getBoolean("settings.disable-give-dropping", disableGiveCommandDrops);
}
+ public static String commandTPSBarTitle = "<gray>TPS<yellow>:</yellow> <tps> MSPT<yellow>:</yellow> <mspt> Ping<yellow>:</yellow> <ping>ms";
+ public static BossBar.Overlay commandTPSBarProgressOverlay = BossBar.Overlay.NOTCHED_20;
+ public static TPSBarTask.FillMode commandTPSBarProgressFillMode = TPSBarTask.FillMode.MSPT;
+ public static BossBar.Color commandTPSBarProgressColorGood = BossBar.Color.GREEN;
+ public static BossBar.Color commandTPSBarProgressColorMedium = BossBar.Color.YELLOW;
+ public static BossBar.Color commandTPSBarProgressColorLow = BossBar.Color.RED;
+ public static String commandTPSBarTextColorGood = "<gradient:#55ff55:#00aa00><text></gradient>";
+ public static String commandTPSBarTextColorMedium = "<gradient:#ffff55:#ffaa00><text></gradient>";
+ public static String commandTPSBarTextColorLow = "<gradient:#ff5555:#aa0000><text></gradient>";
+ public static int commandTPSBarTickInterval = 20;
+ private static void commandSettings() {
+ commandTPSBarTitle = getString("settings.command.tpsbar.title", commandTPSBarTitle);
+ commandTPSBarProgressOverlay = BossBar.Overlay.valueOf(getString("settings.command.tpsbar.overlay", commandTPSBarProgressOverlay.name()));
+ commandTPSBarProgressFillMode = TPSBarTask.FillMode.valueOf(getString("settings.command.tpsbar.fill-mode", commandTPSBarProgressFillMode.name()));
+ commandTPSBarProgressColorGood = BossBar.Color.valueOf(getString("settings.command.tpsbar.progress-color.good", commandTPSBarProgressColorGood.name()));
+ commandTPSBarProgressColorMedium = BossBar.Color.valueOf(getString("settings.command.tpsbar.progress-color.medium", commandTPSBarProgressColorMedium.name()));
+ commandTPSBarProgressColorLow = BossBar.Color.valueOf(getString("settings.command.tpsbar.progress-color.low", commandTPSBarProgressColorLow.name()));
+ commandTPSBarTextColorGood = getString("settings.command.tpsbar.text-color.good", commandTPSBarTextColorGood);
+ commandTPSBarTextColorMedium = getString("settings.command.tpsbar.text-color.medium", commandTPSBarTextColorMedium);
+ commandTPSBarTextColorLow = getString("settings.command.tpsbar.text-color.low", commandTPSBarTextColorLow);
+ commandTPSBarTickInterval = getInt("settings.command.tpsbar.tick-interval", commandTPSBarTickInterval);
+ }
+
public static int barrelRows = 3;
public static boolean enderChestSixRows = false;
public static boolean enderChestPermissionRows = false;
diff --git a/src/main/java/org/purpurmc/purpur/command/TPSBarCommand.java b/src/main/java/org/purpurmc/purpur/command/TPSBarCommand.java
new file mode 100644
index 0000000000000000000000000000000000000000..d8f9b044107ff7c29a83eb5378aa9f5465ba1995
--- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/command/TPSBarCommand.java
@@ -0,0 +1,44 @@
+package org.purpurmc.purpur.command;
+
+import com.mojang.brigadier.CommandDispatcher;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
+import net.minecraft.commands.CommandSourceStack;
+import net.minecraft.commands.Commands;
+import net.minecraft.commands.arguments.EntityArgument;
+import net.minecraft.server.level.ServerPlayer;
+import org.purpurmc.purpur.PurpurConfig;
+import org.purpurmc.purpur.task.TPSBarTask;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public class TPSBarCommand {
+ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
+ dispatcher.register(Commands.literal("tpsbar")
+ .requires(listener -> listener.hasPermission(2, "bukkit.command.tpsbar"))
+ .executes(context -> execute(context.getSource(), Collections.singleton(context.getSource().getPlayerOrException())))
+ .then(Commands.argument("targets", EntityArgument.players())
+ .requires(listener -> listener.hasPermission(2, "bukkit.command.tpsbar.other"))
+ .executes((context) -> execute(context.getSource(), EntityArgument.getPlayers(context, "targets")))
+ )
+ );
+ }
+
+ private static int execute(CommandSourceStack sender, Collection<ServerPlayer> targets) {
+ for (ServerPlayer player : targets) {
+ boolean result = TPSBarTask.instance().togglePlayer(player.getBukkitEntity());
+ player.tpsBar(result);
+
+ Component output = MiniMessage.miniMessage().deserialize(PurpurConfig.tpsbarCommandOutput,
+ Placeholder.component("onoff", Component.translatable(result ? "options.on" : "options.off")
+ .color(result ? NamedTextColor.GREEN : NamedTextColor.RED)),
+ Placeholder.parsed("target", player.getGameProfile().getName()));
+
+ sender.sendSuccess(output, false);
+ }
+ return targets.size();
+ }
+}
diff --git a/src/main/java/org/purpurmc/purpur/task/BossBarTask.java b/src/main/java/org/purpurmc/purpur/task/BossBarTask.java
new file mode 100644
index 0000000000000000000000000000000000000000..6796fd6a936212a6eb768d9cf0fa5e74132c89e8
--- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/task/BossBarTask.java
@@ -0,0 +1,109 @@
+package org.purpurmc.purpur.task;
+
+import net.kyori.adventure.bossbar.BossBar;
+import net.minecraft.server.level.ServerPlayer;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitRunnable;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.UUID;
+import org.purpurmc.purpur.util.MinecraftInternalPlugin;
+
+public abstract class BossBarTask extends BukkitRunnable {
+ private final Map<UUID, BossBar> bossbars = new HashMap<>();
+ private boolean started;
+
+ abstract BossBar createBossBar();
+
+ abstract void updateBossBar(BossBar bossbar, Player player);
+
+ @Override
+ public void run() {
+ Iterator<Map.Entry<UUID, BossBar>> iter = bossbars.entrySet().iterator();
+ while (iter.hasNext()) {
+ Map.Entry<UUID, BossBar> entry = iter.next();
+ Player player = Bukkit.getPlayer(entry.getKey());
+ if (player == null) {
+ iter.remove();
+ continue;
+ }
+ updateBossBar(entry.getValue(), player);
+ }
+ }
+
+ @Override
+ public void cancel() {
+ super.cancel();
+ new HashSet<>(this.bossbars.keySet()).forEach(uuid -> {
+ Player player = Bukkit.getPlayer(uuid);
+ if (player != null) {
+ removePlayer(player);
+ }
+ });
+ this.bossbars.clear();
+ }
+
+ public boolean removePlayer(Player player) {
+ BossBar bossbar = this.bossbars.remove(player.getUniqueId());
+ if (bossbar != null) {
+ player.hideBossBar(bossbar);
+ return true;
+ }
+ return false;
+ }
+
+ public void addPlayer(Player player) {
+ removePlayer(player);
+ BossBar bossbar = createBossBar();
+ this.bossbars.put(player.getUniqueId(), bossbar);
+ this.updateBossBar(bossbar, player);
+ player.showBossBar(bossbar);
+ }
+
+ public boolean hasPlayer(UUID uuid) {
+ return this.bossbars.containsKey(uuid);
+ }
+
+ public boolean togglePlayer(Player player) {
+ if (removePlayer(player)) {
+ return false;
+ }
+ addPlayer(player);
+ return true;
+ }
+
+ public void start() {
+ stop();
+ this.runTaskTimerAsynchronously(new MinecraftInternalPlugin(), 1, 1);
+ started = true;
+ }
+
+ public void stop() {
+ if (started) {
+ cancel();
+ }
+ }
+
+ public static void startAll() {
+ TPSBarTask.instance().start();
+ }
+
+ public static void stopAll() {
+ TPSBarTask.instance().stop();
+ }
+
+ public static void addToAll(ServerPlayer player) {
+ Player bukkit = player.getBukkitEntity();
+ if (player.tpsBar()) {
+ TPSBarTask.instance().addPlayer(bukkit);
+ }
+ }
+
+ public static void removeFromAll(Player player) {
+ TPSBarTask.instance().removePlayer(player);
+ }
+}
diff --git a/src/main/java/org/purpurmc/purpur/task/TPSBarTask.java b/src/main/java/org/purpurmc/purpur/task/TPSBarTask.java
new file mode 100644
index 0000000000000000000000000000000000000000..8769993e7ca59da309087051a3cd38fc562c15d1
--- /dev/null
+++ b/src/main/java/org/purpurmc/purpur/task/TPSBarTask.java
@@ -0,0 +1,142 @@
+package org.purpurmc.purpur.task;
+
+import net.kyori.adventure.bossbar.BossBar;
+import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
+import org.purpurmc.purpur.PurpurConfig;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+
+public class TPSBarTask extends BossBarTask {
+ private static TPSBarTask instance;
+ private double tps = 20.0D;
+ private double mspt = 0.0D;
+ private int tick = 0;
+
+ public static TPSBarTask instance() {
+ if (instance == null) {
+ instance = new TPSBarTask();
+ }
+ return instance;
+ }
+
+ @Override
+ BossBar createBossBar() {
+ return BossBar.bossBar(Component.text(""), 0.0F, instance().getBossBarColor(), PurpurConfig.commandTPSBarProgressOverlay);
+ }
+
+ @Override
+ void updateBossBar(BossBar bossbar, Player player) {
+ bossbar.progress(getBossBarProgress());
+ bossbar.color(getBossBarColor());
+ bossbar.name(MiniMessage.miniMessage().deserialize(PurpurConfig.commandTPSBarTitle,
+ Placeholder.component("tps", getTPSColor()),
+ Placeholder.component("mspt", getMSPTColor()),
+ Placeholder.component("ping", getPingColor(player.getPing()))
+ ));
+ }
+
+ @Override
+ public void run() {
+ if (++tick < PurpurConfig.commandTPSBarTickInterval) {
+ return;
+ }
+ tick = 0;
+
+ this.tps = Math.max(Math.min(Bukkit.getTPS()[0], 20.0D), 0.0D);
+ this.mspt = Bukkit.getAverageTickTime();
+
+ super.run();
+ }
+
+ private float getBossBarProgress() {
+ if (PurpurConfig.commandTPSBarProgressFillMode == FillMode.MSPT) {
+ return Math.max(Math.min((float) mspt / 50.0F, 1.0F), 0.0F);
+ } else {
+ return Math.max(Math.min((float) tps / 20.0F, 1.0F), 0.0F);
+ }
+ }
+
+ private BossBar.Color getBossBarColor() {
+ if (isGood(PurpurConfig.commandTPSBarProgressFillMode)) {
+ return PurpurConfig.commandTPSBarProgressColorGood;
+ } else if (isMedium(PurpurConfig.commandTPSBarProgressFillMode)) {
+ return PurpurConfig.commandTPSBarProgressColorMedium;
+ } else {
+ return PurpurConfig.commandTPSBarProgressColorLow;
+ }
+ }
+
+ private boolean isGood(FillMode mode) {
+ return isGood(mode, 0);
+ }
+
+ private boolean isGood(FillMode mode, int ping) {
+ if (mode == FillMode.MSPT) {
+ return mspt < 40;
+ } else if (mode == FillMode.TPS) {
+ return tps >= 19;
+ } else if (mode == FillMode.PING) {
+ return ping < 100;
+ } else {
+ return false;
+ }
+ }
+
+ private boolean isMedium(FillMode mode) {
+ return isMedium(mode, 0);
+ }
+
+ private boolean isMedium(FillMode mode, int ping) {
+ if (mode == FillMode.MSPT) {
+ return mspt < 50;
+ } else if (mode == FillMode.TPS) {
+ return tps >= 15;
+ } else if (mode == FillMode.PING) {
+ return ping < 200;
+ } else {
+ return false;
+ }
+ }
+
+ private Component getTPSColor() {
+ String color;
+ if (isGood(FillMode.TPS)) {
+ color = PurpurConfig.commandTPSBarTextColorGood;
+ } else if (isMedium(FillMode.TPS)) {
+ color = PurpurConfig.commandTPSBarTextColorMedium;
+ } else {
+ color = PurpurConfig.commandTPSBarTextColorLow;
+ }
+ return MiniMessage.miniMessage().deserialize(color, Placeholder.parsed("text", String.format("%.2f", tps)));
+ }
+
+ private Component getMSPTColor() {
+ String color;
+ if (isGood(FillMode.MSPT)) {
+ color = PurpurConfig.commandTPSBarTextColorGood;
+ } else if (isMedium(FillMode.MSPT)) {
+ color = PurpurConfig.commandTPSBarTextColorMedium;
+ } else {
+ color = PurpurConfig.commandTPSBarTextColorLow;
+ }
+ return MiniMessage.miniMessage().deserialize(color, Placeholder.parsed("text", String.format("%.2f", mspt)));
+ }
+
+ private Component getPingColor(int ping) {
+ String color;
+ if (isGood(FillMode.PING, ping)) {
+ color = PurpurConfig.commandTPSBarTextColorGood;
+ } else if (isMedium(FillMode.PING, ping)) {
+ color = PurpurConfig.commandTPSBarTextColorMedium;
+ } else {
+ color = PurpurConfig.commandTPSBarTextColorLow;
+ }
+ return MiniMessage.miniMessage().deserialize(color, Placeholder.parsed("text", String.format("%s", ping)));
+ }
+
+ public enum FillMode {
+ TPS, MSPT, PING
+ }
+}

View File

@@ -18,10 +18,10 @@ index 29d402620d2e1cbed94f941f933ae8eb5d786e7f..ec0998369158286fccb38c8e10c3cfa2
public boolean isLocalPlayer() {
return true;
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index d68d453a668a7767e5c115095df114b2dbb87d68..13c3d5377581bb82970aa99ca4a4f647f17f78e8 100644
index dbd5629ff0bc97177e872630bc39c608d009297f..5cba0608e24d2f5a687921e0c6b68827925590cd 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1721,6 +1721,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1722,6 +1722,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
serverLevel.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent
serverLevel.updateLagCompensationTick(); // Paper - lag compensation
net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = serverLevel.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper - Perf: Optimize Hoppers
@@ -42,10 +42,10 @@ index 7f136e044a243814372beef1400d3b6a148d2cbf..5e730cdde960603d5fa0fa7d1b70ec56
public LevelChunk getChunkIfLoaded(int x, int z) {
return this.chunkSource.getChunkAtIfLoadedImmediately(x, z); // Paper - Use getChunkIfLoadedImmediately
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index bd2f6c1ec45cf043549f49b80d4567d7493ea0ec..d6e17c816e7dc2260d95490145a1e571cdffb912 100644
index 5b50bc97ccab73dcafa29e3a8c5d04b3c4e8c1d4..c03639557e498f44a53fbf223928f68e515638eb 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -838,6 +838,15 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -842,6 +842,15 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
this.trackEnteredOrExitedLavaOnVehicle();
this.updatePlayerAttributes();
this.advancements.flushDirty(this);

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Barrels and enderchests 6 rows
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index e693c5ef414dd77b684d0a393444a5d28b975bfd..d12896bb6f23bfdb1d22e1ecadd23c01b71a07fc 100644
index ec0c9f6d1bcf00606b0a6af114264d1ea6650d51..513daca2246f07bbb7b11e75f972f1fffbda2fd8 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -1025,6 +1025,27 @@ public abstract class PlayerList {
@@ -1027,6 +1027,27 @@ public abstract class PlayerList {
player.getBukkitEntity().recalculatePermissions(); // CraftBukkit
this.server.getCommands().sendCommands(player);
} // Paper - Add sendOpLevel API
@@ -37,7 +37,7 @@ index e693c5ef414dd77b684d0a393444a5d28b975bfd..d12896bb6f23bfdb1d22e1ecadd23c01
public boolean isWhiteListed(GameProfile profile) {
diff --git a/net/minecraft/world/entity/player/Player.java b/net/minecraft/world/entity/player/Player.java
index 27a0cb04dd50974a96ed420ef811d9c9f3182e52..9b762d48c63ddc532c86e2982006eed42375ac1e 100644
index 27a0cb04dd50974a96ed420ef811d9c9f3182e52..575dd9b9e31ac5bf29ca6abc6ce76bcf16e3e89c 100644
--- a/net/minecraft/world/entity/player/Player.java
+++ b/net/minecraft/world/entity/player/Player.java
@@ -200,6 +200,7 @@ public abstract class Player extends LivingEntity {
@@ -49,7 +49,7 @@ index 27a0cb04dd50974a96ed420ef811d9c9f3182e52..9b762d48c63ddc532c86e2982006eed4
// CraftBukkit start
public boolean fauxSleeping;
diff --git a/net/minecraft/world/inventory/ChestMenu.java b/net/minecraft/world/inventory/ChestMenu.java
index cf5b99c1337a7eafa9f5e8b2062c32ab4ff78968..0582698825544267e65a427351e27101c320bc0a 100644
index cf5b99c1337a7eafa9f5e8b2062c32ab4ff78968..e046d070e24c892743b241136f18c14c10f1efd9 100644
--- a/net/minecraft/world/inventory/ChestMenu.java
+++ b/net/minecraft/world/inventory/ChestMenu.java
@@ -61,10 +61,30 @@ public class ChestMenu extends AbstractContainerMenu {
@@ -84,7 +84,7 @@ index cf5b99c1337a7eafa9f5e8b2062c32ab4ff78968..0582698825544267e65a427351e27101
return new ChestMenu(MenuType.GENERIC_9x6, containerId, playerInventory, container, 6);
}
diff --git a/net/minecraft/world/inventory/PlayerEnderChestContainer.java b/net/minecraft/world/inventory/PlayerEnderChestContainer.java
index a6a359bab2a727f4631b633a8bb370dd40decc75..4c48bdc2a4596b7b192e76974fa385c323ddabb2 100644
index a6a359bab2a727f4631b633a8bb370dd40decc75..d2d75e5c34c97300ce5da8c7ea70958aba31fa4a 100644
--- a/net/minecraft/world/inventory/PlayerEnderChestContainer.java
+++ b/net/minecraft/world/inventory/PlayerEnderChestContainer.java
@@ -25,11 +25,18 @@ public class PlayerEnderChestContainer extends SimpleContainer {
@@ -108,7 +108,7 @@ index a6a359bab2a727f4631b633a8bb370dd40decc75..4c48bdc2a4596b7b192e76974fa385c3
this.activeChest = enderChestBlockEntity;
}
diff --git a/net/minecraft/world/level/block/EnderChestBlock.java b/net/minecraft/world/level/block/EnderChestBlock.java
index 2f60681c50e3656400e84fe9a7670e0412743853..79dbafcfde314058bdf95f887fa7a1032433032c 100644
index 2f60681c50e3656400e84fe9a7670e0412743853..6e3d28aa6206d969815889ed327a5e343b8658d9 100644
--- a/net/minecraft/world/level/block/EnderChestBlock.java
+++ b/net/minecraft/world/level/block/EnderChestBlock.java
@@ -84,7 +84,7 @@ public class EnderChestBlock extends AbstractChestBlock<EnderChestBlockEntity> i
@@ -157,7 +157,7 @@ index 2f60681c50e3656400e84fe9a7670e0412743853..79dbafcfde314058bdf95f887fa7a103
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new EnderChestBlockEntity(pos, state);
diff --git a/net/minecraft/world/level/block/entity/BarrelBlockEntity.java b/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
index 0f808855f58281578c2758513787f0f7330c9291..7ea7032eae78726e6d4dcfda49b01a10e0f26de8 100644
index 0f808855f58281578c2758513787f0f7330c9291..9f6063089f0aa3a68d26ae7cfe39379123ab2f47 100644
--- a/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
+++ b/net/minecraft/world/level/block/entity/BarrelBlockEntity.java
@@ -55,7 +55,17 @@ public class BarrelBlockEntity extends RandomizableContainerBlockEntity {

View File

@@ -5,10 +5,10 @@ Subject: [PATCH] Minecart settings and WASD controls
diff --git a/net/minecraft/server/level/ServerPlayer.java b/net/minecraft/server/level/ServerPlayer.java
index d6e17c816e7dc2260d95490145a1e571cdffb912..69dfdfca73206dd93b660efcb41a63dca5b7842d 100644
index c03639557e498f44a53fbf223928f68e515638eb..bc0a19d7ce8a080f2e75efa8bd9ab497038a3ac1 100644
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -1229,6 +1229,11 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
@@ -1233,6 +1233,11 @@ public class ServerPlayer extends Player implements ca.spottedleaf.moonrise.patc
} else {
// Purpur start - Add boat fall damage config
if (damageSource.is(net.minecraft.tags.DamageTypeTags.IS_FALL)) {

View File

@@ -7,10 +7,10 @@ temporarily migrate to paper's config
drop patch on the next minecraft release
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index b5011af774484b6ed35ee83b4a562ddd4425c22f..88c90e0ffca024c2867a7ed70d53d12aff7201c6 100644
index 5cba0608e24d2f5a687921e0c6b68827925590cd..90cdcb8934e28dcc51272c9b40a6d89ac5dec75e 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1198,7 +1198,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1199,7 +1199,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
LOGGER.info("*************************************************************************************");
}
// Paper end - Add onboarding message for initial server start
@@ -28,7 +28,7 @@ index b5011af774484b6ed35ee83b4a562ddd4425c22f..88c90e0ffca024c2867a7ed70d53d12a
long l;
if (!this.isPaused() && this.tickRateManager.isSprinting() && this.tickRateManager.checkShouldSprintThisTick()) {
diff --git a/net/minecraft/server/dedicated/DedicatedServer.java b/net/minecraft/server/dedicated/DedicatedServer.java
index aa896acd15916df24e646d10a7a3c5157044b4bd..92948d75c928368f3d1999b45951648a6be3fdc7 100644
index d685bbaed0afe5be40ce18ad92fd8d9f351bd90e..c02a7375d356ccdb23c24c784584029eab51fae1 100644
--- a/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/net/minecraft/server/dedicated/DedicatedServer.java
@@ -208,6 +208,15 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface

View File

@@ -8,13 +8,14 @@
import org.slf4j.Logger;
public class Commands {
@@ -245,6 +_,9 @@
@@ -245,6 +_,10 @@
StopCommand.register(this.dispatcher);
TransferCommand.register(this.dispatcher);
WhitelistCommand.register(this.dispatcher);
+ org.purpurmc.purpur.command.CreditsCommand.register(this.dispatcher); // Purpur - Add credits command
+ org.purpurmc.purpur.command.DemoCommand.register(this.dispatcher); // Purpur - Add demo command
+ org.purpurmc.purpur.command.PingCommand.register(this.dispatcher); // Purpur - Add ping command
+ org.purpurmc.purpur.command.TPSBarCommand.register(this.dispatcher); // Purpur - Implement TPSBar
}
if (selection.includeIntegrated) {

View File

@@ -17,6 +17,14 @@
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
@@ -1093,6 +_,7 @@
this.safeShutdown(waitForServer, false);
}
public void safeShutdown(boolean waitForServer, boolean isRestarting) {
+ org.purpurmc.purpur.task.BossBarTask.stopAll(); // Purpur - Implement TPSBar
this.isRestarting = isRestarting;
this.hasLoggedStop = true; // Paper - Debugging
if (isDebugging()) io.papermc.paper.util.TraceUtil.dumpTraceForThread("Server stopped"); // Paper - Debugging
@@ -1112,6 +_,7 @@
private static final long MAX_CATCHUP_BUFFER = TICK_TIME * TPS * 60L;
private long lastTick = 0;

View File

@@ -16,3 +16,11 @@
com.destroystokyo.paper.VersionHistoryManager.INSTANCE.getClass(); // Paper - load version history now
this.setPvpAllowed(properties.pvp);
@@ -350,6 +_,7 @@
LOGGER.info("JMX monitoring enabled");
}
+ org.purpurmc.purpur.task.BossBarTask.startAll(); // Purpur - Implement TPSBar
return true;
}
}

View File

@@ -1,13 +1,31 @@
--- a/net/minecraft/server/level/ServerPlayer.java
+++ b/net/minecraft/server/level/ServerPlayer.java
@@ -393,6 +_,7 @@
@@ -393,6 +_,8 @@
public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
public @Nullable String clientBrandName = null; // Paper - Brand support
public org.bukkit.event.player.PlayerQuitEvent.QuitReason quitReason = null; // Paper - Add API for quit reason; there are a lot of changes to do if we change all methods leading to the event
+ public boolean purpurClient = false; // Purpur - Purpur client support
+ private boolean tpsBar = false; // Purpur - Implement TPSBar
// Paper start - rewrite chunk system
private ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.PlayerChunkLoaderData chunkLoader;
@@ -561,6 +_,8 @@
if (tag != null) {
BlockPos.CODEC.parse(NbtOps.INSTANCE, tag).resultOrPartial(LOGGER::error).ifPresent(pos -> this.raidOmenPosition = pos);
}
+
+ if (compound.contains("Purpur.TPSBar")) { this.tpsBar = compound.getBoolean("Purpur.TPSBar"); } // Purpur - Implement TPSBar
}
@Override
@@ -605,6 +_,7 @@
}
this.saveEnderPearls(compound);
+ compound.putBoolean("Purpur.TPSBar", this.tpsBar); // Purpur - Implement TPSBar
}
private void saveParentVehicle(CompoundTag tag) {
@@ -1217,6 +_,13 @@
if (this.isInvulnerableTo(level, damageSource)) {
return false;
@@ -139,7 +157,7 @@
public ServerStatsCounter getStats() {
return this.stats;
@@ -3077,4 +_,26 @@
@@ -3077,4 +_,36 @@
return (org.bukkit.craftbukkit.entity.CraftPlayer) super.getBukkitEntity();
}
// CraftBukkit end
@@ -165,4 +183,14 @@
+ }
+ }
+ // Purpur end - Add option to teleport to spawn if outside world border
+
+ // Purpur start - Implement TPSBar
+ public boolean tpsBar() {
+ return this.tpsBar;
+ }
+
+ public void tpsBar(boolean tpsBar) {
+ this.tpsBar = tpsBar;
+ }
+ // Purpur end - Implement TPSBar
}

View File

@@ -1,5 +1,21 @@
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -396,6 +_,7 @@
scoreboard.addPlayerToTeam(player.getScoreboardName(), collideRuleTeam);
}
// Paper end - Configurable player collision
+ org.purpurmc.purpur.task.BossBarTask.addToAll(player); // Purpur - Implement TPSBar
PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", player.getName().getString(), loggableAddress, player.getId(), serverLevel.serverLevelData.getLevelName(), player.getX(), player.getY(), player.getZ());
// Paper start - Send empty chunk, so players aren't stuck in the world loading screen with our chunk system not sending chunks when dead
if (player.isDeadOrDying()) {
@@ -501,6 +_,7 @@
}
public net.kyori.adventure.text.Component remove(ServerPlayer player, net.kyori.adventure.text.Component leaveMessage) {
// Paper end - Fix kick event leave message not being sent
+ org.purpurmc.purpur.task.BossBarTask.removeFromAll(player.getBukkitEntity()); // Purpur - Implement TPSBar
ServerLevel serverLevel = player.serverLevel();
player.awardStat(Stats.LEAVE_GAME);
// CraftBukkit start - Quitting must be before we do final save of data, in case plugins need to modify it
@@ -919,6 +_,20 @@
}
}

View File

@@ -2,6 +2,7 @@ package org.purpurmc.purpur;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.entity.EntityDimensions;
@@ -24,6 +25,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import org.purpurmc.purpur.task.TPSBarTask;
@SuppressWarnings("unused")
public class PurpurConfig {
@@ -168,6 +170,7 @@ public class PurpurConfig {
public static String creditsCommandOutput = "<green>%s has been shown the end credits";
public static String demoCommandOutput = "<green>%s has been shown the demo screen";
public static String pingCommandOutput = "<green>%s's ping is %sms";
public static String tpsbarCommandOutput = "<green>Tpsbar toggled <onoff> for <target>";
private static void messages() {
cannotRideMob = getString("settings.messages.cannot-ride-mob", cannotRideMob);
afkBroadcastAway = getString("settings.messages.afk-broadcast-away", afkBroadcastAway);
@@ -178,6 +181,7 @@ public class PurpurConfig {
creditsCommandOutput = getString("settings.messages.credits-command-output", creditsCommandOutput);
demoCommandOutput = getString("settings.messages.demo-command-output", demoCommandOutput);
pingCommandOutput = getString("settings.messages.ping-command-output", pingCommandOutput);
tpsbarCommandOutput = getString("settings.messages.tpsbar-command-output", tpsbarCommandOutput);
}
public static String serverModName = io.papermc.paper.ServerBuildInfo.buildInfo().brandName();
@@ -200,6 +204,29 @@ public class PurpurConfig {
disableGiveCommandDrops = getBoolean("settings.disable-give-dropping", disableGiveCommandDrops);
}
public static String commandTPSBarTitle = "<gray>TPS<yellow>:</yellow> <tps> MSPT<yellow>:</yellow> <mspt> Ping<yellow>:</yellow> <ping>ms";
public static BossBar.Overlay commandTPSBarProgressOverlay = BossBar.Overlay.NOTCHED_20;
public static TPSBarTask.FillMode commandTPSBarProgressFillMode = TPSBarTask.FillMode.MSPT;
public static BossBar.Color commandTPSBarProgressColorGood = BossBar.Color.GREEN;
public static BossBar.Color commandTPSBarProgressColorMedium = BossBar.Color.YELLOW;
public static BossBar.Color commandTPSBarProgressColorLow = BossBar.Color.RED;
public static String commandTPSBarTextColorGood = "<gradient:#55ff55:#00aa00><text></gradient>";
public static String commandTPSBarTextColorMedium = "<gradient:#ffff55:#ffaa00><text></gradient>";
public static String commandTPSBarTextColorLow = "<gradient:#ff5555:#aa0000><text></gradient>";
public static int commandTPSBarTickInterval = 20;
private static void commandSettings() {
commandTPSBarTitle = getString("settings.command.tpsbar.title", commandTPSBarTitle);
commandTPSBarProgressOverlay = BossBar.Overlay.valueOf(getString("settings.command.tpsbar.overlay", commandTPSBarProgressOverlay.name()));
commandTPSBarProgressFillMode = TPSBarTask.FillMode.valueOf(getString("settings.command.tpsbar.fill-mode", commandTPSBarProgressFillMode.name()));
commandTPSBarProgressColorGood = BossBar.Color.valueOf(getString("settings.command.tpsbar.progress-color.good", commandTPSBarProgressColorGood.name()));
commandTPSBarProgressColorMedium = BossBar.Color.valueOf(getString("settings.command.tpsbar.progress-color.medium", commandTPSBarProgressColorMedium.name()));
commandTPSBarProgressColorLow = BossBar.Color.valueOf(getString("settings.command.tpsbar.progress-color.low", commandTPSBarProgressColorLow.name()));
commandTPSBarTextColorGood = getString("settings.command.tpsbar.text-color.good", commandTPSBarTextColorGood);
commandTPSBarTextColorMedium = getString("settings.command.tpsbar.text-color.medium", commandTPSBarTextColorMedium);
commandTPSBarTextColorLow = getString("settings.command.tpsbar.text-color.low", commandTPSBarTextColorLow);
commandTPSBarTickInterval = getInt("settings.command.tpsbar.tick-interval", commandTPSBarTickInterval);
}
public static int barrelRows = 3;
public static boolean enderChestSixRows = false;
public static boolean enderChestPermissionRows = false;

View File

@@ -0,0 +1,44 @@
package org.purpurmc.purpur.command;
import com.mojang.brigadier.CommandDispatcher;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.arguments.EntityArgument;
import net.minecraft.server.level.ServerPlayer;
import org.purpurmc.purpur.PurpurConfig;
import org.purpurmc.purpur.task.TPSBarTask;
import java.util.Collection;
import java.util.Collections;
public class TPSBarCommand {
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
dispatcher.register(Commands.literal("tpsbar")
.requires(listener -> listener.hasPermission(2, "bukkit.command.tpsbar"))
.executes(context -> execute(context.getSource(), Collections.singleton(context.getSource().getPlayerOrException())))
.then(Commands.argument("targets", EntityArgument.players())
.requires(listener -> listener.hasPermission(2, "bukkit.command.tpsbar.other"))
.executes((context) -> execute(context.getSource(), EntityArgument.getPlayers(context, "targets")))
)
);
}
private static int execute(CommandSourceStack sender, Collection<ServerPlayer> targets) {
for (ServerPlayer player : targets) {
boolean result = TPSBarTask.instance().togglePlayer(player.getBukkitEntity());
player.tpsBar(result);
Component output = MiniMessage.miniMessage().deserialize(PurpurConfig.tpsbarCommandOutput,
Placeholder.component("onoff", Component.translatable(result ? "options.on" : "options.off")
.color(result ? NamedTextColor.GREEN : NamedTextColor.RED)),
Placeholder.parsed("target", player.getGameProfile().getName()));
sender.sendSuccess(output, false);
}
return targets.size();
}
}

View File

@@ -0,0 +1,109 @@
package org.purpurmc.purpur.task;
import net.kyori.adventure.bossbar.BossBar;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import org.purpurmc.purpur.util.MinecraftInternalPlugin;
public abstract class BossBarTask extends BukkitRunnable {
private final Map<UUID, BossBar> bossbars = new HashMap<>();
private boolean started;
abstract BossBar createBossBar();
abstract void updateBossBar(BossBar bossbar, Player player);
@Override
public void run() {
Iterator<Map.Entry<UUID, BossBar>> iter = bossbars.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<UUID, BossBar> entry = iter.next();
Player player = Bukkit.getPlayer(entry.getKey());
if (player == null) {
iter.remove();
continue;
}
updateBossBar(entry.getValue(), player);
}
}
@Override
public void cancel() {
super.cancel();
new HashSet<>(this.bossbars.keySet()).forEach(uuid -> {
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
removePlayer(player);
}
});
this.bossbars.clear();
}
public boolean removePlayer(Player player) {
BossBar bossbar = this.bossbars.remove(player.getUniqueId());
if (bossbar != null) {
player.hideBossBar(bossbar);
return true;
}
return false;
}
public void addPlayer(Player player) {
removePlayer(player);
BossBar bossbar = createBossBar();
this.bossbars.put(player.getUniqueId(), bossbar);
this.updateBossBar(bossbar, player);
player.showBossBar(bossbar);
}
public boolean hasPlayer(UUID uuid) {
return this.bossbars.containsKey(uuid);
}
public boolean togglePlayer(Player player) {
if (removePlayer(player)) {
return false;
}
addPlayer(player);
return true;
}
public void start() {
stop();
this.runTaskTimerAsynchronously(new MinecraftInternalPlugin(), 1, 1);
started = true;
}
public void stop() {
if (started) {
cancel();
}
}
public static void startAll() {
TPSBarTask.instance().start();
}
public static void stopAll() {
TPSBarTask.instance().stop();
}
public static void addToAll(ServerPlayer player) {
Player bukkit = player.getBukkitEntity();
if (player.tpsBar()) {
TPSBarTask.instance().addPlayer(bukkit);
}
}
public static void removeFromAll(Player player) {
TPSBarTask.instance().removePlayer(player);
}
}

View File

@@ -0,0 +1,142 @@
package org.purpurmc.purpur.task;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.purpurmc.purpur.PurpurConfig;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class TPSBarTask extends BossBarTask {
private static TPSBarTask instance;
private double tps = 20.0D;
private double mspt = 0.0D;
private int tick = 0;
public static TPSBarTask instance() {
if (instance == null) {
instance = new TPSBarTask();
}
return instance;
}
@Override
BossBar createBossBar() {
return BossBar.bossBar(Component.text(""), 0.0F, instance().getBossBarColor(), PurpurConfig.commandTPSBarProgressOverlay);
}
@Override
void updateBossBar(BossBar bossbar, Player player) {
bossbar.progress(getBossBarProgress());
bossbar.color(getBossBarColor());
bossbar.name(MiniMessage.miniMessage().deserialize(PurpurConfig.commandTPSBarTitle,
Placeholder.component("tps", getTPSColor()),
Placeholder.component("mspt", getMSPTColor()),
Placeholder.component("ping", getPingColor(player.getPing()))
));
}
@Override
public void run() {
if (++tick < PurpurConfig.commandTPSBarTickInterval) {
return;
}
tick = 0;
this.tps = Math.max(Math.min(Bukkit.getTPS()[0], 20.0D), 0.0D);
this.mspt = Bukkit.getAverageTickTime();
super.run();
}
private float getBossBarProgress() {
if (PurpurConfig.commandTPSBarProgressFillMode == FillMode.MSPT) {
return Math.max(Math.min((float) mspt / 50.0F, 1.0F), 0.0F);
} else {
return Math.max(Math.min((float) tps / 20.0F, 1.0F), 0.0F);
}
}
private BossBar.Color getBossBarColor() {
if (isGood(PurpurConfig.commandTPSBarProgressFillMode)) {
return PurpurConfig.commandTPSBarProgressColorGood;
} else if (isMedium(PurpurConfig.commandTPSBarProgressFillMode)) {
return PurpurConfig.commandTPSBarProgressColorMedium;
} else {
return PurpurConfig.commandTPSBarProgressColorLow;
}
}
private boolean isGood(FillMode mode) {
return isGood(mode, 0);
}
private boolean isGood(FillMode mode, int ping) {
if (mode == FillMode.MSPT) {
return mspt < 40;
} else if (mode == FillMode.TPS) {
return tps >= 19;
} else if (mode == FillMode.PING) {
return ping < 100;
} else {
return false;
}
}
private boolean isMedium(FillMode mode) {
return isMedium(mode, 0);
}
private boolean isMedium(FillMode mode, int ping) {
if (mode == FillMode.MSPT) {
return mspt < 50;
} else if (mode == FillMode.TPS) {
return tps >= 15;
} else if (mode == FillMode.PING) {
return ping < 200;
} else {
return false;
}
}
private Component getTPSColor() {
String color;
if (isGood(FillMode.TPS)) {
color = PurpurConfig.commandTPSBarTextColorGood;
} else if (isMedium(FillMode.TPS)) {
color = PurpurConfig.commandTPSBarTextColorMedium;
} else {
color = PurpurConfig.commandTPSBarTextColorLow;
}
return MiniMessage.miniMessage().deserialize(color, Placeholder.parsed("text", String.format("%.2f", tps)));
}
private Component getMSPTColor() {
String color;
if (isGood(FillMode.MSPT)) {
color = PurpurConfig.commandTPSBarTextColorGood;
} else if (isMedium(FillMode.MSPT)) {
color = PurpurConfig.commandTPSBarTextColorMedium;
} else {
color = PurpurConfig.commandTPSBarTextColorLow;
}
return MiniMessage.miniMessage().deserialize(color, Placeholder.parsed("text", String.format("%.2f", mspt)));
}
private Component getPingColor(int ping) {
String color;
if (isGood(FillMode.PING, ping)) {
color = PurpurConfig.commandTPSBarTextColorGood;
} else if (isMedium(FillMode.PING, ping)) {
color = PurpurConfig.commandTPSBarTextColorMedium;
} else {
color = PurpurConfig.commandTPSBarTextColorLow;
}
return MiniMessage.miniMessage().deserialize(color, Placeholder.parsed("text", String.format("%s", ping)));
}
public enum FillMode {
TPS, MSPT, PING
}
}