Merge pull request 'added combined info bar for TPS, MSPT and online player count' (#17) from feature/combinedInfoBar into master
Reviewed-on: #17 Reviewed-by: Elias Müller <elias@elias-mueller.com>
This commit was merged in pull request #17.
This commit is contained in:
commit
b06ba40d16
3 files changed
+110
-3
No files matched your search
+3
-2
@@ -19,7 +19,8 @@ public class InfoBarSetting extends MultiBoolSetting<InfoBarSetting.InfoBarConfi
|
|||||||
public record InfoBarConfiguration(
|
public record InfoBarConfiguration(
|
||||||
@DisplayName("Millisekunden pro Tick") boolean mspt,
|
@DisplayName("Millisekunden pro Tick") boolean mspt,
|
||||||
@DisplayName("Spieler online") boolean playerCounter,
|
@DisplayName("Spieler online") boolean playerCounter,
|
||||||
@DisplayName("Ticks pro Sekunde") boolean tps
|
@DisplayName("Ticks pro Sekunde") boolean tps,
|
||||||
|
@DisplayName("TPS, MSPT & Spieler") boolean tpsMsptPlayerCounter
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -39,7 +40,7 @@ public class InfoBarSetting extends MultiBoolSetting<InfoBarSetting.InfoBarConfi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected InfoBarConfiguration defaultValue() {
|
protected InfoBarConfiguration defaultValue() {
|
||||||
return new InfoBarConfiguration(false, false, false);
|
return new InfoBarConfiguration(false, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+4
-1
@@ -1,5 +1,6 @@
|
|||||||
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars;
|
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars.TpsMsptPlayerCounterBar;
|
||||||
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.settings.Settings;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
import eu.mhsl.craftattack.spawn.core.appliance.Appliance;
|
||||||
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
import eu.mhsl.craftattack.spawn.core.appliance.ApplianceCommand;
|
||||||
@@ -16,7 +17,8 @@ public class InfoBars extends Appliance {
|
|||||||
private final List<Bar> infoBars = List.of(
|
private final List<Bar> infoBars = List.of(
|
||||||
new TpsBar(),
|
new TpsBar(),
|
||||||
new MsptBar(),
|
new MsptBar(),
|
||||||
new PlayerCounterBar()
|
new PlayerCounterBar(),
|
||||||
|
new TpsMsptPlayerCounterBar()
|
||||||
);
|
);
|
||||||
|
|
||||||
public void showAllEnabled(Player player) {
|
public void showAllEnabled(Player player) {
|
||||||
@@ -24,6 +26,7 @@ public class InfoBars extends Appliance {
|
|||||||
this.setVisible(player, MsptBar.name, config.mspt());
|
this.setVisible(player, MsptBar.name, config.mspt());
|
||||||
this.setVisible(player, PlayerCounterBar.name, config.playerCounter());
|
this.setVisible(player, PlayerCounterBar.name, config.playerCounter());
|
||||||
this.setVisible(player, TpsBar.name, config.tps());
|
this.setVisible(player, TpsBar.name, config.tps());
|
||||||
|
this.setVisible(player, TpsMsptPlayerCounterBar.name, config.tpsMsptPlayerCounter());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisible(Player player, String bar, boolean visible) {
|
public void setVisible(Player player, String bar, boolean visible) {
|
||||||
|
|||||||
+103
@@ -0,0 +1,103 @@
|
|||||||
|
package eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.bars;
|
||||||
|
|
||||||
|
import eu.mhsl.craftattack.spawn.common.appliances.metaGameplay.infoBars.Bar;
|
||||||
|
import eu.mhsl.craftattack.spawn.common.appliances.tooling.playerlimit.PlayerLimit;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.Main;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.util.statistics.ServerMonitor;
|
||||||
|
import eu.mhsl.craftattack.spawn.core.util.text.ColorUtil;
|
||||||
|
import net.kyori.adventure.bossbar.BossBar;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
public class TpsMsptPlayerCounterBar extends Bar {
|
||||||
|
public static String name = "serverStats";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Duration refresh() {
|
||||||
|
return Duration.ofSeconds(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Component title() {
|
||||||
|
float tps = this.currentTps();
|
||||||
|
float mspt = this.currentMspt();
|
||||||
|
int players = this.currentPlayerCount();
|
||||||
|
|
||||||
|
Component separator = Component.text(" | ", NamedTextColor.DARK_GRAY);
|
||||||
|
TextColor color = ColorUtil.mapGreenToRed(players, 0, this.getMaxPlayerCount(), true);
|
||||||
|
|
||||||
|
return Component.text()
|
||||||
|
.append(Component.text("TPS: ", NamedTextColor.GRAY))
|
||||||
|
.append(Component.text(String.format("%.2f", tps), ColorUtil.tpsColor(tps)))
|
||||||
|
.append(separator)
|
||||||
|
.append(Component.text("MSPT: ", NamedTextColor.GRAY))
|
||||||
|
.append(Component.text(String.format("%.2f", mspt), ColorUtil.msptColor(mspt)))
|
||||||
|
.append(separator)
|
||||||
|
.append(Component.text("Spieler: ", NamedTextColor.GRAY))
|
||||||
|
.append(Component.text(players, color))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected float progress() {
|
||||||
|
return Math.clamp(this.currentTps() / 20f, 0f, 1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BossBar.Color color() {
|
||||||
|
int severity = Math.max(
|
||||||
|
this.tpsSeverity(),
|
||||||
|
Math.max(this.msptSeverity(), this.playerSeverity())
|
||||||
|
);
|
||||||
|
|
||||||
|
return switch (severity) {
|
||||||
|
case 2 -> BossBar.Color.RED;
|
||||||
|
case 1 -> BossBar.Color.YELLOW;
|
||||||
|
default -> BossBar.Color.GREEN;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected BossBar.Overlay overlay() {
|
||||||
|
return BossBar.Overlay.PROGRESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int tpsSeverity() {
|
||||||
|
float tps = this.currentTps();
|
||||||
|
return tps >= 18 ? 0 : tps >= 15 ? 1 : 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int msptSeverity() {
|
||||||
|
return this.currentMspt() <= 50 ? 0 : 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int playerSeverity() {
|
||||||
|
int freeSlots = this.getMaxPlayerCount() - this.currentPlayerCount();
|
||||||
|
return freeSlots <= 0 ? 2 : freeSlots < 5 ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private float currentTps() {
|
||||||
|
return (float) Bukkit.getTPS()[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
private float currentMspt() {
|
||||||
|
return ServerMonitor.getServerMSPT();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int currentPlayerCount() {
|
||||||
|
return Bukkit.getOnlinePlayers().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getMaxPlayerCount() {
|
||||||
|
return Main.instance().getAppliance(PlayerLimit.class).getLimit();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user