diff --git a/out/production/Minecraft-Server-Launcher/META-INF/MANIFEST.MF b/out/production/Minecraft-Server-Launcher/META-INF/MANIFEST.MF deleted file mode 100644 index 5ee19cb..0000000 --- a/out/production/Minecraft-Server-Launcher/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Main-Class: Main - diff --git a/src/Main.java b/src/Main.java index 579c1d6..d60e468 100644 --- a/src/Main.java +++ b/src/Main.java @@ -37,6 +37,7 @@ class Main { try { String readText = collection.getServer().read(); if (!readText.equals("")) { + //TODO: If the text contains joining or leaving message of player, update playerlist. collection.getServerConsole().output(readText); } } catch (IOException e) { diff --git a/src/net/knarcraft/serverlauncher/profile/Collection.java b/src/net/knarcraft/serverlauncher/profile/Collection.java index 566db32..c1732b1 100644 --- a/src/net/knarcraft/serverlauncher/profile/Collection.java +++ b/src/net/knarcraft/serverlauncher/profile/Collection.java @@ -6,14 +6,17 @@ import net.knarcraft.serverlauncher.userinterface.ServerConsoles; import net.knarcraft.serverlauncher.userinterface.ServerTab; import net.knarcraft.serverlauncher.userinterface.Console; +/** + * Acts as a wrapper for objects necessary for each server. + */ public class Collection { private final Server server; private final ServerTab serverTab; private final Console serverConsole; - private String name; + private final String name; - public Collection(String name) { + Collection(String name) { this.serverTab = new ServerTab(name); this.server = new Server(name, GUI.getGUI(), this.serverTab); this.serverConsole = ServerConsoles.getGUI().addTab(name); diff --git a/src/net/knarcraft/serverlauncher/profile/Profile.java b/src/net/knarcraft/serverlauncher/profile/Profile.java index e6b8644..24f8b6a 100644 --- a/src/net/knarcraft/serverlauncher/profile/Profile.java +++ b/src/net/knarcraft/serverlauncher/profile/Profile.java @@ -10,7 +10,7 @@ import java.io.IOException; import java.util.ArrayList; /** - * Contains all user settings + * Contains all user settings, and a list of servers. * * @author Kristian Knarvik * @version 0.0.0.1 diff --git a/src/net/knarcraft/serverlauncher/server/Server.java b/src/net/knarcraft/serverlauncher/server/Server.java index 598f362..3f1a54e 100644 --- a/src/net/knarcraft/serverlauncher/server/Server.java +++ b/src/net/knarcraft/serverlauncher/server/Server.java @@ -84,9 +84,6 @@ public class Server { return this.process; } - public void toggle() { - this.enabled = !this.enabled; - } public void toggle(boolean value) { this.enabled = value; } @@ -300,8 +297,8 @@ public class Server { * Reads a file from a website. * This is used to find the newest version of the software. * - * @param path The full url of the file to read. - * @return True if successful. False otherwise. + * @param path The full url of the file to read + * @return True if successful. False otherwise */ private static String readFile(String path) throws IOException { URL url = new URL(path); @@ -312,8 +309,8 @@ public class Server { * Downloads a file from a website. * * @param path The full url of the file to download. - * @param outfile The file to save to. - * @return True if successful. False otherwise. + * @param outfile The file to save to + * @return True if successful. False otherwise */ private static boolean downloadFile(String path, Path outfile) { try { @@ -329,9 +326,9 @@ public class Server { /** * Finds a substring between two substrings in a string. * - * @param string The string containing the substrings. - * @param start The substring before the wanted substring. - * @param end The substring after the wanted substring. + * @param string The string containing the substrings + * @param start The substring before the wanted substring + * @param end The substring after the wanted substring * @return The wanted substring. */ private String stringBetween(String string, String start, String end) { @@ -339,6 +336,12 @@ public class Server { return string.substring(startPos, string.indexOf(end, startPos)); } + /** + * Sends a command to this server through its writer. + * + * @param command Command to send to the server + * @throws IOException If write fails + */ public void sendCommand(String command) throws IOException { if (this.process != null && this.writer != null) { this.writer.write(command + "\n"); diff --git a/src/net/knarcraft/serverlauncher/userinterface/GUI.java b/src/net/knarcraft/serverlauncher/userinterface/GUI.java index b9a821d..3c7293f 100644 --- a/src/net/knarcraft/serverlauncher/userinterface/GUI.java +++ b/src/net/knarcraft/serverlauncher/userinterface/GUI.java @@ -20,7 +20,7 @@ import java.util.Scanner; import java.util.concurrent.Executors; /** - * Generates a GUI + * Generates a GUI. * * @author Kristian Knarvik * @version 0.0.0.1 @@ -60,7 +60,7 @@ public class GUI implements ActionListener { //TODO: Update target server list with the list of servers when adding or removing a server. /** - * Create the application. + * Create the application window. */ public GUI() { initialize(); @@ -68,10 +68,6 @@ public class GUI implements ActionListener { gui = this; } - public JFrame getFrame() { - return this.frame; - } - public void setStatus(String text) { this.lblStatuslabel.setText(text); } @@ -92,8 +88,9 @@ public class GUI implements ActionListener { Object selected = profiles.getSelectedItem(); if (selected != null) { return Profile.getProfile(selected.toString()); + } else { + return null; } - return null; } public static GUI getGUI() { @@ -118,9 +115,6 @@ public class GUI implements ActionListener { } - /** - * Initialize the contents of the frame. - */ private void initialize() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); @@ -481,10 +475,11 @@ public class GUI implements ActionListener { } /** - * Reads all combo boxes, updates variables and saves to disk + * Reads all combo boxes, updates variables (and saves to disk). */ private void save() { currentProfile().save(); + //TODO: Save to a text file. } /** @@ -518,7 +513,7 @@ public class GUI implements ActionListener { } /** - * Saves the runInBackground setting to the current profile + * Saves the runInBackground setting to the current profile. */ private void background() { Object selected = profiles.getSelectedItem(); @@ -536,7 +531,7 @@ public class GUI implements ActionListener { } /** - * Saves the downloadJars setting to the current profile + * Saves the downloadJars setting to the current profile. */ private void downloadJars() { Object selected = profiles.getSelectedItem(); @@ -549,7 +544,7 @@ public class GUI implements ActionListener { } /** - * Copies all server directories to a folder specified by the user + * Copies all server directories to a folder specified by the user. */ private void backup() { JFileChooser chooser = new JFileChooser(); @@ -583,7 +578,7 @@ public class GUI implements ActionListener { } /** - * Opens an url in the user's default application + * Opens an url in the user's default application. * * @param url URL to open */ @@ -597,32 +592,34 @@ public class GUI implements ActionListener { } /** - * Loads popup messages from a text file + * Loads popup messages from a text file. */ private void loadMessages() { - try (Scanner in = new Scanner(new File("config/menumsg.csv"))) { - while (in.hasNextLine()) { - String[] line = in.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; - } - } + Scanner file; + try { + file = new Scanner(new File("config/menumsg.csv")); } catch (FileNotFoundException e) { - JOptionPane.showMessageDialog(null, "Messages file could not be read", "Setup", JOptionPane.ERROR_MESSAGE); + 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; + } } } diff --git a/src/net/knarcraft/serverlauncher/userinterface/ServerConsoles.java b/src/net/knarcraft/serverlauncher/userinterface/ServerConsoles.java index 517f049..d826441 100644 --- a/src/net/knarcraft/serverlauncher/userinterface/ServerConsoles.java +++ b/src/net/knarcraft/serverlauncher/userinterface/ServerConsoles.java @@ -5,9 +5,9 @@ import javax.swing.JTabbedPane; import java.awt.BorderLayout; /** - * A parent window for server consoles - * Should be toggled with the "View server consoles" button - * Keeps track of all consoles + * A parent window for server consoles. + * Should be toggled with the "View server consoles" button. + * Keeps track of all consoles. * * @author Kristian Knarvik * @version 0.0.0.1 diff --git a/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java b/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java index ecf9e28..298d2ff 100644 --- a/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java +++ b/src/net/knarcraft/serverlauncher/userinterface/ServerTab.java @@ -8,8 +8,8 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** - * Contains all buttons for configuring a server - * Does some visual stuff by itself, but otherwise reads boxes and stuff + * Contains all buttons for configuring a server. + * Does some visual stuff by itself, but otherwise reads user inputs. * * @author Kristian Knarvik * @version 0.0.0.1 diff --git a/test/ServerTest.java b/test/ServerTest.java deleted file mode 100644 index 5538edd..0000000 --- a/test/ServerTest.java +++ /dev/null @@ -1,65 +0,0 @@ -import javax.naming.ConfigurationException; - -import net.knarcraft.serverlauncher.server.*; -import net.knarcraft.serverlauncher.userinterface.GUI; -import net.knarcraft.serverlauncher.userinterface.ServerTab; - -import java.awt.*; -import java.io.*; - -/** - * A class for testing new and existing features. - * - * @author Kristian Knarvik - * @version 0.0.0.1 - * @since 0.0.0.1 - */ -class ServerTest { - public static void main(String[] args) { - EventQueue.invokeLater(() -> { - try { - setup(); - GUI window = new GUI(); - window.getFrame().setVisible(true); - - - - Server server1 = new Server("Server1", window, new ServerTab("Server1")); - server1.toggle(); - server1.setPath("C:\\Users\\Kristian\\Desktop\\Test"); - server1.setType(ServerType.getServerTypes().get(4)); - server1.setServerVersion("1.12.2"); - server1.setMaxRam("1G"); - Server.startServers(); - - - InputStream stdout = server1.getProcess().getInputStream (); - - BufferedReader reader = new BufferedReader (new InputStreamReader(stdout)); - - OutputStream stdin = server1.getProcess().getOutputStream (); - BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin)); - - String line; - while ((line = reader.readLine ()) != null) { - System.out.println ("Stdout: " + line); - writer.write("stop\n"); - writer.flush(); - } - //writer.close(); - - } catch (Exception e) { - e.printStackTrace(); - } - }); - } - - private static void setup() { - try { - ServerType.loadServerTypes(); - } catch (ConfigurationException e) { - e.printStackTrace(); - System.exit(1); - } - } -}