feature: added tps and ping in tab
This commit is contained in:
parent
d6991a30b0
commit
2e3a4315c2
@ -54,6 +54,7 @@ public class TablistService implements Listener {
|
||||
|
||||
private void updateAll() {
|
||||
updateSorting();
|
||||
updatePlayerListNames();
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
updateHeaderFooter(player);
|
||||
}
|
||||
@ -138,6 +139,39 @@ public class TablistService implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePlayerListNames() {
|
||||
for (Player target : Bukkit.getOnlinePlayers()) {
|
||||
User user = luckPerms.getUserManager().getUser(target.getUniqueId());
|
||||
String prefix = user != null ? user.getCachedData().getMetaData().getPrefix() : null;
|
||||
|
||||
Component nameComponent = Component.text(target.getName(), NamedTextColor.WHITE)
|
||||
.decoration(TextDecoration.BOLD, false);
|
||||
if (prefix != null && !prefix.isEmpty()) {
|
||||
Component rankComp = MiniMessage.miniMessage().deserialize(prefix);
|
||||
nameComponent = rankComp.append(Component.text(" ").decoration(TextDecoration.BOLD, false))
|
||||
.append(nameComponent);
|
||||
}
|
||||
|
||||
int ping = target.getPing();
|
||||
Component pingComponent = Component.text(" [" + ping + "ms]", getPingColor(ping))
|
||||
.decoration(TextDecoration.BOLD, false);
|
||||
|
||||
target.playerListName(nameComponent.append(pingComponent));
|
||||
}
|
||||
}
|
||||
|
||||
private TextColor getPingColor(int ping) {
|
||||
if (ping <= 50) return NamedTextColor.GREEN;
|
||||
if (ping <= 150) return NamedTextColor.YELLOW;
|
||||
return NamedTextColor.RED;
|
||||
}
|
||||
|
||||
private TextColor getTpsColor(double tps) {
|
||||
if (tps >= 18.0) return NamedTextColor.GREEN;
|
||||
if (tps >= 15.0) return NamedTextColor.YELLOW;
|
||||
return NamedTextColor.RED;
|
||||
}
|
||||
|
||||
private void updateHeaderFooter(Player player) {
|
||||
Component title = ColorUtil.applyGradient("ᴍɪɴɪɴɢᴍᴀɴ.eu", gradientColors)
|
||||
.decorate(TextDecoration.BOLD);
|
||||
@ -154,8 +188,16 @@ public class TablistService implements Listener {
|
||||
Component discordLine = Component.text(" ᴅɪsᴄᴏʀᴅ: ", TextColor.fromHexString("#FE5A1D"))
|
||||
.append(Component.text("discord.gg/V32MCYsFhn ", NamedTextColor.WHITE));
|
||||
|
||||
double tps = Math.min(20.0, Bukkit.getServer().getTPS()[0]);
|
||||
Component tpsLine = Component.text(" ᴛᴘs: ", TextColor.fromHexString("#FE5A1D"))
|
||||
.append(Component.text(String.format("%.1f", tps), getTpsColor(tps)))
|
||||
.append(Component.text(" ᴘɪɴɢ: ", TextColor.fromHexString("#FE5A1D")))
|
||||
.append(Component.text(player.getPing() + "ms", getPingColor(player.getPing())));
|
||||
|
||||
Component footer = Component.newline()
|
||||
.append(discordLine)
|
||||
.append(Component.newline())
|
||||
.append(tpsLine)
|
||||
.append(Component.newline());
|
||||
|
||||
player.sendPlayerListHeaderAndFooter(header, footer);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user