|
| 1 | +--- a/net/minecraft/server/gui/MinecraftServerGui.java |
| 2 | ++++ b/net/minecraft/server/gui/MinecraftServerGui.java |
| 3 | +@@ -39,6 +_,11 @@ |
| 4 | + private Thread logAppenderThread; |
| 5 | + private final Collection<Runnable> finalizers = Lists.newArrayList(); |
| 6 | + final AtomicBoolean isClosing = new AtomicBoolean(); |
| 7 | ++ // Purpur start - GUI Improvements |
| 8 | ++ private final CommandHistory history = new CommandHistory(); |
| 9 | ++ private String currentCommand = ""; |
| 10 | ++ private int historyIndex = 0; |
| 11 | ++ // Purpur end - GUI Improvements |
| 12 | + |
| 13 | + public static MinecraftServerGui showFrameFor(final DedicatedServer server) { |
| 14 | + try { |
| 15 | +@@ -46,7 +_,7 @@ |
| 16 | + } catch (Exception var3) { |
| 17 | + } |
| 18 | + |
| 19 | +- final JFrame jFrame = new JFrame("Minecraft server"); |
| 20 | ++ final JFrame jFrame = new JFrame("Purpur Minecraft server"); // Purpur - Improve GUI |
| 21 | + final MinecraftServerGui minecraftServerGui = new MinecraftServerGui(server); |
| 22 | + jFrame.setDefaultCloseOperation(2); |
| 23 | + jFrame.add(minecraftServerGui); |
| 24 | +@@ -54,7 +_,7 @@ |
| 25 | + jFrame.setLocationRelativeTo(null); |
| 26 | + jFrame.setVisible(true); |
| 27 | + // Paper start - Improve ServerGUI |
| 28 | +- jFrame.setName("Minecraft server"); |
| 29 | ++ jFrame.setName("Purpur Minecraft server"); // Purpur - Improve GUI |
| 30 | + try { |
| 31 | + jFrame.setIconImage(javax.imageio.ImageIO.read(java.util.Objects.requireNonNull(MinecraftServerGui.class.getClassLoader().getResourceAsStream("logo.png")))); |
| 32 | + } catch (java.io.IOException ignore) { |
| 33 | +@@ -64,7 +_,7 @@ |
| 34 | + @Override |
| 35 | + public void windowClosing(WindowEvent event) { |
| 36 | + if (!minecraftServerGui.isClosing.getAndSet(true)) { |
| 37 | +- jFrame.setTitle("Minecraft server - shutting down!"); |
| 38 | ++ jFrame.setTitle("Purpur Minecraft server - shutting down!"); // Purpur - Improve GUI |
| 39 | + server.halt(true); |
| 40 | + minecraftServerGui.runFinalizers(); |
| 41 | + } |
| 42 | +@@ -112,7 +_,7 @@ |
| 43 | + |
| 44 | + private JComponent buildChatPanel() { |
| 45 | + JPanel jPanel = new JPanel(new BorderLayout()); |
| 46 | +- JTextArea jTextArea = new JTextArea(); |
| 47 | ++ org.purpurmc.purpur.gui.JColorTextPane jTextArea = new org.purpurmc.purpur.gui.JColorTextPane(); // Purpur - GUI Improvements |
| 48 | + JScrollPane jScrollPane = new JScrollPane(jTextArea, 22, 30); |
| 49 | + jTextArea.setEditable(false); |
| 50 | + jTextArea.setFont(MONOSPACED); |
| 51 | +@@ -121,10 +_,43 @@ |
| 52 | + String trimmed = jTextField.getText().trim(); |
| 53 | + if (!trimmed.isEmpty()) { |
| 54 | + this.server.handleConsoleInput(trimmed, this.server.createCommandSourceStack()); |
| 55 | ++ // Purpur start - GUI Improvements |
| 56 | ++ history.add(trimmed); |
| 57 | ++ historyIndex = -1; |
| 58 | ++ // Purpur end - GUI Improvements |
| 59 | + } |
| 60 | + |
| 61 | + jTextField.setText(""); |
| 62 | + }); |
| 63 | ++ // Purpur start - GUI Improvements |
| 64 | ++ jTextField.getInputMap().put(javax.swing.KeyStroke.getKeyStroke("UP"), "up"); |
| 65 | ++ jTextField.getInputMap().put(javax.swing.KeyStroke.getKeyStroke("DOWN"), "down"); |
| 66 | ++ jTextField.getActionMap().put("up", new javax.swing.AbstractAction() { |
| 67 | ++ @Override |
| 68 | ++ public void actionPerformed(java.awt.event.ActionEvent actionEvent) { |
| 69 | ++ if (historyIndex < 0) { |
| 70 | ++ currentCommand = jTextField.getText(); |
| 71 | ++ } |
| 72 | ++ if (historyIndex < history.size() - 1) { |
| 73 | ++ jTextField.setText(history.get(++historyIndex)); |
| 74 | ++ } |
| 75 | ++ } |
| 76 | ++ }); |
| 77 | ++ jTextField.getActionMap().put("down", new javax.swing.AbstractAction() { |
| 78 | ++ @Override |
| 79 | ++ public void actionPerformed(java.awt.event.ActionEvent actionEvent) { |
| 80 | ++ if (historyIndex >= 0) { |
| 81 | ++ if (historyIndex == 0) { |
| 82 | ++ --historyIndex; |
| 83 | ++ jTextField.setText(currentCommand); |
| 84 | ++ } else { |
| 85 | ++ --historyIndex; |
| 86 | ++ jTextField.setText(history.get(historyIndex)); |
| 87 | ++ } |
| 88 | ++ } |
| 89 | ++ } |
| 90 | ++ }); |
| 91 | ++ // Purpur end - GUI Improvements |
| 92 | + jTextArea.addFocusListener(new FocusAdapter() { |
| 93 | + @Override |
| 94 | + public void focusGained(FocusEvent event) { |
| 95 | +@@ -159,7 +_,7 @@ |
| 96 | + } |
| 97 | + |
| 98 | + private static final java.util.regex.Pattern ANSI = java.util.regex.Pattern.compile("\\e\\[[\\d;]*[^\\d;]"); // CraftBukkit // Paper |
| 99 | +- public void print(JTextArea textArea, JScrollPane scrollPane, String line) { |
| 100 | ++ public void print(org.purpurmc.purpur.gui.JColorTextPane textArea, JScrollPane scrollPane, String line) { // Purpur - GUI Improvements |
| 101 | + if (!SwingUtilities.isEventDispatchThread()) { |
| 102 | + SwingUtilities.invokeLater(() -> this.print(textArea, scrollPane, line)); |
| 103 | + } else { |
| 104 | +@@ -170,16 +_,29 @@ |
| 105 | + flag = verticalScrollBar.getValue() + verticalScrollBar.getSize().getHeight() + MONOSPACED.getSize() * 4 > verticalScrollBar.getMaximum(); |
| 106 | + } |
| 107 | + |
| 108 | +- try { |
| 109 | ++ /*try { // Purpur - GUI Improvements |
| 110 | + document.insertString(document.getLength(), MinecraftServerGui.ANSI.matcher(line).replaceAll(""), null); // CraftBukkit |
| 111 | + } catch (BadLocationException var8) { |
| 112 | +- } |
| 113 | ++ }*/ // Purpur - GUI Improvements |
| 114 | ++ textArea.append(line); // Purpur - GUI Improvements |
| 115 | + |
| 116 | + if (flag) { |
| 117 | + verticalScrollBar.setValue(Integer.MAX_VALUE); |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | ++ |
| 122 | ++ // Purpur start - GUI Improvements |
| 123 | ++ public static class CommandHistory extends java.util.LinkedList<String> { |
| 124 | ++ @Override |
| 125 | ++ public boolean add(String command) { |
| 126 | ++ if (size() > 1000) { |
| 127 | ++ remove(); |
| 128 | ++ } |
| 129 | ++ return super.offerFirst(command); |
| 130 | ++ } |
| 131 | ++ } |
| 132 | ++ // Purpur end - GUI Improvements |
| 133 | + |
| 134 | + // Paper start - Add onboarding message for initial server start |
| 135 | + private JComponent buildOnboardingPanel() { |
0 commit comments