mirror of https://github.com/LOOHP/Limbo.git
Added a GUI like Minecraft
This commit is contained in:
parent
18612aa8b4
commit
9d695dd2d4
2
pom.xml
2
pom.xml
|
|
@ -4,7 +4,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>Limbo</groupId>
|
||||
<artifactId>Limbo</artifactId>
|
||||
<version>0.2.0-ALPHA</version>
|
||||
<version>0.2.1-ALPHA</version>
|
||||
<build>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<resources>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.loohp.limbo;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
|
@ -15,6 +16,7 @@ import java.util.Locale;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import com.loohp.limbo.Commands.CommandSender;
|
||||
import com.loohp.limbo.GUI.ConsoleTextOutput;
|
||||
import com.loohp.limbo.Utils.CustomStringUtils;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
|
@ -36,11 +38,21 @@ public class Console implements CommandSender {
|
|||
File logs = new File(dir, fileName);
|
||||
this.logs = new PrintStream(logs);
|
||||
|
||||
System.setIn(in);
|
||||
this.in = in;
|
||||
System.setOut(new ConsoleOutputStream(out, this.logs));
|
||||
System.setIn(in == null ? new ByteArrayInputStream(new byte[0]) : in);
|
||||
this.in = System.in;
|
||||
System.setOut(new ConsoleOutputStream(out == null ? new PrintStream(new PrintStream(new OutputStream() {
|
||||
@Override
|
||||
public void write(int b) {
|
||||
//DO NOTHING
|
||||
}
|
||||
})) : out, this.logs));
|
||||
this.out = System.out;
|
||||
System.setErr(new ConsoleErrorStream(err, this.logs));
|
||||
System.setErr(new ConsoleErrorStream(err == null ? new PrintStream(new PrintStream(new OutputStream() {
|
||||
@Override
|
||||
public void write(int b) {
|
||||
//DO NOTHING
|
||||
}
|
||||
})) : err, this.logs));
|
||||
this.err = System.err;
|
||||
}
|
||||
|
||||
|
|
@ -90,85 +102,97 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public PrintStream printf(Locale l, String format, Object... args) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.printf(l, "[" + date + " INFO]" + format, args);
|
||||
return super.printf(l, "[" + date + " INFO]" + format, args);
|
||||
ConsoleTextOutput.appendText(String.format(l, "[" + date + " Info]" + format, args));
|
||||
logs.printf(l, "[" + date + " Info]" + format, args);
|
||||
return super.printf(l, "[" + date + " Info]" + format, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrintStream printf(String format, Object... args) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.printf("[" + date + " INFO]" + format, args);
|
||||
return super.printf("[" + date + " INFO]" + format, args);
|
||||
ConsoleTextOutput.appendText(String.format("[" + date + " Info]" + format, args));
|
||||
logs.printf("[" + date + " Info]" + format, args);
|
||||
return super.printf("[" + date + " Info]" + format, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println() {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.println("[" + date + " INFO]");
|
||||
super.println("[" + date + " INFO]");
|
||||
ConsoleTextOutput.appendText("[" + date + " Info]", true);
|
||||
logs.println("[" + date + " Info]");
|
||||
super.println("[" + date + " Info]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(boolean x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.println("[" + date + " INFO]" + x);
|
||||
super.println("[" + date + " INFO]" + x);
|
||||
ConsoleTextOutput.appendText("[" + date + " Info] " + x, true);
|
||||
logs.println("[" + date + " Info]" + x);
|
||||
super.println("[" + date + " Info]" + x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(char x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.println("[" + date + " INFO]" + x);
|
||||
super.println("[" + date + " INFO]" + x);
|
||||
ConsoleTextOutput.appendText("[" + date + " Info] " + x, true);
|
||||
logs.println("[" + date + " Info]" + x);
|
||||
super.println("[" + date + " Info]" + x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(char[] x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.println("[" + date + " INFO]" + String.valueOf(x));
|
||||
super.println("[" + date + " INFO]" + String.valueOf(x));
|
||||
ConsoleTextOutput.appendText("[" + date + " Info] " + String.valueOf(x), true);
|
||||
logs.println("[" + date + " Info]" + String.valueOf(x));
|
||||
super.println("[" + date + " Info]" + String.valueOf(x));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(double x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.println("[" + date + " INFO]" + x);
|
||||
super.println("[" + date + " INFO]" + x);
|
||||
ConsoleTextOutput.appendText("[" + date + " Info] " + x, true);
|
||||
logs.println("[" + date + " Info]" + x);
|
||||
super.println("[" + date + " Info]" + x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(float x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.println("[" + date + " INFO]" + x);
|
||||
super.println("[" + date + " INFO]" + x);
|
||||
ConsoleTextOutput.appendText("[" + date + " Info] " + x, true);
|
||||
logs.println("[" + date + " Info]" + x);
|
||||
super.println("[" + date + " Info]" + x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(int x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.println("[" + date + " INFO]" + x);
|
||||
super.println("[" + date + " INFO]" + x);
|
||||
ConsoleTextOutput.appendText("[" + date + " Info] " + x, true);
|
||||
logs.println("[" + date + " Info]" + x);
|
||||
super.println("[" + date + " Info]" + x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(long x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.println("[" + date + " INFO]" + x);
|
||||
super.println("[" + date + " INFO]" + x);
|
||||
ConsoleTextOutput.appendText("[" + date + " Info] " + x, true);
|
||||
logs.println("[" + date + " Info]" + x);
|
||||
super.println("[" + date + " Info]" + x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(Object x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.println("[" + date + " INFO]" + x);
|
||||
super.println("[" + date + " INFO]" + x);
|
||||
ConsoleTextOutput.appendText("[" + date + " Info] " + x, true);
|
||||
logs.println("[" + date + " Info]" + x);
|
||||
super.println("[" + date + " Info]" + x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void println(String string) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
logs.println("[" + date + " INFO] " + string);
|
||||
super.println("[" + date + " INFO] " + string);
|
||||
ConsoleTextOutput.appendText("[" + date + " Info] " + string, true);
|
||||
logs.println("[" + date + " Info] " + string);
|
||||
super.println("[" + date + " Info] " + string);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -184,6 +208,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public PrintStream printf(Locale l, String format, Object... args) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText(String.format(l, "[" + date + " Error]" + format, args));
|
||||
logs.printf(l, "[" + date + " Error]" + format, args);
|
||||
return super.printf(l, "[" + date + " Error]" + format, args);
|
||||
}
|
||||
|
|
@ -191,6 +216,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public PrintStream printf(String format, Object... args) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText(String.format("[" + date + " Error]" + format, args));
|
||||
logs.printf("[" + date + " Error]" + format, args);
|
||||
return super.printf("[" + date + " Error]" + format, args);
|
||||
}
|
||||
|
|
@ -198,6 +224,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public void println() {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText("[" + date + " Error]", true);
|
||||
logs.println("[" + date + " Error]");
|
||||
super.println("[" + date + " Error]");
|
||||
}
|
||||
|
|
@ -205,6 +232,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public void println(boolean x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText("[" + date + " Error] " + x, true);
|
||||
logs.println("[" + date + " Error]" + x);
|
||||
super.println("[" + date + " Error]" + x);
|
||||
}
|
||||
|
|
@ -212,6 +240,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public void println(char x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText("[" + date + " Error] " + x, true);
|
||||
logs.println("[" + date + " Error]" + x);
|
||||
super.println("[" + date + " Error]" + x);
|
||||
}
|
||||
|
|
@ -219,6 +248,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public void println(char[] x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText("[" + date + " Error] " + String.valueOf(x), true);
|
||||
logs.println("[" + date + " Error]" + String.valueOf(x));
|
||||
super.println("[" + date + " Error]" + String.valueOf(x));
|
||||
}
|
||||
|
|
@ -226,6 +256,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public void println(double x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText("[" + date + " Error] " + x, true);
|
||||
logs.println("[" + date + " Error]" + x);
|
||||
super.println("[" + date + " Error]" + x);
|
||||
}
|
||||
|
|
@ -233,6 +264,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public void println(float x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText("[" + date + " Error] " + x, true);
|
||||
logs.println("[" + date + " Error]" + x);
|
||||
super.println("[" + date + " Error]" + x);
|
||||
}
|
||||
|
|
@ -240,6 +272,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public void println(int x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText("[" + date + " Error] " + x, true);
|
||||
logs.println("[" + date + " Error]" + x);
|
||||
super.println("[" + date + " Error]" + x);
|
||||
}
|
||||
|
|
@ -247,6 +280,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public void println(long x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText("[" + date + " Error] " + x, true);
|
||||
logs.println("[" + date + " Error]" + x);
|
||||
super.println("[" + date + " Error]" + x);
|
||||
}
|
||||
|
|
@ -254,6 +288,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public void println(Object x) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText("[" + date + " Error] " + x, true);
|
||||
logs.println("[" + date + " Error]" + x);
|
||||
super.println("[" + date + " Error]" + x);
|
||||
}
|
||||
|
|
@ -261,6 +296,7 @@ public class Console implements CommandSender {
|
|||
@Override
|
||||
public void println(String string) {
|
||||
String date = new SimpleDateFormat("HH':'mm':'ss").format(new Date());
|
||||
ConsoleTextOutput.appendText("[" + date + " Error] " + string, true);
|
||||
logs.println("[" + date + " Error] " + string);
|
||||
super.println("[" + date + " Error] " + string);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package com.loohp.limbo.GUI;
|
||||
|
||||
import com.loohp.limbo.Limbo;
|
||||
|
||||
public class ConsoleTextOutput {
|
||||
|
||||
public static void appendText(String string) {
|
||||
if (!Limbo.noGui) {
|
||||
GUI.textOutput.setText(GUI.textOutput.getText() + string);
|
||||
GUI.scrollPane.getVerticalScrollBar().setValue(GUI.scrollPane.getVerticalScrollBar().getMaximum());
|
||||
}
|
||||
}
|
||||
|
||||
public static void appendText(String string, boolean isWriteLine) {
|
||||
if (isWriteLine) {
|
||||
appendText(string + "\n");
|
||||
} else {
|
||||
appendText(string);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,218 @@
|
|||
package com.loohp.limbo.GUI;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JTextPane;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import com.loohp.limbo.Limbo;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class GUI extends JFrame {
|
||||
|
||||
public static JPanel contentPane;
|
||||
public static JTextField commandInput;
|
||||
public static JButton execCommand;
|
||||
public static JTextPane textOutput;
|
||||
public static JScrollPane scrollPane;
|
||||
public static JLabel consoleLabel;
|
||||
public static JLabel clientLabel;
|
||||
public static JTextPane clientText;
|
||||
public static JScrollPane scrollPane_client;
|
||||
public static JLabel sysLabel;
|
||||
public static JScrollPane scrollPane_sys;
|
||||
public static JTextPane sysText;
|
||||
|
||||
public static List<String> history = new ArrayList<String>();
|
||||
public static int currenthistory = 0;
|
||||
|
||||
public static boolean loadFinish = false;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main() {
|
||||
GUI frame = new GUI();
|
||||
frame.setVisible(true);
|
||||
|
||||
Thread t1 = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SystemInfo.printInfo();
|
||||
}
|
||||
});
|
||||
t1.start();
|
||||
|
||||
loadFinish = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public GUI() {
|
||||
setTitle("Limbo Minecraft Server");
|
||||
addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
Limbo.getInstance().stopServer();
|
||||
}
|
||||
});
|
||||
setBounds(100, 100, 1198, 686);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
GridBagLayout gbl_contentPane = new GridBagLayout();
|
||||
gbl_contentPane.columnWidths = new int[]{243, 10, 36, 111, 0};
|
||||
gbl_contentPane.rowHeights = new int[]{0, 160, 0, 10, 33, 33, 0};
|
||||
gbl_contentPane.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||
gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||
contentPane.setLayout(gbl_contentPane);
|
||||
|
||||
sysLabel = new JLabel("System Information");
|
||||
sysLabel.setFont(new Font("Arial", Font.BOLD, 11));
|
||||
GridBagConstraints gbc_sysLabel = new GridBagConstraints();
|
||||
gbc_sysLabel.fill = GridBagConstraints.BOTH;
|
||||
gbc_sysLabel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_sysLabel.gridx = 0;
|
||||
gbc_sysLabel.gridy = 0;
|
||||
contentPane.add(sysLabel, gbc_sysLabel);
|
||||
|
||||
consoleLabel = new JLabel("Console Output");
|
||||
consoleLabel.setFont(new Font("Arial", Font.BOLD, 11));
|
||||
GridBagConstraints gbc_consoleLabel = new GridBagConstraints();
|
||||
gbc_consoleLabel.anchor = GridBagConstraints.WEST;
|
||||
gbc_consoleLabel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_consoleLabel.gridx = 2;
|
||||
gbc_consoleLabel.gridy = 0;
|
||||
contentPane.add(consoleLabel, gbc_consoleLabel);
|
||||
|
||||
commandInput = new JTextField();
|
||||
commandInput.setToolTipText("Input a command");
|
||||
commandInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyCode() == 10) {
|
||||
String cmd = commandInput.getText();
|
||||
if (!commandInput.getText().equals("")) {
|
||||
history.add(cmd);
|
||||
currenthistory = history.size();
|
||||
}
|
||||
Limbo.getInstance().dispatchCommand(Limbo.getInstance().getConsole(), cmd.trim().replaceAll(" +", " "));
|
||||
commandInput.setText("");
|
||||
} else if (e.getKeyCode() == 38) {
|
||||
currenthistory--;
|
||||
if (currenthistory >= 0) {
|
||||
commandInput.setText(history.get(currenthistory));
|
||||
} else {
|
||||
currenthistory++;
|
||||
}
|
||||
} else if (e.getKeyCode() == 40) {
|
||||
currenthistory++;
|
||||
if (currenthistory < history.size()) {
|
||||
commandInput.setText(history.get(currenthistory));
|
||||
} else {
|
||||
currenthistory--;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
scrollPane_sys = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane_sys = new GridBagConstraints();
|
||||
gbc_scrollPane_sys.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_scrollPane_sys.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane_sys.gridx = 0;
|
||||
gbc_scrollPane_sys.gridy = 1;
|
||||
contentPane.add(scrollPane_sys, gbc_scrollPane_sys);
|
||||
|
||||
sysText = new JTextPane();
|
||||
sysText.setFont(new Font("Consolas", Font.PLAIN, 12));
|
||||
sysText.setEditable(false);
|
||||
scrollPane_sys.setViewportView(sysText);
|
||||
|
||||
clientLabel = new JLabel("Connected Clients");
|
||||
clientLabel.setFont(new Font("Arial", Font.BOLD, 11));
|
||||
GridBagConstraints gbc_clientLabel = new GridBagConstraints();
|
||||
gbc_clientLabel.anchor = GridBagConstraints.WEST;
|
||||
gbc_clientLabel.insets = new Insets(0, 0, 5, 5);
|
||||
gbc_clientLabel.gridx = 0;
|
||||
gbc_clientLabel.gridy = 3;
|
||||
contentPane.add(clientLabel, gbc_clientLabel);
|
||||
|
||||
scrollPane_client = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane_client = new GridBagConstraints();
|
||||
gbc_scrollPane_client.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane_client.gridheight = 2;
|
||||
gbc_scrollPane_client.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_scrollPane_client.gridx = 0;
|
||||
gbc_scrollPane_client.gridy = 4;
|
||||
contentPane.add(scrollPane_client, gbc_scrollPane_client);
|
||||
|
||||
clientText = new JTextPane();
|
||||
scrollPane_client.setViewportView(clientText);
|
||||
clientText.setFont(new Font("Consolas", Font.PLAIN, 12));
|
||||
clientText.setEditable(false);
|
||||
|
||||
scrollPane = new JScrollPane();
|
||||
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
|
||||
gbc_scrollPane.gridheight = 4;
|
||||
gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
|
||||
gbc_scrollPane.gridwidth = 2;
|
||||
gbc_scrollPane.fill = GridBagConstraints.BOTH;
|
||||
gbc_scrollPane.gridx = 2;
|
||||
gbc_scrollPane.gridy = 1;
|
||||
contentPane.add(scrollPane, gbc_scrollPane);
|
||||
|
||||
textOutput = new JTextPane();
|
||||
scrollPane.setViewportView(textOutput);
|
||||
textOutput.setFont(new Font("Consolas", Font.PLAIN, 12));
|
||||
textOutput.setEditable(false);
|
||||
commandInput.setFont(new Font("Tahoma", Font.PLAIN, 19));
|
||||
GridBagConstraints gbc_commandInput = new GridBagConstraints();
|
||||
gbc_commandInput.insets = new Insets(0, 0, 0, 5);
|
||||
gbc_commandInput.fill = GridBagConstraints.BOTH;
|
||||
gbc_commandInput.gridx = 2;
|
||||
gbc_commandInput.gridy = 5;
|
||||
contentPane.add(commandInput, gbc_commandInput);
|
||||
commandInput.setColumns(10);
|
||||
|
||||
execCommand = new JButton("RUN");
|
||||
execCommand.setToolTipText("Execute a command");
|
||||
execCommand.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
String cmd = commandInput.getText();
|
||||
if (!commandInput.getText().equals("")) {
|
||||
history.add(cmd);
|
||||
currenthistory = history.size();
|
||||
}
|
||||
Limbo.getInstance().dispatchCommand(Limbo.getInstance().getConsole(), cmd.trim().replaceAll(" +", " "));
|
||||
commandInput.setText("");
|
||||
}
|
||||
});
|
||||
execCommand.setFont(new Font("Tahoma", Font.PLAIN, 19));
|
||||
GridBagConstraints gbc_execCommand = new GridBagConstraints();
|
||||
gbc_execCommand.fill = GridBagConstraints.BOTH;
|
||||
gbc_execCommand.gridx = 3;
|
||||
gbc_execCommand.gridy = 5;
|
||||
contentPane.add(execCommand, gbc_execCommand);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.loohp.limbo.GUI;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.loohp.limbo.Limbo;
|
||||
|
||||
public class SystemInfo {
|
||||
|
||||
public static void printInfo() {
|
||||
if (!Limbo.noGui) {
|
||||
while (true) {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
|
||||
NumberFormat format = NumberFormat.getInstance();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
long maxMemory = runtime.maxMemory();
|
||||
long allocatedMemory = runtime.totalMemory();
|
||||
long freeMemory = runtime.freeMemory();
|
||||
|
||||
sb.append("Free Memory: " + format.format(freeMemory / 1024 / 1024) + " MB\n");
|
||||
sb.append("Allocated Memory: " + format.format(allocatedMemory / 1024 / 1024) + " MB\n");
|
||||
sb.append("Max Memory: " + format.format(maxMemory / 1024 / 1024) + " MB\n");
|
||||
sb.append("Memory Usage: " + format.format((allocatedMemory - freeMemory) / 1024 / 1024) + "/" + format.format(maxMemory / 1024 / 1024) + " MB (" + Math.round((double) (allocatedMemory - freeMemory) / (double) (maxMemory) * 100) + "%)\n");
|
||||
sb.append("\n");
|
||||
|
||||
try {
|
||||
@SuppressWarnings("restriction")
|
||||
com.sun.management.OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
|
||||
@SuppressWarnings("restriction")
|
||||
double processLoad = operatingSystemMXBean.getProcessCpuLoad();
|
||||
@SuppressWarnings("restriction")
|
||||
double systemLoad = operatingSystemMXBean.getSystemCpuLoad();
|
||||
int processors = runtime.availableProcessors();
|
||||
|
||||
sb.append("Available Processors: " + processors + "\n");
|
||||
sb.append("Process CPU Load: " + Math.round(processLoad * 100) + "%\n");
|
||||
sb.append("System CPU Load: " + Math.round(systemLoad * 100) + "%\n");
|
||||
GUI.sysText.setText(sb.toString());
|
||||
} catch (Exception ignore) {}
|
||||
|
||||
try {TimeUnit.MILLISECONDS.sleep(1000);} catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.loohp.limbo;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
|
|
@ -26,6 +27,7 @@ import org.json.simple.parser.ParseException;
|
|||
import com.loohp.limbo.Commands.CommandSender;
|
||||
import com.loohp.limbo.Events.EventsManager;
|
||||
import com.loohp.limbo.File.ServerProperties;
|
||||
import com.loohp.limbo.GUI.GUI;
|
||||
import com.loohp.limbo.Location.Location;
|
||||
import com.loohp.limbo.Permissions.PermissionsManager;
|
||||
import com.loohp.limbo.Player.Player;
|
||||
|
|
@ -47,8 +49,34 @@ import net.querz.nbt.tag.CompoundTag;
|
|||
public class Limbo {
|
||||
|
||||
private static Limbo instance;
|
||||
public static boolean noGui = false;
|
||||
|
||||
public static void main(String args[]) throws IOException, ParseException, NumberFormatException, ClassNotFoundException {
|
||||
public static void main(String args[]) throws IOException, ParseException, NumberFormatException, ClassNotFoundException, InterruptedException {
|
||||
for (String flag : args) {
|
||||
if (flag.equals("--nogui")) {
|
||||
noGui = true;
|
||||
} else {
|
||||
System.out.println("Accepted flags:");
|
||||
System.out.println(" --nogui ");
|
||||
System.out.println();
|
||||
System.out.println("Press [enter] to quit");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
noGui = true;
|
||||
}
|
||||
if (!noGui) {
|
||||
System.out.println("Launching Server GUI.. Add \"--nogui\" in launch arguments to disable");
|
||||
Thread t1 = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
GUI.main();
|
||||
}
|
||||
});
|
||||
t1.start();
|
||||
}
|
||||
|
||||
new Limbo();
|
||||
}
|
||||
|
||||
|
|
@ -75,9 +103,15 @@ public class Limbo {
|
|||
public AtomicInteger entityIdCount = new AtomicInteger();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Limbo() throws IOException, ParseException, NumberFormatException, ClassNotFoundException {
|
||||
public Limbo() throws IOException, ParseException, NumberFormatException, ClassNotFoundException, InterruptedException {
|
||||
instance = this;
|
||||
|
||||
if (!noGui) {
|
||||
while (!GUI.loadFinish) {
|
||||
TimeUnit.MILLISECONDS.sleep(500);
|
||||
}
|
||||
}
|
||||
|
||||
console = new Console(System.in, System.out, System.err);
|
||||
|
||||
String spName = "server.properties";
|
||||
|
|
|
|||
Loading…
Reference in New Issue