extended infobars, added coloring
This commit is contained in:
parent
0f976d2316
commit
b9f88bc4b2
@ -1,17 +1,18 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliances.infoBars.bars;
|
package eu.mhsl.craftattack.spawn.appliances.infoBars.bars;
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.appliances.infoBars.Bar;
|
import eu.mhsl.craftattack.spawn.appliances.infoBars.Bar;
|
||||||
|
import eu.mhsl.craftattack.spawn.util.statistics.ServerMonitor;
|
||||||
|
import eu.mhsl.craftattack.spawn.util.text.ColorUtil;
|
||||||
import net.kyori.adventure.bossbar.BossBar;
|
import net.kyori.adventure.bossbar.BossBar;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
public class MsptBar extends Bar {
|
public class MsptBar extends Bar {
|
||||||
@Override
|
@Override
|
||||||
protected Duration refresh() {
|
protected Duration refresh() {
|
||||||
return Duration.ofSeconds(1);
|
return Duration.ofSeconds(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -30,21 +31,27 @@ public class MsptBar extends Bar {
|
|||||||
.append(Component.text("er ", NamedTextColor.GRAY))
|
.append(Component.text("er ", NamedTextColor.GRAY))
|
||||||
.append(Component.text("T"))
|
.append(Component.text("T"))
|
||||||
.append(Component.text("ick", NamedTextColor.GRAY))
|
.append(Component.text("ick", NamedTextColor.GRAY))
|
||||||
|
.append(Component.text(": "))
|
||||||
|
.append(Component.text(String.format("%.2f", this.currentMSPT()), ColorUtil.msptColor(this.currentMSPT())))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float progress() {
|
protected float progress() {
|
||||||
return Bukkit.getServer().getTickTimes()[0] / 50f;
|
return this.currentMSPT() / 50f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BossBar.Color color() {
|
protected BossBar.Color color() {
|
||||||
return BossBar.Color.YELLOW;
|
return BossBar.Color.BLUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BossBar.Overlay overlay() {
|
protected BossBar.Overlay overlay() {
|
||||||
return BossBar.Overlay.NOTCHED_10;
|
return BossBar.Overlay.PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float currentMSPT() {
|
||||||
|
return ServerMonitor.getServerMSPT();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,10 @@ package eu.mhsl.craftattack.spawn.appliances.infoBars.bars;
|
|||||||
import eu.mhsl.craftattack.spawn.Main;
|
import eu.mhsl.craftattack.spawn.Main;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.infoBars.Bar;
|
import eu.mhsl.craftattack.spawn.appliances.infoBars.Bar;
|
||||||
import eu.mhsl.craftattack.spawn.appliances.playerlimit.PlayerLimit;
|
import eu.mhsl.craftattack.spawn.appliances.playerlimit.PlayerLimit;
|
||||||
|
import eu.mhsl.craftattack.spawn.util.text.ColorUtil;
|
||||||
import net.kyori.adventure.bossbar.BossBar;
|
import net.kyori.adventure.bossbar.BossBar;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
@ -22,14 +24,16 @@ public class PlayerCounterBar extends Bar {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Component title() {
|
protected Component title() {
|
||||||
return Component.text("Spieler online");
|
TextColor color = ColorUtil.mapGreenToRed(this.getCurrentPlayerCount(), 0, this.getMaxPlayerCount(), true);
|
||||||
|
return Component.text()
|
||||||
|
.append(Component.text("Spieler online: "))
|
||||||
|
.append(Component.text(this.getCurrentPlayerCount(), color))
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float progress() {
|
protected float progress() {
|
||||||
int maxPlayers = Main.instance().getAppliance(PlayerLimit.class).getLimit();
|
return (float) this.getCurrentPlayerCount() / this.getMaxPlayerCount();
|
||||||
int currentPlayers = Bukkit.getOnlinePlayers().size();
|
|
||||||
return (float) currentPlayers / maxPlayers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -39,6 +43,14 @@ public class PlayerCounterBar extends Bar {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BossBar.Overlay overlay() {
|
protected BossBar.Overlay overlay() {
|
||||||
return BossBar.Overlay.NOTCHED_10;
|
return BossBar.Overlay.PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getCurrentPlayerCount() {
|
||||||
|
return Bukkit.getOnlinePlayers().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getMaxPlayerCount() {
|
||||||
|
return Main.instance().getAppliance(PlayerLimit.class).getLimit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.mhsl.craftattack.spawn.appliances.infoBars.bars;
|
package eu.mhsl.craftattack.spawn.appliances.infoBars.bars;
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.appliances.infoBars.Bar;
|
import eu.mhsl.craftattack.spawn.appliances.infoBars.Bar;
|
||||||
|
import eu.mhsl.craftattack.spawn.util.text.ColorUtil;
|
||||||
import net.kyori.adventure.bossbar.BossBar;
|
import net.kyori.adventure.bossbar.BossBar;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
@ -28,21 +29,27 @@ public class TpsBar extends Bar {
|
|||||||
.append(Component.text("er ", NamedTextColor.GRAY))
|
.append(Component.text("er ", NamedTextColor.GRAY))
|
||||||
.append(Component.text("S"))
|
.append(Component.text("S"))
|
||||||
.append(Component.text("econds", NamedTextColor.GRAY))
|
.append(Component.text("econds", NamedTextColor.GRAY))
|
||||||
|
.append(Component.text(": "))
|
||||||
|
.append(Component.text(String.format("%.2f", this.currentTps()), ColorUtil.tpsColor(this.currentTps())))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float progress() {
|
protected float progress() {
|
||||||
return (float) (Bukkit.getTPS()[0] / 20);
|
return this.currentTps() / 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BossBar.Color color() {
|
protected BossBar.Color color() {
|
||||||
return BossBar.Color.YELLOW;
|
return BossBar.Color.BLUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected BossBar.Overlay overlay() {
|
protected BossBar.Overlay overlay() {
|
||||||
return BossBar.Overlay.NOTCHED_20;
|
return BossBar.Overlay.NOTCHED_20;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float currentTps() {
|
||||||
|
return (float) Bukkit.getTPS()[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.util.statistics;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
public class ServerMonitor {
|
||||||
|
public static float getServerMSPT() {
|
||||||
|
long[] times = Bukkit.getServer().getTickTimes();
|
||||||
|
return ((float) Arrays.stream(times).sum() / times.length) * 1.0E-6f;
|
||||||
|
}
|
||||||
|
}
|
@ -15,4 +15,13 @@ public class ColorUtil {
|
|||||||
|
|
||||||
return TextColor.color(Color.getHSBColor(hue / 360, 1f, 1f).getRGB());
|
return TextColor.color(Color.getHSBColor(hue / 360, 1f, 1f).getRGB());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TextColor msptColor(float mspt) {
|
||||||
|
if(mspt > 50) return TextColor.color(255, 0, 0);
|
||||||
|
return ColorUtil.mapGreenToRed(mspt, 25, 60, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TextColor tpsColor(float tps) {
|
||||||
|
return ColorUtil.mapGreenToRed(tps, 15, 20, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package eu.mhsl.craftattack.spawn.util.text;
|
package eu.mhsl.craftattack.spawn.util.text;
|
||||||
|
|
||||||
import eu.mhsl.craftattack.spawn.util.statistics.NetworkMonitor;
|
import eu.mhsl.craftattack.spawn.util.statistics.NetworkMonitor;
|
||||||
|
import eu.mhsl.craftattack.spawn.util.statistics.ServerMonitor;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.ComponentBuilder;
|
import net.kyori.adventure.text.ComponentBuilder;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
@ -12,7 +13,6 @@ import org.bukkit.entity.Player;
|
|||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.lang.management.OperatingSystemMXBean;
|
import java.lang.management.OperatingSystemMXBean;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@ -55,15 +55,12 @@ public class ComponentUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Component getFormattedTickTimes(boolean detailed) {
|
public static Component getFormattedTickTimes(boolean detailed) {
|
||||||
long[] times = Bukkit.getServer().getTickTimes();
|
float mspt = ServerMonitor.getServerMSPT();
|
||||||
float mspt = ((float) Arrays.stream(times).sum() / times.length) * 1.0E-6f;
|
|
||||||
float roundedMspt = Math.round(mspt * 100f) / 100f;
|
float roundedMspt = Math.round(mspt * 100f) / 100f;
|
||||||
int loadPercentage = (int) (Math.min(100, (mspt / 50.0) * 100));
|
int loadPercentage = (int) (Math.min(100, (mspt / 50.0) * 100));
|
||||||
float roundedTPS = Math.round(Bukkit.getTPS()[0] * 100f) / 100f;
|
float roundedTPS = Math.round(Bukkit.getTPS()[0] * 100f) / 100f;
|
||||||
|
|
||||||
TextColor msptColor = ColorUtil.mapGreenToRed(roundedMspt, 0, 50, true);
|
|
||||||
TextColor percentageColor = ColorUtil.mapGreenToRed(loadPercentage, 80, 100, true);
|
TextColor percentageColor = ColorUtil.mapGreenToRed(loadPercentage, 80, 100, true);
|
||||||
TextColor tpsColor = ColorUtil.mapGreenToRed(roundedTPS, 15, 20, false);
|
|
||||||
|
|
||||||
ComponentBuilder<TextComponent, TextComponent.Builder> tickTimes = Component.text()
|
ComponentBuilder<TextComponent, TextComponent.Builder> tickTimes = Component.text()
|
||||||
.append(Component.text("Serverlast: ", NamedTextColor.GRAY))
|
.append(Component.text("Serverlast: ", NamedTextColor.GRAY))
|
||||||
@ -72,12 +69,12 @@ public class ComponentUtil {
|
|||||||
|
|
||||||
if(detailed) {
|
if(detailed) {
|
||||||
tickTimes
|
tickTimes
|
||||||
.append(Component.text(roundedMspt + "mspt", msptColor))
|
.append(Component.text(roundedMspt + "mspt", ColorUtil.msptColor(mspt)))
|
||||||
.append(Component.text(" | ", NamedTextColor.GRAY));
|
.append(Component.text(" | ", NamedTextColor.GRAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
return tickTimes
|
return tickTimes
|
||||||
.append(Component.text(roundedTPS + "tps", tpsColor))
|
.append(Component.text(roundedTPS + "tps", ColorUtil.tpsColor(roundedTPS)))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user