From fec74bb29548fa675d91aea8db93c9dee048fd28 Mon Sep 17 00:00:00 2001 From: Kristian Knarvik Date: Fri, 26 Jan 2018 20:34:15 +0100 Subject: [PATCH] Add unfinished gui --- src/Main.java | 7 ++++--- .../server/AdvancedServerType.java | 10 ++++----- .../serverlauncher/server/Server.java | 10 ++++----- .../serverlauncher/server/ServerType.java | 21 +++++++++++-------- .../serverlauncher/userinterface/GUI.java | 9 -------- test/ServerTest.java | 2 +- 6 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/Main.java b/src/Main.java index 7ba204f..94c1cf1 100644 --- a/src/Main.java +++ b/src/Main.java @@ -11,14 +11,15 @@ import javax.naming.ConfigurationException; * @version 0.0.0.1 * @since 0.0.0.1 */ -public class Main { +@SuppressWarnings("SpellCheckingInspection") +class Main { public static void main(String[] args) { setup(); - GUI gui = new GUI(); + new GUI(); } - public static void setup() { + private static void setup() { try { ServerType.loadServerTypes(); } catch (ConfigurationException e) { diff --git a/src/net/knarcraft/serverlauncher/server/AdvancedServerType.java b/src/net/knarcraft/serverlauncher/server/AdvancedServerType.java index f2b667d..a9a157a 100644 --- a/src/net/knarcraft/serverlauncher/server/AdvancedServerType.java +++ b/src/net/knarcraft/serverlauncher/server/AdvancedServerType.java @@ -7,11 +7,11 @@ package net.knarcraft.serverlauncher.server; * @version 0.0.0.1 * @since 0.0.0.1 */ -public class AdvancedServerType extends ServerType { - private String versionURL; - private String downloadURLPart; - private String srcStart; - private String srcEnd; +class AdvancedServerType extends ServerType { + private final String versionURL; + private final String downloadURLPart; + private final String srcStart; + private final String srcEnd; public AdvancedServerType(String name, String[] versions, String versionURL, String srcStart, String srcEnd, String downloadURL, String downloadURLPart) { super(name, versions, downloadURL); diff --git a/src/net/knarcraft/serverlauncher/server/Server.java b/src/net/knarcraft/serverlauncher/server/Server.java index 85e348e..29c7813 100644 --- a/src/net/knarcraft/serverlauncher/server/Server.java +++ b/src/net/knarcraft/serverlauncher/server/Server.java @@ -3,7 +3,6 @@ package net.knarcraft.serverlauncher.server; import java.io.*; import java.net.URL; import java.util.Scanner; -import java.nio.file.StandardCopyOption; import java.nio.file.*; import java.util.ArrayList; @@ -18,12 +17,12 @@ import java.util.ArrayList; public class Server { /** Available ram sizes. For GUI dropdown */ private static final String[] ramList = {"512M", "1G", "2G", "3G", "4G", "5G", "6G", "7G", "8G", "9G", "10G", "11G", "12G", "13G", "14G", "15G", "16G"}; - private static ArrayList servers = new ArrayList<>(); + private static final ArrayList servers = new ArrayList<>(); private String name; private String path; private boolean enabled; - private ArrayList playerList; + private final ArrayList playerList; private ServerType type; private String serverVersion; private String maxRam; @@ -129,8 +128,7 @@ public class Server { ProcessBuilder builder = new ProcessBuilder("java", "-Xmx" + this.maxRam, "-Xms512M", "-Djline.terminal=jline.UnsupportedTerminal", "-Dcom.mojang.eula.agree=true", "-jar", "\"" + this.path + "\\" + this.getType() + "\""); builder.directory(new File(this.path)); builder.redirectErrorStream(true); - Process pr = builder.start(); - this.process = pr; + this.process = builder.start(); System.out.println("Success"); } catch (IOException e) { System.out.println("Error"); @@ -228,7 +226,7 @@ public class Server { * This is used to find the newest version of the software. * * @param path The full url of the file to read. - * @return True if successfull. False otherwise. + * @return True if successful. False otherwise. */ private static String readFile(String path) throws IOException { URL url = new URL(path); diff --git a/src/net/knarcraft/serverlauncher/server/ServerType.java b/src/net/knarcraft/serverlauncher/server/ServerType.java index 30b0810..7fa4426 100644 --- a/src/net/knarcraft/serverlauncher/server/ServerType.java +++ b/src/net/knarcraft/serverlauncher/server/ServerType.java @@ -7,7 +7,7 @@ import java.util.ArrayList; import java.util.Scanner; /** - * Contains the bare minimum to be a functional servertype. + * Contains the bare minimum to be a functional server type. * * @author Kristian Knarvik * @version 0.0.0.1 @@ -17,9 +17,9 @@ public class ServerType { private final String name; private final String[] versions; private final String downloadURL; - private static ArrayList serverTypes = new ArrayList<>(); + private static final ArrayList serverTypes = new ArrayList<>(); - public ServerType(String name, String[] versions, String downloadURL) { + ServerType(String name, String[] versions, String downloadURL) { this.name = name; this.versions = versions; this.downloadURL = downloadURL; @@ -59,12 +59,15 @@ public class ServerType { } else { ver = new String[]{str[1]}; } - if (len == 7) { - new AdvancedServerType(str[0], ver, str[2], str[3], str[4], str[5], str[6]); - } else if (len == 3) { - new ServerType(str[0], ver, str[2]); - } else { - throw new ConfigurationException("Error: Configuration file invalid."); + switch (len) { + case 7: + new AdvancedServerType(str[0], ver, str[2], str[3], str[4], str[5], str[6]); + break; + case 3: + new ServerType(str[0], ver, str[2]); + break; + default: + throw new ConfigurationException("Error: Configuration file invalid."); } } } catch (FileNotFoundException e) { diff --git a/src/net/knarcraft/serverlauncher/userinterface/GUI.java b/src/net/knarcraft/serverlauncher/userinterface/GUI.java index 5a8e225..19239ae 100644 --- a/src/net/knarcraft/serverlauncher/userinterface/GUI.java +++ b/src/net/knarcraft/serverlauncher/userinterface/GUI.java @@ -84,13 +84,4 @@ public class GUI { Insets insets = frame.getInsets(); frame.setSize(450 + 2 * insets.left, 170 + insets.top + insets.bottom); } - - protected JComponent makeTextPanel(String text) { - JPanel panel = new JPanel(false); - JLabel filler = new JLabel(text); - filler.setHorizontalAlignment(JLabel.CENTER); - panel.setLayout(new GridLayout(1, 1)); - panel.add(filler); - return panel; - } } diff --git a/test/ServerTest.java b/test/ServerTest.java index 8e6fd38..75ec2c6 100644 --- a/test/ServerTest.java +++ b/test/ServerTest.java @@ -11,7 +11,7 @@ import java.io.*; * @version 0.0.0.1 * @since 0.0.0.1 */ -public class ServerTest { +class ServerTest { public static void main(String[] args) throws IOException { try { ServerType.loadServerTypes();