1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
--- a/net/minecraft/server/gui/MinecraftServerGui.java
+++ b/net/minecraft/server/gui/MinecraftServerGui.java
@@ -4,14 +4,15 @@
import com.mojang.logging.LogQueues;
import com.mojang.logging.LogUtils;
import java.awt.BorderLayout;
+import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
-import java.awt.event.ActionEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Collection;
+import java.util.Objects;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.JComponent;
import javax.swing.JFrame;
@@ -25,6 +26,7 @@
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
+import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import net.minecraft.DefaultUncaughtExceptionHandler;
@@ -32,6 +34,7 @@
import org.slf4j.Logger;
public class MinecraftServerGui extends JComponent {
+
private static final Font MONOSPACED = new Font("Monospaced", 0, 12);
private static final Logger LOGGER = LogUtils.getLogger();
private static final String TITLE = "Minecraft server";
@@ -44,29 +47,32 @@
public static MinecraftServerGui showFrameFor(final DedicatedServer server) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (Exception var3) {
+ } catch (Exception exception) {
+ ;
}
- final JFrame jFrame = new JFrame("Minecraft server");
- final MinecraftServerGui minecraftServerGui = new MinecraftServerGui(server);
- jFrame.setDefaultCloseOperation(2);
- jFrame.add(minecraftServerGui);
- jFrame.pack();
- jFrame.setLocationRelativeTo(null);
- jFrame.setVisible(true);
- jFrame.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosing(WindowEvent event) {
- if (!minecraftServerGui.isClosing.getAndSet(true)) {
- jFrame.setTitle("Minecraft server - shutting down!");
+ final JFrame jframe = new JFrame("Minecraft server");
+ final MinecraftServerGui servergui = new MinecraftServerGui(server);
+
+ jframe.setDefaultCloseOperation(2);
+ jframe.add(servergui);
+ jframe.pack();
+ jframe.setLocationRelativeTo((Component) null);
+ jframe.setVisible(true);
+ jframe.addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent windowevent) {
+ if (!servergui.isClosing.getAndSet(true)) {
+ jframe.setTitle("Minecraft server - shutting down!");
server.halt(true);
- minecraftServerGui.runFinalizers();
+ servergui.runFinalizers();
}
+
}
});
- minecraftServerGui.addFinalizer(jFrame::dispose);
- minecraftServerGui.start();
- return minecraftServerGui;
+ Objects.requireNonNull(jframe);
+ servergui.addFinalizer(jframe::dispose);
+ servergui.start();
+ return servergui;
}
private MinecraftServerGui(DedicatedServer server) {
@@ -77,9 +83,10 @@
try {
this.add(this.buildChatPanel(), "Center");
this.add(this.buildInfoPanel(), "West");
- } catch (Exception var3) {
- LOGGER.error("Couldn't build server GUI", (Throwable)var3);
+ } catch (Exception exception) {
+ MinecraftServerGui.LOGGER.error("Couldn't build server GUI", exception);
}
+
}
public void addFinalizer(Runnable finalizer) {
@@ -87,54 +94,61 @@
}
private JComponent buildInfoPanel() {
- JPanel jPanel = new JPanel(new BorderLayout());
- StatsComponent statsComponent = new StatsComponent(this.server);
- this.finalizers.add(statsComponent::close);
- jPanel.add(statsComponent, "North");
- jPanel.add(this.buildPlayerPanel(), "Center");
- jPanel.setBorder(new TitledBorder(new EtchedBorder(), "Stats"));
- return jPanel;
+ JPanel jpanel = new JPanel(new BorderLayout());
+ StatsComponent guistatscomponent = new StatsComponent(this.server);
+ Collection<Runnable> collection = this.finalizers; // CraftBukkit - decompile error
+
+ Objects.requireNonNull(guistatscomponent);
+ collection.add(guistatscomponent::close);
+ jpanel.add(guistatscomponent, "North");
+ jpanel.add(this.buildPlayerPanel(), "Center");
+ jpanel.setBorder(new TitledBorder(new EtchedBorder(), "Stats"));
+ return jpanel;
}
private JComponent buildPlayerPanel() {
- JList<?> jList = new PlayerListComponent(this.server);
- JScrollPane jScrollPane = new JScrollPane(jList, 22, 30);
- jScrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Players"));
- return jScrollPane;
+ JList<?> jlist = new PlayerListComponent(this.server);
+ JScrollPane jscrollpane = new JScrollPane(jlist, 22, 30);
+
+ jscrollpane.setBorder(new TitledBorder(new EtchedBorder(), "Players"));
+ return jscrollpane;
}
private JComponent buildChatPanel() {
- JPanel jPanel = new JPanel(new BorderLayout());
- JTextArea jTextArea = new JTextArea();
- JScrollPane jScrollPane = new JScrollPane(jTextArea, 22, 30);
- jTextArea.setEditable(false);
- jTextArea.setFont(MONOSPACED);
- JTextField jTextField = new JTextField();
- jTextField.addActionListener(actionEvent -> {
- String trimmed = jTextField.getText().trim();
- if (!trimmed.isEmpty()) {
- this.server.handleConsoleInput(trimmed, this.server.createCommandSourceStack());
+ JPanel jpanel = new JPanel(new BorderLayout());
+ JTextArea jtextarea = new JTextArea();
+ JScrollPane jscrollpane = new JScrollPane(jtextarea, 22, 30);
+
+ jtextarea.setEditable(false);
+ jtextarea.setFont(MinecraftServerGui.MONOSPACED);
+ JTextField jtextfield = new JTextField();
+
+ jtextfield.addActionListener((actionevent) -> {
+ String s = jtextfield.getText().trim();
+
+ if (!s.isEmpty()) {
+ this.server.handleConsoleInput(s, this.server.createCommandSourceStack());
}
- jTextField.setText("");
+ jtextfield.setText("");
});
- jTextArea.addFocusListener(new FocusAdapter() {
- @Override
- public void focusGained(FocusEvent event) {
- }
+ jtextarea.addFocusListener(new FocusAdapter() {
+ public void focusGained(FocusEvent focusevent) {}
});
- jPanel.add(jScrollPane, "Center");
- jPanel.add(jTextField, "South");
- jPanel.setBorder(new TitledBorder(new EtchedBorder(), "Log and chat"));
+ jpanel.add(jscrollpane, "Center");
+ jpanel.add(jtextfield, "South");
+ jpanel.setBorder(new TitledBorder(new EtchedBorder(), "Log and chat"));
this.logAppenderThread = new Thread(() -> {
- String string;
- while ((string = LogQueues.getNextLogEvent("ServerGuiConsole")) != null) {
- this.print(jTextArea, jScrollPane, string);
+ String s;
+
+ while ((s = LogQueues.getNextLogEvent("ServerGuiConsole")) != null) {
+ this.print(jtextarea, jscrollpane, s);
}
+
});
- this.logAppenderThread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER));
+ this.logAppenderThread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(MinecraftServerGui.LOGGER));
this.logAppenderThread.setDaemon(true);
- return jPanel;
+ return jpanel;
}
public void start() {
@@ -145,32 +159,38 @@
if (!this.isClosing.getAndSet(true)) {
this.runFinalizers();
}
+
}
void runFinalizers() {
this.finalizers.forEach(Runnable::run);
}
+ private static final java.util.regex.Pattern ANSI = java.util.regex.Pattern.compile("\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]"); // CraftBukkit
public void print(JTextArea textArea, JScrollPane scrollPane, String line) {
if (!SwingUtilities.isEventDispatchThread()) {
- SwingUtilities.invokeLater(() -> this.print(textArea, scrollPane, line));
+ SwingUtilities.invokeLater(() -> {
+ this.print(textArea, scrollPane, line);
+ });
} else {
Document document = textArea.getDocument();
- JScrollBar verticalScrollBar = scrollPane.getVerticalScrollBar();
+ JScrollBar jscrollbar = scrollPane.getVerticalScrollBar();
boolean flag = false;
+
if (scrollPane.getViewport().getView() == textArea) {
- flag = (double)verticalScrollBar.getValue() + verticalScrollBar.getSize().getHeight() + (double)(MONOSPACED.getSize() * 4)
- > (double)verticalScrollBar.getMaximum();
+ flag = (double) jscrollbar.getValue() + jscrollbar.getSize().getHeight() + (double) (MinecraftServerGui.MONOSPACED.getSize() * 4) > (double) jscrollbar.getMaximum();
}
try {
- document.insertString(document.getLength(), line, null);
- } catch (BadLocationException var8) {
+ document.insertString(document.getLength(), ANSI.matcher(line).replaceAll(""), (AttributeSet) null); // CraftBukkit
+ } catch (BadLocationException badlocationexception) {
+ ;
}
if (flag) {
- verticalScrollBar.setValue(Integer.MAX_VALUE);
+ jscrollbar.setValue(Integer.MAX_VALUE);
}
+
}
}
}
|