Fully use chat components in PerformanceAnalysisManager lag bar
This commit is contained in:
parent
3b4cf63c48
commit
21777d4b9e
@ -21,6 +21,7 @@ import net.kyori.adventure.bossbar.BossBar.Color;
|
|||||||
import net.kyori.adventure.bossbar.BossBar.Overlay;
|
import net.kyori.adventure.bossbar.BossBar.Overlay;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
@ -36,6 +37,7 @@ import java.lang.management.ThreadMXBean;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import static fr.pandacube.lib.chat.ChatStatic.chat;
|
import static fr.pandacube.lib.chat.ChatStatic.chat;
|
||||||
import static fr.pandacube.lib.chat.ChatStatic.failureText;
|
import static fr.pandacube.lib.chat.ChatStatic.failureText;
|
||||||
@ -318,20 +320,23 @@ public class PerformanceAnalysisManager implements Listener {
|
|||||||
|
|
||||||
int[] tpsHistory = getTPSHistory();
|
int[] tpsHistory = getTPSHistory();
|
||||||
|
|
||||||
// keep the legacy text when generating the bar to save space when converting to component
|
List<Pair<TextColor, AtomicInteger>> barComponents = new ArrayList<>(60);
|
||||||
StringBuilder s = new StringBuilder();
|
|
||||||
TextColor prevC = null;
|
|
||||||
for (int i = 58; i >= 0; i--) {
|
for (int i = 58; i >= 0; i--) {
|
||||||
int t = tpsHistory[i];
|
int t = tpsHistory[i];
|
||||||
TextColor newC = tps1sGradient.pickColorAt(t);
|
TextColor newC = tps1sGradient.pickColorAt(t);
|
||||||
if (!newC.equals(prevC)) {
|
if (barComponents.isEmpty() || !newC.equals(barComponents.get(barComponents.size() - 1).getKey())) {
|
||||||
s.append(text("|").color(newC).getLegacyText());
|
barComponents.add(Pair.of(newC, new AtomicInteger(1)));
|
||||||
prevC = newC;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
s.append("|");
|
barComponents.get(barComponents.size() - 1).getValue().incrementAndGet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Chat history = chat();
|
||||||
|
barComponents.forEach(p -> {
|
||||||
|
history.then(text("|".repeat(p.getValue().get()))
|
||||||
|
.color(p.getKey())
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -355,7 +360,7 @@ public class PerformanceAnalysisManager implements Listener {
|
|||||||
: (avgTickCPUTime1s < 50) ? NamedTextColor.RED
|
: (avgTickCPUTime1s < 50) ? NamedTextColor.RED
|
||||||
: NamedTextColor.DARK_RED;
|
: NamedTextColor.DARK_RED;
|
||||||
|
|
||||||
float avgTickWaitingTime1s = avgTickDuration1s - avgTickCPUTime1s;
|
float avgTickWaitingTime1s = Math.max(0, avgTickDuration1s - avgTickCPUTime1s);
|
||||||
TextColor avgTickWaitingTime1sColor = (avgTickDuration1s < 46 || avgTickWaitingTime1s < 20) ? PandaTheme.CHAT_GREEN_1_NORMAL
|
TextColor avgTickWaitingTime1sColor = (avgTickDuration1s < 46 || avgTickWaitingTime1s < 20) ? PandaTheme.CHAT_GREEN_1_NORMAL
|
||||||
: (avgTickWaitingTime1s < 30) ? NamedTextColor.YELLOW
|
: (avgTickWaitingTime1s < 30) ? NamedTextColor.YELLOW
|
||||||
: (avgTickWaitingTime1s < 40) ? NamedTextColor.GOLD
|
: (avgTickWaitingTime1s < 40) ? NamedTextColor.GOLD
|
||||||
@ -371,16 +376,16 @@ public class PerformanceAnalysisManager implements Listener {
|
|||||||
: NamedTextColor.RED;
|
: NamedTextColor.RED;
|
||||||
|
|
||||||
timings = text("(R/W/S:")
|
timings = text("(R/W/S:")
|
||||||
.then(text(Math.round(avgTickCPUTime1s)).color(avgTickCPUTime1sColor))
|
.then(text("%02d".formatted(Math.round(avgTickCPUTime1s))).color(avgTickCPUTime1sColor))
|
||||||
.thenText("/")
|
.thenText("/")
|
||||||
.then(text(Math.round(avgTickWaitingTime1s)).color(avgTickWaitingTime1sColor))
|
.then(text("%02d".formatted(Math.round(avgTickWaitingTime1s))).color(avgTickWaitingTime1sColor))
|
||||||
.thenText("/")
|
.thenText("/")
|
||||||
.then(text(Math.round(avgInterTickDuration1s)).color(avgInterTickDuration1sColor))
|
.then(text("%02d".formatted(Math.round(avgInterTickDuration1s))).color(avgInterTickDuration1sColor))
|
||||||
.thenText("ms)");
|
.thenText("ms)");
|
||||||
}
|
}
|
||||||
|
|
||||||
title = infoText("TPS [")
|
title = infoText("TPS [")
|
||||||
.thenLegacyText(s.toString())
|
.thenLegacyText(history)
|
||||||
.thenText("] ")
|
.thenText("] ")
|
||||||
.then(text(tps1sDisplay + "/" + getTargetTickRate() + " ").color(tps1sGradient.pickColorAt(tps1s)))
|
.then(text(tps1sDisplay + "/" + getTargetTickRate() + " ").color(tps1sGradient.pickColorAt(tps1s)))
|
||||||
.then(timings);
|
.then(timings);
|
||||||
|
Loading…
Reference in New Issue
Block a user