2018-01-26 20:26:16 +01:00
|
|
|
package net.knarcraft.serverlauncher.userinterface;
|
|
|
|
|
2018-02-23 21:38:42 +01:00
|
|
|
import net.knarcraft.serverlauncher.Main;
|
2018-01-31 17:40:28 +01:00
|
|
|
import net.knarcraft.serverlauncher.profile.Collection;
|
2018-01-28 16:17:31 +01:00
|
|
|
import net.knarcraft.serverlauncher.server.Server;
|
2018-01-28 19:06:50 +01:00
|
|
|
import net.knarcraft.serverlauncher.profile.Profile;
|
2018-01-28 16:17:31 +01:00
|
|
|
|
2018-01-30 17:14:29 +01:00
|
|
|
import javax.imageio.ImageIO;
|
2018-01-26 20:26:16 +01:00
|
|
|
import javax.swing.*;
|
2018-01-31 17:40:28 +01:00
|
|
|
import java.awt.*;
|
2018-02-04 10:20:58 +01:00
|
|
|
import java.awt.event.*;
|
2018-01-28 19:06:50 +01:00
|
|
|
import java.io.*;
|
2018-01-28 16:17:31 +01:00
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URISyntaxException;
|
2018-01-29 20:14:17 +01:00
|
|
|
import java.util.ArrayList;
|
2018-01-28 19:06:50 +01:00
|
|
|
import java.util.Objects;
|
2018-01-28 16:17:31 +01:00
|
|
|
import java.util.Scanner;
|
2018-01-30 19:35:42 +01:00
|
|
|
import java.util.concurrent.Executors;
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-02-04 10:20:58 +01:00
|
|
|
import static java.awt.Frame.NORMAL;
|
|
|
|
import static javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE;
|
|
|
|
|
2018-01-29 20:14:17 +01:00
|
|
|
/**
|
2018-01-31 23:20:33 +01:00
|
|
|
* Generates a GUI.
|
2018-01-29 20:14:17 +01:00
|
|
|
*
|
2018-02-22 14:12:42 +01:00
|
|
|
* @author Kristian Knarvik <kristian.knarvik@knett.no>
|
|
|
|
* @version 1.0.0
|
|
|
|
* @since 1.0.0
|
2018-01-29 20:14:17 +01:00
|
|
|
*/
|
2018-01-28 16:17:31 +01:00
|
|
|
public class GUI implements ActionListener {
|
2018-01-27 23:34:02 +01:00
|
|
|
|
|
|
|
private JFrame frame;
|
2018-02-22 11:49:12 +01:00
|
|
|
private JTabbedPane tabbedPane;
|
|
|
|
private JTabbedPane serversPane;
|
2018-01-28 16:17:31 +01:00
|
|
|
//Menu
|
|
|
|
private JCheckBoxMenuItem chckbxmntmRunInBackground, chckbxmntmDelayStartup, chckbxmntmDownloadJars; //Options
|
|
|
|
private JMenuItem mntmErrors, mntmSetup, mntmManualUpdate; //Help
|
|
|
|
private JMenuItem mntmRunInBackground, mntmDelayStartup, mntmDownloadJars; //Info/options
|
|
|
|
private JMenuItem mntmAbout, mntmStory; //Info/about
|
|
|
|
//Basic controls
|
|
|
|
private JButton btnStartServer, btnStopServer, addServer, backup, addProfile, delProfile;
|
2018-01-28 19:06:50 +01:00
|
|
|
private JComboBox<String> profiles;
|
2018-01-28 16:17:31 +01:00
|
|
|
private final JLabel lblStatuslabel = new JLabel("Servers are stopped");
|
|
|
|
//Server controls
|
2018-02-01 13:16:25 +01:00
|
|
|
private JComboBox<String> targetServer;
|
|
|
|
private JComboBox<String> targetPlayer;
|
2018-01-28 16:17:31 +01:00
|
|
|
private JButton btnKick, btnBan, btnOp, btnDeop, btnCustomCommand, btnSaveserver, btnReload, btnServerConsoles;
|
|
|
|
private JTextField customCommand;
|
|
|
|
//Text
|
|
|
|
private String setupText;
|
|
|
|
private String runInBackgroundText;
|
|
|
|
private String delayStartupText;
|
|
|
|
private String downloadJarsText;
|
|
|
|
private String aboutText;
|
|
|
|
|
2018-02-01 13:16:25 +01:00
|
|
|
private final ArrayList<String> globalPlayers;
|
2018-02-04 10:20:58 +01:00
|
|
|
private SystemTray tray;
|
|
|
|
private TrayIcon trayIcon;
|
|
|
|
|
2018-01-27 23:34:02 +01:00
|
|
|
/**
|
2018-01-31 23:20:33 +01:00
|
|
|
* Create the application window.
|
2018-01-27 23:34:02 +01:00
|
|
|
*/
|
2018-01-26 20:26:16 +01:00
|
|
|
public GUI() {
|
2018-02-17 23:05:12 +01:00
|
|
|
initialize(440, 170);
|
|
|
|
loadMessages();
|
|
|
|
this.globalPlayers = new ArrayList<>();
|
|
|
|
}
|
|
|
|
|
2018-02-22 11:49:12 +01:00
|
|
|
/**
|
|
|
|
* Creates the application window with a preferred width and height.
|
|
|
|
*
|
|
|
|
* @param width The preferred width
|
|
|
|
* @param height The preferred height
|
|
|
|
*/
|
2018-02-17 23:05:12 +01:00
|
|
|
public GUI(int width, int height) {
|
|
|
|
initialize(width, height);
|
2018-02-05 00:00:51 +01:00
|
|
|
loadMessages();
|
|
|
|
this.globalPlayers = new ArrayList<>();
|
|
|
|
}
|
|
|
|
|
2018-02-22 11:49:12 +01:00
|
|
|
/**
|
|
|
|
* Gets the pane used for server configurations
|
|
|
|
*
|
|
|
|
* @return A JTabbedPane
|
|
|
|
*/
|
2018-02-05 00:00:51 +01:00
|
|
|
public JTabbedPane getPane() {
|
|
|
|
return this.serversPane;
|
|
|
|
}
|
|
|
|
|
2018-02-22 11:49:12 +01:00
|
|
|
/**
|
|
|
|
* Sets the text of the status label.
|
|
|
|
*
|
|
|
|
* @param text The new text
|
|
|
|
*/
|
2018-02-05 00:00:51 +01:00
|
|
|
public void setStatus(String text) {
|
|
|
|
this.lblStatuslabel.setText(text);
|
2018-02-23 21:38:42 +01:00
|
|
|
try (PrintWriter file = new PrintWriter(new FileWriter(Main.getAppDir() + File.separator + "latestrun.log", true))) {
|
|
|
|
file.println(text);
|
|
|
|
} catch (IOException e ) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2018-02-01 13:16:25 +01:00
|
|
|
}
|
|
|
|
|
2018-02-22 11:49:12 +01:00
|
|
|
/**
|
|
|
|
* Adds a player to the global playerlist, and updates the players combo.
|
|
|
|
*
|
|
|
|
* @param name The name of the player to add
|
|
|
|
*/
|
2018-02-01 13:16:25 +01:00
|
|
|
public void addPlayer(String name) {
|
|
|
|
this.globalPlayers.add(name);
|
|
|
|
this.updatePlayers();
|
|
|
|
}
|
|
|
|
|
2018-02-22 11:49:12 +01:00
|
|
|
/**
|
|
|
|
* Removes a player from the global list of players.
|
|
|
|
*
|
|
|
|
* @param name The name of the player to remove.
|
|
|
|
*/
|
2018-02-01 13:16:25 +01:00
|
|
|
public void removePlayer(String name) {
|
|
|
|
for (int i = 0; i < this.globalPlayers.size(); i++) {
|
|
|
|
if (this.globalPlayers.get(i).equals(name)) {
|
|
|
|
this.globalPlayers.remove(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.updatePlayers();
|
|
|
|
}
|
|
|
|
|
2018-02-22 11:49:12 +01:00
|
|
|
/**
|
|
|
|
* Updates the profiles combo.
|
|
|
|
*/
|
2018-02-17 22:04:06 +01:00
|
|
|
public void updateProfiles() {
|
|
|
|
this.profiles.removeAllItems();
|
|
|
|
for (Profile profile : Profile.getProfiles()) {
|
|
|
|
this.profiles.addItem(profile.getName());
|
|
|
|
}
|
2018-01-27 23:34:02 +01:00
|
|
|
}
|
|
|
|
|
2018-02-22 11:49:12 +01:00
|
|
|
/**
|
|
|
|
* Gets the size of the main JFrame
|
|
|
|
*
|
|
|
|
* @return The Dimension of the frame
|
|
|
|
*/
|
2018-02-17 23:05:12 +01:00
|
|
|
public Dimension getSize() {
|
2018-02-18 22:57:39 +01:00
|
|
|
return frame.getContentPane().getSize();
|
2018-02-17 23:05:12 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 00:00:51 +01:00
|
|
|
/**
|
2018-02-22 11:49:12 +01:00
|
|
|
* Updates GUI according to current profile settings.
|
2018-02-05 00:00:51 +01:00
|
|
|
*/
|
2018-02-02 20:09:54 +01:00
|
|
|
public void update() {
|
|
|
|
serversPane.removeAll();
|
2018-02-02 22:02:57 +01:00
|
|
|
for (Collection collection : Profile.getCurrent().getCollections()) {
|
2018-02-02 20:09:54 +01:00
|
|
|
serversPane.addTab(collection.getName(), collection.getServerTab().getPanel());
|
|
|
|
}
|
2018-02-04 10:20:58 +01:00
|
|
|
chckbxmntmRunInBackground.setState(Profile.getCurrent().getRunInBackground());
|
|
|
|
chckbxmntmDelayStartup.setState(Profile.getCurrent().getDelayStartup() > 0);
|
|
|
|
chckbxmntmDownloadJars.setState(Profile.getCurrent().getDownloadJars());
|
2018-02-05 00:00:51 +01:00
|
|
|
this.targetServer.removeAllItems();
|
|
|
|
this.targetServer.addItem("All");
|
|
|
|
for (Collection collection : Profile.getCurrent().getCollections()) {
|
|
|
|
this.targetServer.addItem(collection.getName());
|
|
|
|
}
|
2018-02-02 20:09:54 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 00:00:51 +01:00
|
|
|
/**
|
|
|
|
* Creates the GUI,
|
|
|
|
*/
|
2018-02-17 23:05:12 +01:00
|
|
|
private void initialize(int width, int height) {
|
2018-01-31 21:24:54 +01:00
|
|
|
try {
|
2018-01-26 22:17:36 +01:00
|
|
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
2018-02-05 00:00:51 +01:00
|
|
|
} catch (ClassNotFoundException |
|
|
|
|
UnsupportedLookAndFeelException |
|
|
|
|
InstantiationException |
|
|
|
|
IllegalAccessException e
|
|
|
|
) {
|
2018-01-26 22:17:36 +01:00
|
|
|
e.printStackTrace();
|
2018-01-31 21:24:54 +01:00
|
|
|
}
|
2018-01-26 22:17:36 +01:00
|
|
|
|
2018-01-30 17:14:29 +01:00
|
|
|
frame = new JFrame("Minecraft server launcher");
|
2018-02-04 10:20:58 +01:00
|
|
|
frame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
2018-02-17 23:05:12 +01:00
|
|
|
frame.getContentPane().setPreferredSize(new Dimension(width, height));
|
2018-01-30 17:14:29 +01:00
|
|
|
ImageIcon img;
|
|
|
|
try {
|
|
|
|
img = new ImageIcon(ImageIO.read(GUI.class.getResourceAsStream("/files/GUIIcon.png")));
|
|
|
|
} catch (IOException | IllegalArgumentException e) {
|
|
|
|
img = new ImageIcon("files/GUIIcon.png");
|
|
|
|
}
|
|
|
|
frame.setIconImage(img.getImage());
|
2018-01-26 20:26:16 +01:00
|
|
|
|
2018-01-27 23:34:02 +01:00
|
|
|
JMenuBar menuBar = new JMenuBar();
|
|
|
|
frame.setJMenuBar(menuBar);
|
|
|
|
|
|
|
|
JMenu mnOptions = new JMenu("Options");
|
|
|
|
menuBar.add(mnOptions);
|
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
chckbxmntmRunInBackground = new JCheckBoxMenuItem("Run in background on exit");
|
2018-01-27 23:34:02 +01:00
|
|
|
mnOptions.add(chckbxmntmRunInBackground);
|
2018-01-28 16:17:31 +01:00
|
|
|
chckbxmntmRunInBackground.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
chckbxmntmDelayStartup = new JCheckBoxMenuItem("Delay Startup");
|
2018-01-27 23:34:02 +01:00
|
|
|
mnOptions.add(chckbxmntmDelayStartup);
|
2018-01-28 16:17:31 +01:00
|
|
|
chckbxmntmDelayStartup.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
chckbxmntmDownloadJars = new JCheckBoxMenuItem("Download jars");
|
2018-01-27 23:34:02 +01:00
|
|
|
mnOptions.add(chckbxmntmDownloadJars);
|
2018-01-28 16:17:31 +01:00
|
|
|
chckbxmntmDownloadJars.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
|
|
|
JMenu mnHelp = new JMenu("Help");
|
|
|
|
menuBar.add(mnHelp);
|
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmErrors = new JMenuItem("Errors");
|
2018-01-27 23:34:02 +01:00
|
|
|
mnHelp.add(mntmErrors);
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmErrors.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmSetup = new JMenuItem("Setup");
|
2018-01-27 23:34:02 +01:00
|
|
|
mnHelp.add(mntmSetup);
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmSetup.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmManualUpdate = new JMenuItem("Manual update");
|
2018-01-27 23:34:02 +01:00
|
|
|
mnHelp.add(mntmManualUpdate);
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmManualUpdate.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
|
|
|
JMenu mnInfo = new JMenu("Info");
|
|
|
|
menuBar.add(mnInfo);
|
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
JMenu mnOptionsInfo = new JMenu("Options");
|
|
|
|
mnInfo.add(mnOptionsInfo);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmRunInBackground = new JMenuItem("Run in background on exit");
|
|
|
|
mnOptionsInfo.add(mntmRunInBackground);
|
|
|
|
mntmRunInBackground.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmDelayStartup = new JMenuItem("Delay Startup");
|
|
|
|
mnOptionsInfo.add(mntmDelayStartup);
|
|
|
|
mntmDelayStartup.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmDownloadJars = new JMenuItem("Download jars");
|
|
|
|
mnOptionsInfo.add(mntmDownloadJars);
|
|
|
|
mntmDownloadJars.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
|
|
|
JMenu mnAbout = new JMenu("About");
|
|
|
|
mnInfo.add(mnAbout);
|
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmAbout = new JMenuItem("About");
|
2018-01-27 23:34:02 +01:00
|
|
|
mnAbout.add(mntmAbout);
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmAbout.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmStory = new JMenuItem("Story");
|
2018-01-27 23:34:02 +01:00
|
|
|
mnAbout.add(mntmStory);
|
2018-01-28 16:17:31 +01:00
|
|
|
mntmStory.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-02-22 11:49:12 +01:00
|
|
|
tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
2018-01-27 23:34:02 +01:00
|
|
|
frame.getContentPane().add(tabbedPane);
|
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
JPanel panelBasic = new JPanel();
|
|
|
|
tabbedPane.addTab("Control panel", null, panelBasic, null);
|
2018-01-27 23:34:02 +01:00
|
|
|
SpringLayout sl_panel = new SpringLayout();
|
2018-01-28 16:17:31 +01:00
|
|
|
panelBasic.setLayout(sl_panel);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
|
|
|
JLabel lblBasicControls = new JLabel("Basic controls");
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel.putConstraint(SpringLayout.NORTH, lblBasicControls, 10, SpringLayout.NORTH, panelBasic);
|
|
|
|
panelBasic.add(lblBasicControls);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
btnStartServer = new JButton("Start servers");
|
2018-01-27 23:34:02 +01:00
|
|
|
sl_panel.putConstraint(SpringLayout.WEST, lblBasicControls, 0, SpringLayout.WEST, btnStartServer);
|
2018-01-31 17:40:28 +01:00
|
|
|
sl_panel.putConstraint(SpringLayout.NORTH, btnStartServer, 6, SpringLayout.SOUTH, lblBasicControls);
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel.putConstraint(SpringLayout.WEST, btnStartServer, 10, SpringLayout.WEST, panelBasic);
|
|
|
|
panelBasic.add(btnStartServer);
|
|
|
|
btnStartServer.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
btnStopServer = new JButton("Stop servers");
|
2018-01-27 23:34:02 +01:00
|
|
|
sl_panel.putConstraint(SpringLayout.NORTH, btnStopServer, 0, SpringLayout.NORTH, btnStartServer);
|
|
|
|
sl_panel.putConstraint(SpringLayout.WEST, btnStopServer, 6, SpringLayout.EAST, btnStartServer);
|
2018-01-28 16:17:31 +01:00
|
|
|
panelBasic.add(btnStopServer);
|
|
|
|
btnStopServer.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
|
|
|
JLabel lblProfile = new JLabel("Profile");
|
|
|
|
sl_panel.putConstraint(SpringLayout.NORTH, lblProfile, 6, SpringLayout.SOUTH, btnStartServer);
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel.putConstraint(SpringLayout.WEST, lblProfile, 10, SpringLayout.WEST, panelBasic);
|
|
|
|
panelBasic.add(lblProfile);
|
|
|
|
|
|
|
|
addProfile = new JButton("+");
|
|
|
|
sl_panel.putConstraint(SpringLayout.NORTH, addProfile, 6, SpringLayout.SOUTH, lblProfile);
|
|
|
|
sl_panel.putConstraint(SpringLayout.WEST, addProfile, 10, SpringLayout.WEST, panelBasic);
|
|
|
|
panelBasic.add(addProfile);
|
|
|
|
addProfile.addActionListener(this);
|
|
|
|
|
|
|
|
delProfile = new JButton("-");
|
|
|
|
sl_panel.putConstraint(SpringLayout.NORTH, delProfile, 0, SpringLayout.NORTH, addProfile);
|
|
|
|
sl_panel.putConstraint(SpringLayout.WEST, delProfile, 6, SpringLayout.EAST, addProfile);
|
|
|
|
panelBasic.add(delProfile);
|
|
|
|
delProfile.addActionListener(this);
|
|
|
|
|
2018-01-28 19:06:50 +01:00
|
|
|
profiles = new JComboBox<>();
|
2018-01-31 17:40:28 +01:00
|
|
|
sl_panel.putConstraint(SpringLayout.NORTH, profiles, 0, SpringLayout.NORTH, addProfile);
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel.putConstraint(SpringLayout.WEST, profiles, 6, SpringLayout.EAST, delProfile);
|
|
|
|
sl_panel.putConstraint(SpringLayout.EAST, profiles, 124, SpringLayout.EAST, delProfile);
|
|
|
|
panelBasic.add(profiles);
|
|
|
|
profiles.addActionListener(this);
|
|
|
|
|
2018-01-31 17:40:28 +01:00
|
|
|
sl_panel.putConstraint(SpringLayout.NORTH, lblStatuslabel, 6, SpringLayout.SOUTH, addProfile);
|
|
|
|
sl_panel.putConstraint(SpringLayout.SOUTH, lblStatuslabel, -10, SpringLayout.SOUTH, panelBasic);
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel.putConstraint(SpringLayout.WEST, lblStatuslabel, 10, SpringLayout.WEST, panelBasic);
|
2018-01-31 17:40:28 +01:00
|
|
|
sl_panel.putConstraint(SpringLayout.EAST, lblStatuslabel, -10, SpringLayout.EAST, panelBasic);
|
2018-01-28 16:17:31 +01:00
|
|
|
panelBasic.add(lblStatuslabel);
|
|
|
|
|
|
|
|
addServer = new JButton("Add server");
|
|
|
|
sl_panel.putConstraint(SpringLayout.NORTH, addServer, 0, SpringLayout.NORTH, btnStartServer);
|
|
|
|
sl_panel.putConstraint(SpringLayout.WEST, addServer, 6, SpringLayout.EAST, btnStopServer);
|
|
|
|
panelBasic.add(addServer);
|
|
|
|
addServer.addActionListener(this);
|
|
|
|
|
|
|
|
backup = new JButton("Backup");
|
|
|
|
sl_panel.putConstraint(SpringLayout.NORTH, backup, 0, SpringLayout.NORTH, btnStartServer);
|
|
|
|
sl_panel.putConstraint(SpringLayout.WEST, backup, 6, SpringLayout.EAST, addServer);
|
|
|
|
panelBasic.add(backup);
|
|
|
|
backup.addActionListener(this);
|
|
|
|
|
|
|
|
JPanel controlServers = new JPanel();
|
|
|
|
tabbedPane.addTab("Control servers", null, controlServers, null);
|
2018-01-27 23:34:02 +01:00
|
|
|
SpringLayout sl_panel_1 = new SpringLayout();
|
2018-01-28 16:17:31 +01:00
|
|
|
controlServers.setLayout(sl_panel_1);
|
|
|
|
|
2018-02-01 13:16:25 +01:00
|
|
|
targetServer = new JComboBox<>();
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, targetServer, 10, SpringLayout.NORTH, controlServers);
|
|
|
|
controlServers.add(targetServer);
|
2018-02-20 17:45:30 +01:00
|
|
|
targetServer.addActionListener(this);
|
2018-01-28 16:17:31 +01:00
|
|
|
|
2018-02-01 13:16:25 +01:00
|
|
|
targetPlayer = new JComboBox<>();
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, targetPlayer, 6, SpringLayout.SOUTH, targetServer);
|
|
|
|
targetPlayer.setEditable(true);
|
|
|
|
controlServers.add(targetPlayer);
|
|
|
|
|
|
|
|
btnKick = new JButton("Kick");
|
2018-01-31 12:18:36 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, btnKick, 10, SpringLayout.NORTH, controlServers);
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, btnKick, 6, SpringLayout.EAST, targetServer);
|
2018-01-31 17:40:28 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, btnKick, 104, SpringLayout.WEST, btnKick);
|
2018-01-31 12:18:36 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.SOUTH, targetServer, 0, SpringLayout.SOUTH, btnKick);
|
2018-01-28 16:17:31 +01:00
|
|
|
controlServers.add(btnKick);
|
|
|
|
btnKick.addActionListener(this);
|
|
|
|
|
|
|
|
btnBan = new JButton("Ban");
|
2018-01-31 17:40:28 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, btnBan, 6, SpringLayout.SOUTH, btnKick);
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, btnBan, 6, SpringLayout.EAST, targetPlayer);
|
2018-01-31 17:40:28 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, btnBan, 104, SpringLayout.WEST, btnBan);
|
2018-01-31 12:18:36 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.SOUTH, targetPlayer, 0, SpringLayout.SOUTH, btnBan);
|
2018-01-28 16:17:31 +01:00
|
|
|
controlServers.add(btnBan);
|
|
|
|
btnBan.addActionListener(this);
|
|
|
|
|
|
|
|
btnOp = new JButton("OP");
|
2018-01-31 12:18:36 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, btnOp, 10, SpringLayout.NORTH, controlServers);
|
2018-01-30 23:34:25 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, btnOp, 6, SpringLayout.EAST, btnKick);
|
2018-01-31 12:18:36 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, btnOp, -10, SpringLayout.EAST, controlServers);
|
2018-01-28 16:17:31 +01:00
|
|
|
controlServers.add(btnOp);
|
|
|
|
btnOp.addActionListener(this);
|
|
|
|
|
|
|
|
btnDeop = new JButton("DEOP");
|
2018-01-30 23:34:25 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, btnDeop, 6, SpringLayout.EAST, btnBan);
|
2018-01-31 12:18:36 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, btnDeop, 5, SpringLayout.SOUTH, btnOp);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, btnDeop, -10, SpringLayout.EAST, controlServers);
|
2018-01-28 16:17:31 +01:00
|
|
|
controlServers.add(btnDeop);
|
|
|
|
btnDeop.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
|
|
|
JLabel lblTargetServer = new JLabel("Target server");
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, targetServer, 6, SpringLayout.EAST, lblTargetServer);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, targetServer, 121, SpringLayout.EAST, lblTargetServer);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, lblTargetServer, 10, SpringLayout.NORTH, controlServers);
|
2018-01-31 12:18:36 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.SOUTH, lblTargetServer, 0, SpringLayout.SOUTH, targetServer);
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, lblTargetServer, 10, SpringLayout.WEST, controlServers);
|
|
|
|
controlServers.add(lblTargetServer);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
|
|
|
JLabel lblTargetPlayer = new JLabel("Target player");
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, targetPlayer, 7, SpringLayout.EAST, lblTargetPlayer);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, targetPlayer, 122, SpringLayout.EAST, lblTargetPlayer);
|
2018-01-31 12:18:36 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, lblTargetPlayer, 6, SpringLayout.SOUTH, lblTargetServer);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.SOUTH, lblTargetPlayer, 0, SpringLayout.SOUTH, targetPlayer);
|
2018-01-27 23:34:02 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, lblTargetPlayer, 0, SpringLayout.WEST, lblTargetServer);
|
2018-01-28 16:17:31 +01:00
|
|
|
controlServers.add(lblTargetPlayer);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
btnCustomCommand = new JButton("Custom command");
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, btnCustomCommand, 250, SpringLayout.WEST, controlServers);
|
2018-01-27 23:34:02 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, btnCustomCommand, 0, SpringLayout.EAST, btnOp);
|
2018-01-28 16:17:31 +01:00
|
|
|
controlServers.add(btnCustomCommand);
|
|
|
|
btnCustomCommand.addActionListener(this);
|
2018-02-01 13:16:25 +01:00
|
|
|
frame.getRootPane().setDefaultButton(btnCustomCommand);
|
2018-01-28 16:17:31 +01:00
|
|
|
|
|
|
|
customCommand = new JTextField();
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, customCommand, 10, SpringLayout.WEST, controlServers);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, customCommand, -6, SpringLayout.WEST, btnCustomCommand);
|
2018-01-31 12:18:36 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, btnCustomCommand, 0, SpringLayout.NORTH, customCommand);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.SOUTH, customCommand, 0, SpringLayout.SOUTH, btnCustomCommand);
|
2018-01-28 16:17:31 +01:00
|
|
|
controlServers.add(customCommand);
|
|
|
|
customCommand.setColumns(10);
|
|
|
|
|
|
|
|
btnSaveserver = new JButton("Save server");
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, customCommand, 6, SpringLayout.SOUTH, btnSaveserver);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, btnSaveserver, 6, SpringLayout.SOUTH, btnBan);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, btnSaveserver, 0, SpringLayout.WEST, btnKick);
|
2018-01-31 17:40:28 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, btnSaveserver, 104, SpringLayout.WEST, btnKick);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, btnSaveserver, 104, SpringLayout.WEST, btnKick);
|
2018-01-28 16:17:31 +01:00
|
|
|
controlServers.add(btnSaveserver);
|
|
|
|
btnSaveserver.addActionListener(this);
|
|
|
|
|
|
|
|
btnReload = new JButton("Reload");
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, btnReload, 6, SpringLayout.SOUTH, btnDeop);
|
2018-01-30 23:34:25 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, btnReload, 0, SpringLayout.WEST, btnDeop);
|
2018-01-28 16:17:31 +01:00
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, btnReload, 0, SpringLayout.EAST, btnOp);
|
|
|
|
controlServers.add(btnReload);
|
|
|
|
btnReload.addActionListener(this);
|
|
|
|
|
|
|
|
btnServerConsoles = new JButton("View server consoles");
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.NORTH, btnServerConsoles, 0, SpringLayout.NORTH, btnSaveserver);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.WEST, btnServerConsoles, 0, SpringLayout.WEST, lblTargetServer);
|
|
|
|
sl_panel_1.putConstraint(SpringLayout.EAST, btnServerConsoles, 0, SpringLayout.EAST, targetServer);
|
|
|
|
controlServers.add(btnServerConsoles);
|
|
|
|
btnServerConsoles.addActionListener(this);
|
2018-01-27 23:34:02 +01:00
|
|
|
|
|
|
|
JPanel panel_2 = new JPanel();
|
|
|
|
tabbedPane.addTab("Servers", null, panel_2, null);
|
|
|
|
SpringLayout sl_panel_2 = new SpringLayout();
|
|
|
|
panel_2.setLayout(sl_panel_2);
|
|
|
|
|
|
|
|
JTabbedPane tabbedPane_1 = new JTabbedPane(JTabbedPane.TOP);
|
|
|
|
sl_panel_2.putConstraint(SpringLayout.NORTH, tabbedPane_1, 0, SpringLayout.NORTH, panel_2);
|
|
|
|
sl_panel_2.putConstraint(SpringLayout.WEST, tabbedPane_1, 0, SpringLayout.WEST, panel_2);
|
2018-01-30 23:34:25 +01:00
|
|
|
sl_panel_2.putConstraint(SpringLayout.SOUTH, tabbedPane_1, 0, SpringLayout.SOUTH, panel_2);
|
|
|
|
sl_panel_2.putConstraint(SpringLayout.EAST, tabbedPane_1, 0, SpringLayout.EAST, panel_2);
|
2018-01-27 23:34:02 +01:00
|
|
|
panel_2.add(tabbedPane_1);
|
|
|
|
|
|
|
|
this.serversPane = tabbedPane_1;
|
2018-01-30 19:35:42 +01:00
|
|
|
tabbedPane_1.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
|
2018-01-28 19:06:50 +01:00
|
|
|
|
2018-01-30 23:38:22 +01:00
|
|
|
frame.validate();
|
2018-01-31 17:40:28 +01:00
|
|
|
frame.pack();
|
2018-01-28 19:06:50 +01:00
|
|
|
frame.setVisible(true);
|
2018-02-04 10:20:58 +01:00
|
|
|
tray();
|
2018-02-22 11:49:12 +01:00
|
|
|
updateRunning(false);
|
2018-02-04 10:20:58 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 00:00:51 +01:00
|
|
|
/**
|
|
|
|
* Prepares the system tray if available.
|
|
|
|
*/
|
2018-02-04 10:20:58 +01:00
|
|
|
private void tray() {
|
|
|
|
if (SystemTray.isSupported()) {
|
|
|
|
tray = SystemTray.getSystemTray();
|
|
|
|
Image trayImage = Toolkit.getDefaultToolkit().getImage("files/GUIIcon.png");
|
|
|
|
PopupMenu popup = new PopupMenu();
|
|
|
|
trayIcon = new TrayIcon(trayImage, "Minecraft Server Launcher", popup);
|
|
|
|
trayIcon.setImageAutoSize(true);
|
|
|
|
ActionListener exitListener= e -> {
|
2018-02-20 22:13:57 +01:00
|
|
|
stop();
|
2018-02-17 22:04:06 +01:00
|
|
|
try {
|
|
|
|
Profile.getCurrent().save();
|
|
|
|
} catch (FileNotFoundException e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
2018-02-04 10:20:58 +01:00
|
|
|
System.exit(0);
|
|
|
|
};
|
|
|
|
|
|
|
|
MenuItem restoreItem = new MenuItem("Restore");
|
|
|
|
popup.add(restoreItem);
|
|
|
|
restoreItem.addActionListener(e -> {
|
|
|
|
frame.setExtendedState(NORMAL);
|
|
|
|
tray.remove(trayIcon);
|
|
|
|
frame.setVisible(true);
|
|
|
|
});
|
|
|
|
MenuItem exitItem = new MenuItem("Exit");
|
|
|
|
exitItem.addActionListener(exitListener);
|
|
|
|
popup.add(exitItem);
|
|
|
|
frame.addWindowStateListener(e -> {
|
|
|
|
if (e.getNewState() == NORMAL) {
|
|
|
|
tray.remove(trayIcon);
|
|
|
|
frame.setVisible(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
frame.addWindowListener(new WindowAdapter() {
|
|
|
|
@Override
|
|
|
|
public void windowClosing(WindowEvent e) {
|
|
|
|
if (Profile.getCurrent().getRunInBackground() && SystemTray.isSupported()) {
|
|
|
|
try {
|
|
|
|
tray.add(trayIcon);
|
|
|
|
frame.setVisible(false);
|
|
|
|
} catch (AWTException e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
} else {
|
2018-02-20 22:13:57 +01:00
|
|
|
stop();
|
2018-02-17 22:04:06 +01:00
|
|
|
try {
|
|
|
|
Profile.getCurrent().save();
|
|
|
|
} catch (FileNotFoundException e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
2018-02-04 10:20:58 +01:00
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
trayIcon.addMouseListener(new MouseAdapter() {
|
|
|
|
@Override
|
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
|
if(e.getClickCount() >= 1 && e.getButton() == MouseEvent.BUTTON1){
|
|
|
|
frame.setExtendedState(NORMAL);
|
|
|
|
tray.remove(trayIcon);
|
|
|
|
frame.setVisible(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
frame.addWindowListener(new WindowAdapter() {
|
|
|
|
@Override
|
|
|
|
public void windowClosing(WindowEvent e) {
|
2018-02-17 22:04:06 +01:00
|
|
|
try {
|
|
|
|
Profile.getCurrent().save();
|
|
|
|
} catch (FileNotFoundException e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
2018-02-04 10:20:58 +01:00
|
|
|
stop();
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-01-26 22:17:36 +01:00
|
|
|
}
|
2018-01-27 23:34:02 +01:00
|
|
|
|
2018-02-05 00:00:51 +01:00
|
|
|
/**
|
|
|
|
* Hides the gui to the tray,
|
|
|
|
*/
|
|
|
|
public void hide() {
|
|
|
|
frame.setVisible(false);
|
|
|
|
try {
|
|
|
|
tray.add(trayIcon);
|
|
|
|
} catch (AWTException e) {
|
|
|
|
e.printStackTrace();
|
2018-02-01 13:16:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 16:17:31 +01:00
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
2018-01-30 00:44:03 +01:00
|
|
|
String selectedServerValue = null, selectedPlayerValue = null;
|
|
|
|
Object selectedServer = targetServer.getSelectedItem();
|
|
|
|
if (selectedServer != null) {
|
|
|
|
selectedServerValue = selectedServer.toString();
|
|
|
|
}
|
|
|
|
Object selectedPlayer = targetPlayer.getSelectedItem();
|
|
|
|
if (selectedPlayer != null) {
|
|
|
|
selectedPlayerValue = selectedPlayer.toString();
|
|
|
|
}
|
2018-01-28 16:17:31 +01:00
|
|
|
if (e.getSource() == chckbxmntmRunInBackground) {
|
2018-01-28 19:06:50 +01:00
|
|
|
background();
|
2018-01-28 16:17:31 +01:00
|
|
|
} else if (e.getSource() == chckbxmntmDelayStartup) {
|
2018-01-28 19:06:50 +01:00
|
|
|
delay();
|
2018-01-28 16:17:31 +01:00
|
|
|
} else if (e.getSource() == chckbxmntmDownloadJars) {
|
2018-01-28 19:06:50 +01:00
|
|
|
downloadJars();
|
2018-01-28 16:17:31 +01:00
|
|
|
} else if (e.getSource() == mntmErrors) {
|
|
|
|
goToURL("https://knarcraft.net/Bungeeminecraftserverlauncher/Info/");
|
|
|
|
} else if (e.getSource() == mntmSetup) {
|
2018-02-05 00:00:51 +01:00
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
null,
|
|
|
|
setupText,
|
|
|
|
"Setup",
|
|
|
|
JOptionPane.INFORMATION_MESSAGE
|
|
|
|
);
|
2018-01-28 16:17:31 +01:00
|
|
|
} else if (e.getSource() == mntmManualUpdate) {
|
|
|
|
goToURL("https://knarcraft.net/Downloads/Bungeeminecraftserverlauncher/");
|
|
|
|
} else if (e.getSource() == mntmRunInBackground) {
|
2018-02-05 00:00:51 +01:00
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
null,
|
|
|
|
runInBackgroundText,
|
|
|
|
"Run in background",
|
|
|
|
JOptionPane.INFORMATION_MESSAGE
|
|
|
|
);
|
2018-01-28 16:17:31 +01:00
|
|
|
} else if (e.getSource() == mntmDelayStartup) {
|
2018-02-05 00:00:51 +01:00
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
null,
|
|
|
|
delayStartupText,
|
|
|
|
"Delay startup",
|
|
|
|
JOptionPane.INFORMATION_MESSAGE
|
|
|
|
);
|
2018-01-28 16:17:31 +01:00
|
|
|
} else if (e.getSource() == mntmDownloadJars) {
|
2018-02-05 00:00:51 +01:00
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
null,
|
|
|
|
downloadJarsText,
|
|
|
|
"Download jars",
|
|
|
|
JOptionPane.INFORMATION_MESSAGE
|
|
|
|
);
|
2018-01-28 16:17:31 +01:00
|
|
|
} else if (e.getSource() == mntmAbout) {
|
2018-02-05 00:00:51 +01:00
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
null,
|
|
|
|
aboutText,
|
|
|
|
"About",
|
|
|
|
JOptionPane.INFORMATION_MESSAGE
|
|
|
|
);
|
2018-01-28 16:17:31 +01:00
|
|
|
} else if (e.getSource() == mntmStory) {
|
|
|
|
goToURL("https://knarcraft.net/Bungeeminecraftserverlauncher/Story/");
|
|
|
|
} else if (e.getSource() == btnStartServer) {
|
2018-02-20 22:13:57 +01:00
|
|
|
try {
|
|
|
|
Profile.getCurrent().save();
|
|
|
|
} catch (FileNotFoundException e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
Executors.newSingleThreadExecutor().execute(Server::startServers);
|
2018-01-28 16:17:31 +01:00
|
|
|
} else if (e.getSource() == btnStopServer) {
|
2018-01-28 19:06:50 +01:00
|
|
|
stop();
|
2018-01-28 16:17:31 +01:00
|
|
|
} else if (e.getSource() == addServer) {
|
|
|
|
String serverName = JOptionPane.showInputDialog("Name of server: ");
|
2018-02-02 22:02:57 +01:00
|
|
|
Profile.getCurrent().addCollection(serverName);
|
2018-02-02 20:09:54 +01:00
|
|
|
this.update();
|
2018-02-13 12:21:39 +01:00
|
|
|
Profile.getCurrent().updateConsoles();
|
2018-01-28 16:17:31 +01:00
|
|
|
} else if (e.getSource() == backup) {
|
2018-01-28 19:06:50 +01:00
|
|
|
backup();
|
|
|
|
} else if (e.getSource() == addProfile) {
|
|
|
|
Profile.addProfile(JOptionPane.showInputDialog("Profile name: "));
|
2018-02-17 22:04:06 +01:00
|
|
|
updateProfiles();
|
2018-01-28 19:06:50 +01:00
|
|
|
} else if (e.getSource() == delProfile) {
|
|
|
|
Object selected = profiles.getSelectedItem();
|
|
|
|
if (selected != null) {
|
2018-02-05 00:00:51 +01:00
|
|
|
Profile.removeProfile(selected.toString());
|
2018-02-17 22:04:06 +01:00
|
|
|
updateProfiles();
|
2018-01-28 19:06:50 +01:00
|
|
|
}
|
2018-02-02 22:02:57 +01:00
|
|
|
} else if (e.getSource() == profiles) {
|
2018-02-20 22:13:57 +01:00
|
|
|
try {
|
|
|
|
changeProfile();
|
|
|
|
} catch (FileNotFoundException e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
2018-01-30 00:44:03 +01:00
|
|
|
} else if (e.getSource() == btnKick) {
|
|
|
|
if (selectedServerValue != null && selectedPlayerValue != null) {
|
2018-02-02 22:02:57 +01:00
|
|
|
Profile.getCurrent().sendCommand(selectedServerValue, "kick " + selectedPlayerValue);
|
2018-01-30 00:44:03 +01:00
|
|
|
}
|
|
|
|
} else if (e.getSource() == btnBan) {
|
|
|
|
if (selectedServerValue != null && selectedPlayerValue != null) {
|
2018-02-02 22:02:57 +01:00
|
|
|
Profile.getCurrent().sendCommand(selectedServerValue, "ban " + selectedPlayerValue);
|
2018-01-30 00:44:03 +01:00
|
|
|
}
|
|
|
|
} else if (e.getSource() == btnOp) {
|
|
|
|
if (selectedServerValue != null && selectedPlayerValue != null) {
|
2018-02-02 22:02:57 +01:00
|
|
|
Profile.getCurrent().sendCommand(selectedServerValue, "op " + selectedPlayerValue);
|
2018-01-30 00:44:03 +01:00
|
|
|
}
|
|
|
|
} else if (e.getSource() == btnDeop) {
|
|
|
|
if (selectedServerValue != null && selectedPlayerValue != null) {
|
2018-02-02 22:02:57 +01:00
|
|
|
Profile.getCurrent().sendCommand(selectedServerValue, "deop " + selectedPlayerValue);
|
2018-01-30 00:44:03 +01:00
|
|
|
}
|
|
|
|
} else if (e.getSource() == btnCustomCommand) {
|
|
|
|
if (selectedServerValue != null) {
|
2018-02-02 22:02:57 +01:00
|
|
|
Profile.getCurrent().sendCommand(selectedServerValue, customCommand.getText());
|
2018-02-01 13:16:25 +01:00
|
|
|
customCommand.setText("");
|
2018-01-30 00:44:03 +01:00
|
|
|
}
|
|
|
|
} else if (e.getSource() == btnSaveserver) {
|
|
|
|
if (selectedServerValue != null) {
|
2018-02-02 22:02:57 +01:00
|
|
|
Profile.getCurrent().sendCommand(selectedServerValue, "save-all");
|
2018-01-30 00:44:03 +01:00
|
|
|
}
|
|
|
|
} else if (e.getSource() == btnReload) {
|
|
|
|
if (selectedServerValue != null) {
|
2018-02-02 22:02:57 +01:00
|
|
|
Profile.getCurrent().sendCommand(selectedServerValue, "reload");
|
2018-01-30 00:44:03 +01:00
|
|
|
}
|
|
|
|
} else if (e.getSource() == btnServerConsoles) {
|
2018-01-31 21:24:54 +01:00
|
|
|
ServerConsoles.show();
|
2018-02-20 22:13:57 +01:00
|
|
|
} else if (e.getSource() == targetServer) {
|
|
|
|
updatePlayers();
|
2018-01-28 16:17:31 +01:00
|
|
|
}
|
2018-01-29 20:14:17 +01:00
|
|
|
}
|
|
|
|
|
2018-02-22 11:49:12 +01:00
|
|
|
/**
|
|
|
|
* Updates the GUI components to block a user from doing illegal actions.
|
|
|
|
*
|
|
|
|
* @param running Are the servers currently running?
|
|
|
|
*/
|
|
|
|
public void updateRunning(boolean running) {
|
|
|
|
boolean stopped = !running; //Most gui is only enabled when the server is stopped rather than running.
|
|
|
|
profiles.setEnabled(stopped);
|
|
|
|
addProfile.setEnabled(stopped);
|
|
|
|
delProfile.setEnabled(stopped);
|
|
|
|
btnStartServer.setEnabled(stopped);
|
|
|
|
addServer.setEnabled(stopped);
|
|
|
|
tabbedPane.setEnabledAt(2, stopped);
|
|
|
|
btnStopServer.setEnabled(running);
|
2018-02-20 22:13:57 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 00:00:51 +01:00
|
|
|
/**
|
|
|
|
* Saves the previous profile and loads data from the new profile.
|
|
|
|
*/
|
2018-02-17 22:04:06 +01:00
|
|
|
private void changeProfile() throws FileNotFoundException {
|
2018-02-05 00:00:51 +01:00
|
|
|
Profile.getCurrent().save();
|
2018-02-13 12:21:39 +01:00
|
|
|
Object current = this.profiles.getSelectedItem();
|
2018-02-02 22:02:57 +01:00
|
|
|
if (current != null) {
|
|
|
|
Profile.setCurrent(current.toString());
|
|
|
|
}
|
2018-02-13 12:21:39 +01:00
|
|
|
this.update();
|
|
|
|
Profile.getCurrent().updateConsoles();
|
2018-02-02 22:02:57 +01:00
|
|
|
}
|
|
|
|
|
2018-01-29 20:14:17 +01:00
|
|
|
/**
|
|
|
|
* Stops all servers
|
|
|
|
*/
|
2018-01-28 19:06:50 +01:00
|
|
|
private void stop() {
|
|
|
|
try {
|
2018-02-22 11:49:12 +01:00
|
|
|
setStatus("Servers are stopping...");
|
2018-01-28 19:06:50 +01:00
|
|
|
Server.stop();
|
|
|
|
} catch (IOException e1) {
|
2018-02-05 00:00:51 +01:00
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
null,
|
|
|
|
"Could not stop server.",
|
|
|
|
"Error",
|
|
|
|
JOptionPane.ERROR_MESSAGE
|
|
|
|
);
|
2018-02-13 12:21:39 +01:00
|
|
|
e1.printStackTrace();
|
2018-01-28 19:06:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Asks the user for a delay if checked, and sets the value to the current profile.
|
|
|
|
*/
|
|
|
|
private void delay() {
|
|
|
|
Object selected = profiles.getSelectedItem();
|
|
|
|
if (selected != null) {
|
|
|
|
Profile profile = Profile.getProfile(selected.toString());
|
|
|
|
if (chckbxmntmDelayStartup.isSelected()) {
|
2018-02-05 00:00:51 +01:00
|
|
|
Objects.requireNonNull(profile).setDelayStartup(
|
|
|
|
Integer.parseInt(JOptionPane.showInputDialog("Seconds to delay: "))
|
|
|
|
);
|
2018-01-28 19:06:50 +01:00
|
|
|
} else {
|
|
|
|
Objects.requireNonNull(profile).setDelayStartup(0);
|
|
|
|
}
|
|
|
|
} else {
|
2018-02-05 00:00:51 +01:00
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
null,
|
|
|
|
"No profile selected",
|
|
|
|
"Error",
|
|
|
|
JOptionPane.ERROR_MESSAGE
|
|
|
|
);
|
2018-01-28 19:06:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 20:14:17 +01:00
|
|
|
/**
|
2018-01-31 23:20:33 +01:00
|
|
|
* Saves the runInBackground setting to the current profile.
|
2018-01-29 20:14:17 +01:00
|
|
|
*/
|
2018-01-28 19:06:50 +01:00
|
|
|
private void background() {
|
|
|
|
Object selected = profiles.getSelectedItem();
|
|
|
|
if (selected != null) {
|
|
|
|
Profile profile = Profile.getProfile(selected.toString());
|
|
|
|
Objects.requireNonNull(profile).setRunInBackground(chckbxmntmRunInBackground.isSelected());
|
|
|
|
} else {
|
2018-02-05 00:00:51 +01:00
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
null,
|
|
|
|
"No profile selected",
|
|
|
|
"Error",
|
|
|
|
JOptionPane.ERROR_MESSAGE
|
|
|
|
);
|
2018-01-28 19:06:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 20:14:17 +01:00
|
|
|
/**
|
2018-01-31 23:20:33 +01:00
|
|
|
* Saves the downloadJars setting to the current profile.
|
2018-01-29 20:14:17 +01:00
|
|
|
*/
|
2018-01-28 19:06:50 +01:00
|
|
|
private void downloadJars() {
|
|
|
|
Object selected = profiles.getSelectedItem();
|
|
|
|
if (selected != null) {
|
|
|
|
Profile profile = Profile.getProfile(selected.toString());
|
|
|
|
Objects.requireNonNull(profile).setDownloadJars(chckbxmntmDownloadJars.isSelected());
|
|
|
|
} else {
|
2018-02-05 00:00:51 +01:00
|
|
|
JOptionPane.showMessageDialog(
|
|
|
|
null,
|
|
|
|
"No profile selected",
|
|
|
|
"Error",
|
|
|
|
JOptionPane.ERROR_MESSAGE
|
|
|
|
);
|
2018-01-28 19:06:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 20:14:17 +01:00
|
|
|
/**
|
2018-01-31 23:20:33 +01:00
|
|
|
* Copies all server directories to a folder specified by the user.
|
2018-01-29 20:14:17 +01:00
|
|
|
*/
|
2018-01-28 19:06:50 +01:00
|
|
|
private void backup() {
|
|
|
|
JFileChooser chooser = new JFileChooser();
|
|
|
|
chooser.setCurrentDirectory(new java.io.File("."));
|
|
|
|
chooser.setDialogTitle("Backup folder");
|
|
|
|
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
|
|
|
chooser.setAcceptAllFileFilterUsed(false);
|
|
|
|
|
|
|
|
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
|
|
|
File path = chooser.getSelectedFile();
|
2018-02-02 22:02:57 +01:00
|
|
|
for (Collection collection : Profile.getCurrent().getCollections()) {
|
2018-01-31 17:40:28 +01:00
|
|
|
if (!collection.getServer().getPath().equals("") && collection.getServer().isEnabled()) {
|
|
|
|
String name = collection.getServer().getName();
|
|
|
|
File srcFolder = new File(collection.getServer().getPath());
|
2018-01-28 19:06:50 +01:00
|
|
|
File destFolder = new File(path, name);
|
|
|
|
if (!destFolder.exists()) {
|
|
|
|
if (destFolder.mkdirs()) {
|
|
|
|
try {
|
|
|
|
copyFolder(srcFolder, destFolder);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-22 11:49:12 +01:00
|
|
|
this.setStatus("Backup finished");
|
2018-01-28 19:06:50 +01:00
|
|
|
}
|
|
|
|
|
2018-02-05 00:00:51 +01:00
|
|
|
/**
|
|
|
|
* Updates the list of players currently online on the selected server,
|
|
|
|
*/
|
|
|
|
private void updatePlayers() {
|
|
|
|
String selectedServerValue;
|
|
|
|
Object selectedServer = targetServer.getSelectedItem();
|
|
|
|
if (selectedServer != null) {
|
|
|
|
targetPlayer.removeAllItems();
|
|
|
|
selectedServerValue = selectedServer.toString();
|
|
|
|
if (selectedServerValue.equals("All")) {
|
2018-02-20 17:45:30 +01:00
|
|
|
for (String player : this.globalPlayers) {
|
|
|
|
targetPlayer.addItem(player);
|
|
|
|
}
|
2018-02-05 00:00:51 +01:00
|
|
|
} else {
|
|
|
|
for (String player : Profile.getCurrent().getCollection(selectedServerValue).getServer().getPlayers()) {
|
|
|
|
targetPlayer.addItem(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 20:14:17 +01:00
|
|
|
/**
|
2018-01-31 23:20:33 +01:00
|
|
|
* Opens an url in the user's default application.
|
2018-01-29 20:14:17 +01:00
|
|
|
*
|
|
|
|
* @param url URL to open
|
|
|
|
*/
|
2018-02-02 22:02:57 +01:00
|
|
|
private void goToURL(String url) {
|
2018-01-28 16:17:31 +01:00
|
|
|
java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
|
|
|
|
try {
|
|
|
|
desktop.browse(new URI(url));
|
|
|
|
} catch (URISyntaxException | IOException e1) {
|
|
|
|
e1.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 20:14:17 +01:00
|
|
|
/**
|
2018-01-31 23:20:33 +01:00
|
|
|
* Loads popup messages from a text file.
|
2018-01-29 20:14:17 +01:00
|
|
|
*/
|
2018-01-28 16:17:31 +01:00
|
|
|
private void loadMessages() {
|
2018-01-31 23:20:33 +01:00
|
|
|
Scanner file;
|
|
|
|
try {
|
|
|
|
file = new Scanner(new File("config/menumsg.csv"));
|
2018-01-28 16:17:31 +01:00
|
|
|
} catch (FileNotFoundException e) {
|
2018-01-31 23:20:33 +01:00
|
|
|
file = new Scanner(GUI.class.getResourceAsStream("/config/menumsg.csv"));
|
|
|
|
}
|
|
|
|
while (file.hasNextLine()) {
|
|
|
|
String[] line = file.nextLine().split("=");
|
|
|
|
String content = line[1].replaceAll("_BREAK_", System.getProperty("line.separator"));
|
|
|
|
switch (line[0]) {
|
|
|
|
case "setup":
|
|
|
|
setupText = content;
|
|
|
|
break;
|
|
|
|
case "runinbk":
|
|
|
|
runInBackgroundText = content;
|
|
|
|
break;
|
|
|
|
case "delaystartup":
|
|
|
|
delayStartupText = content;
|
|
|
|
break;
|
|
|
|
case "downloadjars":
|
|
|
|
downloadJarsText = content;
|
|
|
|
break;
|
|
|
|
case "about":
|
|
|
|
aboutText = content;
|
|
|
|
}
|
2018-01-28 16:17:31 +01:00
|
|
|
}
|
2018-01-28 19:06:50 +01:00
|
|
|
}
|
2018-01-28 16:17:31 +01:00
|
|
|
|
2018-01-29 20:14:17 +01:00
|
|
|
/**
|
|
|
|
* Recursivly copies a folder to another location
|
|
|
|
*
|
|
|
|
* @param src The folder to copy
|
|
|
|
* @param dest Target destination
|
|
|
|
* @throws IOException If we can't start a file stream
|
|
|
|
*/
|
2018-01-28 19:06:50 +01:00
|
|
|
private void copyFolder(File src, File dest) throws IOException{
|
|
|
|
if (!src.isDirectory()) {
|
|
|
|
InputStream in = new FileInputStream(src);
|
|
|
|
OutputStream out = new FileOutputStream(dest);
|
|
|
|
byte[] buffer = new byte[1024];
|
|
|
|
int length;
|
|
|
|
while ((length = in.read(buffer)) > 0){
|
|
|
|
out.write(buffer, 0, length);
|
|
|
|
}
|
|
|
|
in.close();
|
|
|
|
out.close();
|
2018-02-22 11:49:12 +01:00
|
|
|
this.setStatus("Copied file " + src);
|
2018-01-28 19:06:50 +01:00
|
|
|
} else {
|
|
|
|
if(!dest.exists()){
|
|
|
|
if (dest.mkdir()) {
|
2018-02-22 11:49:12 +01:00
|
|
|
this.setStatus("Copied directory " + src);
|
2018-01-28 19:06:50 +01:00
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String files[] = src.list();
|
|
|
|
if (files != null) {
|
|
|
|
for (String file : files) {
|
|
|
|
File srcFile = new File(src, file);
|
|
|
|
File destFile = new File(dest, file);
|
|
|
|
copyFolder(srcFile, destFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-28 16:17:31 +01:00
|
|
|
}
|
2018-01-26 20:26:16 +01:00
|
|
|
}
|