From 68961d9f5e257a352a374db6a71572092940c209 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Sat, 14 Dec 2024 17:35:50 +0100 Subject: [PATCH] net.minecraft.server.gui --- .../server/gui/MinecraftServerGui.java.patch | 93 ++++++++----------- .../server/gui/StatsComponent.java.patch | 12 +-- 2 files changed, 44 insertions(+), 61 deletions(-) rename paper-server/patches/{unapplied => sources}/net/minecraft/server/gui/MinecraftServerGui.java.patch (56%) rename paper-server/patches/{unapplied => sources}/net/minecraft/server/gui/StatsComponent.java.patch (78%) diff --git a/paper-server/patches/unapplied/net/minecraft/server/gui/MinecraftServerGui.java.patch b/paper-server/patches/sources/net/minecraft/server/gui/MinecraftServerGui.java.patch similarity index 56% rename from paper-server/patches/unapplied/net/minecraft/server/gui/MinecraftServerGui.java.patch rename to paper-server/patches/sources/net/minecraft/server/gui/MinecraftServerGui.java.patch index 84332717d5..d78cde0d2c 100644 --- a/paper-server/patches/unapplied/net/minecraft/server/gui/MinecraftServerGui.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/gui/MinecraftServerGui.java.patch @@ -1,44 +1,58 @@ --- a/net/minecraft/server/gui/MinecraftServerGui.java +++ b/net/minecraft/server/gui/MinecraftServerGui.java -@@ -59,6 +59,15 @@ - jframe.pack(); - jframe.setLocationRelativeTo((Component) null); - jframe.setVisible(true); -+ jframe.setName("Minecraft server"); // Paper - Improve ServerGUI -+ +@@ -53,6 +_,13 @@ + jFrame.pack(); + jFrame.setLocationRelativeTo(null); + jFrame.setVisible(true); + // Paper start - Improve ServerGUI ++ jFrame.setName("Minecraft server"); + try { -+ jframe.setIconImage(javax.imageio.ImageIO.read(Objects.requireNonNull(MinecraftServerGui.class.getClassLoader().getResourceAsStream("logo.png")))); ++ jFrame.setIconImage(javax.imageio.ImageIO.read(java.util.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)) { -@@ -81,6 +90,7 @@ + jFrame.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent event) { +@@ -74,6 +_,7 @@ this.setLayout(new BorderLayout()); try { + this.add(this.buildOnboardingPanel(), "North"); // Paper - Add onboarding message for initial server start this.add(this.buildChatPanel(), "Center"); this.add(this.buildInfoPanel(), "West"); - } catch (Exception exception) { -@@ -95,8 +105,8 @@ + } catch (Exception var3) { +@@ -87,7 +_,7 @@ private JComponent buildInfoPanel() { - JPanel jpanel = new JPanel(new BorderLayout()); -- StatsComponent guistatscomponent = new StatsComponent(this.server); -- Collection collection = this.finalizers; -+ com.destroystokyo.paper.gui.GuiStatsComponent guistatscomponent = new com.destroystokyo.paper.gui.GuiStatsComponent(this.server); // Paper - Make GUI graph fancier -+ Collection collection = this.finalizers; // CraftBukkit - decompile error - - Objects.requireNonNull(guistatscomponent); - collection.add(guistatscomponent::close); -@@ -106,6 +116,39 @@ - return jpanel; + JPanel jPanel = new JPanel(new BorderLayout()); +- StatsComponent statsComponent = new StatsComponent(this.server); ++ com.destroystokyo.paper.gui.GuiStatsComponent statsComponent = new com.destroystokyo.paper.gui.GuiStatsComponent(this.server); // Paper - Make GUI graph fancier + this.finalizers.add(statsComponent::close); + jPanel.add(statsComponent, "North"); + jPanel.add(this.buildPlayerPanel(), "Center"); +@@ -150,6 +_,7 @@ + this.finalizers.forEach(Runnable::run); } ++ private static final java.util.regex.Pattern ANSI = java.util.regex.Pattern.compile("\\e\\[[\\d;]*[^\\d;]"); // CraftBukkit // Paper + public void print(JTextArea textArea, JScrollPane scrollPane, String line) { + if (!SwingUtilities.isEventDispatchThread()) { + SwingUtilities.invokeLater(() -> this.print(textArea, scrollPane, line)); +@@ -162,7 +_,7 @@ + } + + try { +- document.insertString(document.getLength(), line, null); ++ document.insertString(document.getLength(), MinecraftServerGui.ANSI.matcher(line).replaceAll(""), null); // CraftBukkit + } catch (BadLocationException var8) { + } + +@@ -171,4 +_,37 @@ + } + } + } ++ + // Paper start - Add onboarding message for initial server start + private JComponent buildOnboardingPanel() { + String onboardingLink = "https://docs.papermc.io/paper/next-steps"; @@ -71,33 +85,4 @@ + return jPanel; + } + // Paper end - Add onboarding message for initial server start -+ - private JComponent buildPlayerPanel() { - JList jlist = new PlayerListComponent(this.server); - JScrollPane jscrollpane = new JScrollPane(jlist, 22, 30); -@@ -132,7 +175,7 @@ - - jtextfield.setText(""); - }); -- jtextarea.addFocusListener(new FocusAdapter(this) { -+ jtextarea.addFocusListener(new FocusAdapter() { // CraftBukkit - decompile error - public void focusGained(FocusEvent focusevent) {} - }); - jpanel.add(jscrollpane, "Center"); -@@ -166,6 +209,7 @@ - this.finalizers.forEach(Runnable::run); - } - -+ private static final java.util.regex.Pattern ANSI = java.util.regex.Pattern.compile("\\e\\[[\\d;]*[^\\d;]"); // CraftBukkit // Paper - public void print(JTextArea textArea, JScrollPane scrollPane, String message) { - if (!SwingUtilities.isEventDispatchThread()) { - SwingUtilities.invokeLater(() -> { -@@ -181,7 +225,7 @@ - } - - try { -- document.insertString(document.getLength(), message, (AttributeSet) null); -+ document.insertString(document.getLength(), MinecraftServerGui.ANSI.matcher(message).replaceAll(""), (AttributeSet) null); // CraftBukkit - } catch (BadLocationException badlocationexception) { - ; - } + } diff --git a/paper-server/patches/unapplied/net/minecraft/server/gui/StatsComponent.java.patch b/paper-server/patches/sources/net/minecraft/server/gui/StatsComponent.java.patch similarity index 78% rename from paper-server/patches/unapplied/net/minecraft/server/gui/StatsComponent.java.patch rename to paper-server/patches/sources/net/minecraft/server/gui/StatsComponent.java.patch index 3fa5e0162c..ab6d2d8cb5 100644 --- a/paper-server/patches/unapplied/net/minecraft/server/gui/StatsComponent.java.patch +++ b/paper-server/patches/sources/net/minecraft/server/gui/StatsComponent.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/server/gui/StatsComponent.java +++ b/net/minecraft/server/gui/StatsComponent.java -@@ -34,10 +34,19 @@ +@@ -34,8 +_,17 @@ private void tick() { long l = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); @@ -8,19 +8,17 @@ + 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] ); ++ 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[1] = "Avg tick: " + DECIMAL_FORMAT.format((double)this.server.getAverageTickTimeNanos() / 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 @@ +@@ -64,4 +_,10 @@ public void close() { this.timer.stop(); }