mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
* tps-bar-show-tps-of-server-option * Configurable file locations for `banned-players.json`, `banned-ips.json`, `ops.json`, `whitelist.json`, `help.yml` and `.console_history` and option to see server tps instead of world tps with RCT and per world tpsbar
93 lines
4.0 KiB
Diff
93 lines
4.0 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..b6ecadfb23bb4f694a3b0a138f927936267a02df 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,68 @@ 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.config.DivineConfig.AsyncCategory.enableParallelWorldTicking && org.bxteam.divinemc.config.DivineConfig.AsyncCategory.usePerWorldTpsBar) {
|
|
+ ServerLevel serverLevel = ((CraftWorld)player.getWorld()).getHandle();
|
|
+
|
|
+ double worldMspt = calculateWorldMSPT(serverLevel);
|
|
+ double worldTps = this.tps;
|
|
+
|
|
+ if (!org.bxteam.divinemc.config.DivineConfig.AsyncCategory.showTPSOfServerInsteadOfWorld) {
|
|
+ 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() {
|