Improve ServerGUI

- Added logo to server frame
- Show tps in the server stats
This commit is contained in:
AlexProgrammerDE 2020-10-03 08:27:40 +02:00
parent 90c30bbb0b
commit 73deb32107
4 changed files with 70 additions and 4 deletions

View file

@ -1,6 +1,22 @@
--- a/net/minecraft/server/gui/MinecraftServerGui.java
+++ b/net/minecraft/server/gui/MinecraftServerGui.java
@@ -95,8 +95,8 @@
@@ -59,6 +59,15 @@
jframe.pack();
jframe.setLocationRelativeTo((Component) null);
jframe.setVisible(true);
+ jframe.setName("Minecraft server"); // Paper - Improve ServerGUI
+
+ // Paper start - Improve ServerGUI
+ try {
+ jframe.setIconImage(javax.imageio.ImageIO.read(Objects.requireNonNull(MinecraftServerGui.class.getClassLoader().getResourceAsStream("logo.png"))));
+ } catch (java.io.IOException ignore) {
+ }
+ // Paper end - Improve ServerGUI
+
jframe.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowevent) {
if (!servergui.isClosing.getAndSet(true)) {
@@ -95,8 +104,8 @@
private JComponent buildInfoPanel() {
JPanel jpanel = new JPanel(new BorderLayout());
@ -11,7 +27,7 @@
Objects.requireNonNull(guistatscomponent);
collection.add(guistatscomponent::close);
@@ -132,7 +132,7 @@
@@ -132,7 +141,7 @@
jtextfield.setText("");
});
@ -20,7 +36,7 @@
public void focusGained(FocusEvent focusevent) {}
});
jpanel.add(jscrollpane, "Center");
@@ -166,6 +166,7 @@
@@ -166,6 +175,7 @@
this.finalizers.forEach(Runnable::run);
}
@ -28,7 +44,7 @@
public void print(JTextArea textArea, JScrollPane scrollPane, String message) {
if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeLater(() -> {
@@ -181,7 +182,7 @@
@@ -181,7 +191,7 @@
}
try {

View file

@ -0,0 +1,33 @@
--- a/net/minecraft/server/gui/StatsComponent.java
+++ b/net/minecraft/server/gui/StatsComponent.java
@@ -34,10 +34,19 @@
private void tick() {
long l = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
+ // Paper start - Improve ServerGUI
+ double[] tps = org.bukkit.Bukkit.getTPS();
+ String[] tpsAvg = new String[tps.length];
+
+ for ( int g = 0; g < tps.length; g++) {
+ tpsAvg[g] = format( tps[g] );
+ }
this.msgs[0] = "Memory use: " + l / 1024L / 1024L + " mb (" + Runtime.getRuntime().freeMemory() * 100L / Runtime.getRuntime().maxMemory() + "% free)";
this.msgs[1] = "Avg tick: "
+ DECIMAL_FORMAT.format((double)this.server.getAverageTickTimeNanos() / (double)TimeUtil.NANOSECONDS_PER_MILLISECOND)
+ " ms";
+ this.msgs[2] = "TPS from last 1m, 5m, 15m: " + String.join(", ", tpsAvg);
+ // Paper end - Improve ServerGUI
this.values[this.vp++ & 0xFF] = (int)(l * 100L / Runtime.getRuntime().maxMemory());
this.repaint();
}
@@ -66,4 +75,10 @@
public void close() {
this.timer.stop();
}
+
+ // Paper start - Improve ServerGUI
+ private static String format(double tps) {
+ return (( tps > 21.0 ) ? "*" : "") + Math.min(Math.round(tps * 100.0) / 100.0, 20.0); // only print * at 21, we commonly peak to 20.02 as the tick sleep is not accurate enough, stop the noise
+ }
+ // Paper end - Improve ServerGUI
}

View file

@ -58,9 +58,22 @@ public class RAMDetails extends JList<String> {
public void update() {
GraphData data = RAMGraph.DATA.peekLast();
Vector<String> vector = new Vector<>();
// Follows CraftServer#getTPS
double[] tps = new double[] {
server.tps1.getAverage(),
server.tps5.getAverage(),
server.tps15.getAverage()
};
String[] tpsAvg = new String[tps.length];
for ( int g = 0; g < tps.length; g++) {
tpsAvg[g] = format( tps[g] );
}
vector.add("Memory use: " + (data.getUsedMem() / 1024L / 1024L) + " mb (" + (data.getFree() * 100L / data.getMax()) + "% free)");
vector.add("Heap: " + (data.getTotal() / 1024L / 1024L) + " / " + (data.getMax() / 1024L / 1024L) + " mb");
vector.add("Avg tick: " + DECIMAL_FORMAT.format((double)this.server.getAverageTickTimeNanos() / (double) TimeUtil.NANOSECONDS_PER_MILLISECOND) + " ms");
vector.add("TPS from last 1m, 5m, 15m: " + String.join(", ", tpsAvg));
setListData(vector);
}
@ -71,4 +84,8 @@ public class RAMDetails extends JList<String> {
}
return ((double) total / (double) tickTimes.length) * 1.0E-6D;
}
private static String format(double tps) {
return ( ( tps > 21.0 ) ? "*" : "" ) + Math.min( Math.round( tps * 100.0 ) / 100.0, 20.0 );
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB