mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-21 07:49:18 +00:00
89 lines
3.7 KiB
Diff
89 lines
3.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
|
|
Date: Sat, 8 Mar 2025 16:58:24 +0300
|
|
Subject: [PATCH] MSPT Tracking for each world
|
|
|
|
|
|
diff --git a/src/main/java/org/purpurmc/purpur/task/TPSBarTask.java b/src/main/java/org/purpurmc/purpur/task/TPSBarTask.java
|
|
index 8769993e7ca59da309087051a3cd38fc562c15d1..3d1b183da57e7e267973db27867c7d9a6a64c044 100644
|
|
--- a/src/main/java/org/purpurmc/purpur/task/TPSBarTask.java
|
|
+++ b/src/main/java/org/purpurmc/purpur/task/TPSBarTask.java
|
|
@@ -4,6 +4,8 @@ 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 net.minecraft.server.level.ServerLevel;
|
|
+import org.bukkit.craftbukkit.CraftWorld;
|
|
import org.purpurmc.purpur.PurpurConfig;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.entity.Player;
|
|
@@ -28,14 +30,64 @@ public class TPSBarTask extends BossBarTask {
|
|
|
|
@Override
|
|
void updateBossBar(BossBar bossbar, Player player) {
|
|
- bossbar.progress(getBossBarProgress());
|
|
- bossbar.color(getBossBarColor());
|
|
- bossbar.name(MiniMessage.miniMessage().deserialize(PurpurConfig.commandTPSBarTitle,
|
|
+ // DivineMC start - MSPT Tracking for each world
|
|
+ if (org.bxteam.divinemc.DivineConfig.enableParallelWorldTicking) {
|
|
+ ServerLevel serverLevel = ((CraftWorld)player.getWorld()).getHandle();
|
|
+
|
|
+ double worldMspt = calculateWorldMSPT(serverLevel);
|
|
+ double worldTps = Math.min(20.0, 1000.0 / Math.max(worldMspt, 0.001));
|
|
+
|
|
+ double originalTps = this.tps;
|
|
+ double originalMspt = this.mspt;
|
|
+
|
|
+ try {
|
|
+ this.tps = worldTps;
|
|
+ this.mspt = worldMspt;
|
|
+
|
|
+ Component msptWithWorld = Component.empty()
|
|
+ .append(getMSPTColor())
|
|
+ .append(Component.text(" [" + player.getWorld().getName() + "]").color(net.kyori.adventure.text.format.NamedTextColor.GRAY));
|
|
+
|
|
+ bossbar.progress(getBossBarProgress());
|
|
+ bossbar.color(getBossBarColor());
|
|
+ bossbar.name(MiniMessage.miniMessage().deserialize(PurpurConfig.commandTPSBarTitle,
|
|
+ Placeholder.component("tps", getTPSColor()),
|
|
+ Placeholder.component("mspt", msptWithWorld),
|
|
+ Placeholder.component("ping", getPingColor(player.getPing()))
|
|
+ ));
|
|
+ } finally {
|
|
+ this.tps = originalTps;
|
|
+ this.mspt = originalMspt;
|
|
+ }
|
|
+ } else {
|
|
+ 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()))
|
|
- ));
|
|
+ ));
|
|
+ }
|
|
+ // DivineMC end - MSPT Tracking for each world
|
|
+ }
|
|
+
|
|
+ // DivineMC start - MSPT Tracking for each world
|
|
+ private double calculateWorldMSPT(ServerLevel serverLevel) {
|
|
+ long[] times = serverLevel.tickTimes5s.getTimes();
|
|
+ long total = 0L;
|
|
+ int count = 0;
|
|
+
|
|
+ for (long value : times) {
|
|
+ if (value > 0L) {
|
|
+ total += value;
|
|
+ count++;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (count == 0) return 0.0;
|
|
+ return (double) total / (double) count * 1.0E-6D;
|
|
}
|
|
+ // DivineMC end - MSPT Tracking for each world
|
|
|
|
@Override
|
|
public void run() {
|