diff --git a/src/net/knarcraft/serverlauncher/profile/Profile.java b/src/net/knarcraft/serverlauncher/profile/Profile.java index dcf7498..07f58e7 100644 --- a/src/net/knarcraft/serverlauncher/profile/Profile.java +++ b/src/net/knarcraft/serverlauncher/profile/Profile.java @@ -1,7 +1,9 @@ package net.knarcraft.serverlauncher.profile; import net.knarcraft.serverlauncher.server.Server; +import net.knarcraft.serverlauncher.server.ServerType; import net.knarcraft.serverlauncher.userinterface.GUI; +import net.knarcraft.serverlauncher.userinterface.ServerTab; import javax.swing.*; import java.io.IOException; @@ -173,4 +175,16 @@ public class Profile { return ""; } } + + public void save(ArrayList serverTabs) { + for (int i = 0; i < this.servers.size(); i++) { + Server server = servers.get(i); + ServerTab serverTab = serverTabs.get(i); + server.setPath(serverTab.getPath()); + server.setMaxRam(serverTab.getMaxRam()); + server.setType(ServerType.getByName(serverTab.getType())); + server.setServerVersion(serverTab.getVersion()); + server.toggle(serverTab.enabled()); + } + } } diff --git a/src/net/knarcraft/serverlauncher/server/Server.java b/src/net/knarcraft/serverlauncher/server/Server.java index a353d25..2fb7eae 100644 --- a/src/net/knarcraft/serverlauncher/server/Server.java +++ b/src/net/knarcraft/serverlauncher/server/Server.java @@ -85,6 +85,9 @@ public class Server { public void toggle() { this.enabled = !this.enabled; } + public void toggle(boolean value) { + this.enabled = value; + } public void setPath(String path) { this.path = path; @@ -140,7 +143,7 @@ public class Server { * Runs all enabled servers with their settings. */ public static void startServers() { - System.out.println("Starting servers."); + GUI.getGUI().setStatus("Starting servers"); for (Server server : GUI.getGUI().currentProfile().getServers()) { if (!server.run()) { GUI.getGUI().setStatus("An error occurred. Start aborted"); @@ -169,7 +172,8 @@ public class Server { "-Djline.terminal=jline.UnsupportedTerminal", "-Dcom.mojang.eula.agree=true", "-jar", - "\"" + this.path + "\\" + this.getType() + "\"" + "\"" + this.path + "\\" + this.getType() + "\"", + "nogui" ); builder.directory(new File(this.path)); builder.redirectErrorStream(true); diff --git a/src/net/knarcraft/serverlauncher/server/ServerType.java b/src/net/knarcraft/serverlauncher/server/ServerType.java index c21ea3b..bafbdec 100644 --- a/src/net/knarcraft/serverlauncher/server/ServerType.java +++ b/src/net/knarcraft/serverlauncher/server/ServerType.java @@ -51,6 +51,15 @@ public class ServerType { return serverTypes; } + public static ServerType getByName(String name) { + for (ServerType serverType : serverTypes) { + if (serverType.getName().equals(name)) { + return serverType; + } + } + return null; + } + /** * Reads valid server types and version from a file, and creates their objects. * diff --git a/src/net/knarcraft/serverlauncher/userinterface/GUI.java b/src/net/knarcraft/serverlauncher/userinterface/GUI.java index 1d06b8c..c8ac54e 100644 --- a/src/net/knarcraft/serverlauncher/userinterface/GUI.java +++ b/src/net/knarcraft/serverlauncher/userinterface/GUI.java @@ -3,6 +3,7 @@ package net.knarcraft.serverlauncher.userinterface; import net.knarcraft.serverlauncher.server.Server; import net.knarcraft.serverlauncher.profile.Profile; +import javax.imageio.ImageIO; import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -94,10 +95,6 @@ public class GUI implements ActionListener { return gui; } - public ArrayList getServerTabs() { - return this.serverTabs; - } - /** * Removes a server's tab, removes it from the list of tabs, and removes the server from Profile.java * @@ -125,10 +122,17 @@ public class GUI implements ActionListener { e.printStackTrace(); } - frame = new JFrame(); + frame = new JFrame("Minecraft server launcher"); frame.setBounds(100, 100, 398, 219); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setResizable(false); + 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()); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { @@ -394,7 +398,6 @@ public class GUI implements ActionListener { if (selectedPlayer != null) { selectedPlayerValue = selectedPlayer.toString(); } - if (e.getSource() == chckbxmntmRunInBackground) { background(); } else if (e.getSource() == chckbxmntmDelayStartup) { @@ -418,7 +421,7 @@ public class GUI implements ActionListener { } else if (e.getSource() == mntmStory) { goToURL("https://knarcraft.net/Bungeeminecraftserverlauncher/Story/"); } else if (e.getSource() == btnStartServer) { - save(); + this.save(); Server.startServers(); } else if (e.getSource() == btnStopServer) { stop(); @@ -427,7 +430,7 @@ public class GUI implements ActionListener { if (!serverName.equals("") && !currentProfile().serverExists(serverName)) { new Server(serverName, this); } else { - JOptionPane.showMessageDialog(null, "A servername must my unique and not empty.", "Error", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(null, "A server name must my unique and not empty.", "Error", JOptionPane.ERROR_MESSAGE); } } else if (e.getSource() == backup) { backup(); @@ -475,8 +478,7 @@ public class GUI implements ActionListener { * Reads all combo boxes, updates variables and saves to disk */ private void save() { - //TODO: Finish save - + currentProfile().save(serverTabs); } /** diff --git a/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java b/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java index 2713d2b..bce77ce 100644 --- a/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java +++ b/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java @@ -7,7 +7,7 @@ import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -class ServerTab implements ActionListener { +public class ServerTab implements ActionListener { private final JComboBox serverTypes; private final JComboBox serverVersions; private final JComboBox maxRam; @@ -16,8 +16,6 @@ class ServerTab implements ActionListener { private final JButton btnBrowse; private final JTextField directory; - //TODO: Add custom input field + update combo boxes on version change. - public ServerTab(String name) { JPanel panel = new JPanel(); GUI.getGUI().getPane().addTab(name, null, panel, null); @@ -101,6 +99,41 @@ class ServerTab implements ActionListener { btnBrowse.addActionListener(this); } + public String getPath() { + return this.directory.getText(); + } + + public String getMaxRam() { + Object selected = this.maxRam.getSelectedItem(); + if (selected != null) { + return selected.toString(); + } else { + return "512M"; + } + } + + public String getType() { + Object selected = this.serverTypes.getSelectedItem(); + if (selected != null) { + return selected.toString(); + } else { + return "Vanilla"; + } + } + + public String getVersion() { + Object selected = this.serverVersions.getSelectedItem(); + if (selected != null) { + return selected.toString(); + } else { + return "Vanilla"; + } + } + + public boolean enabled() { + return this.chckbxEnabled.isSelected(); + } + @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == btnRemoveServer) {