This commit is contained in:
Kristian Knarvik 2018-01-31 23:20:33 +01:00
parent 2591f3ed05
commit a59c5f904a
9 changed files with 60 additions and 124 deletions

View File

@ -1,3 +0,0 @@
Manifest-Version: 1.0
Main-Class: Main

View File

@ -37,6 +37,7 @@ class Main {
try { try {
String readText = collection.getServer().read(); String readText = collection.getServer().read();
if (!readText.equals("")) { if (!readText.equals("")) {
//TODO: If the text contains joining or leaving message of player, update playerlist.
collection.getServerConsole().output(readText); collection.getServerConsole().output(readText);
} }
} catch (IOException e) { } catch (IOException e) {

View File

@ -6,14 +6,17 @@ import net.knarcraft.serverlauncher.userinterface.ServerConsoles;
import net.knarcraft.serverlauncher.userinterface.ServerTab; import net.knarcraft.serverlauncher.userinterface.ServerTab;
import net.knarcraft.serverlauncher.userinterface.Console; import net.knarcraft.serverlauncher.userinterface.Console;
/**
* Acts as a wrapper for objects necessary for each server.
*/
public class Collection { public class Collection {
private final Server server; private final Server server;
private final ServerTab serverTab; private final ServerTab serverTab;
private final Console serverConsole; private final Console serverConsole;
private String name; private final String name;
public Collection(String name) { Collection(String name) {
this.serverTab = new ServerTab(name); this.serverTab = new ServerTab(name);
this.server = new Server(name, GUI.getGUI(), this.serverTab); this.server = new Server(name, GUI.getGUI(), this.serverTab);
this.serverConsole = ServerConsoles.getGUI().addTab(name); this.serverConsole = ServerConsoles.getGUI().addTab(name);

View File

@ -10,7 +10,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
* Contains all user settings * Contains all user settings, and a list of servers.
* *
* @author Kristian Knarvik <kristian.knarvik@knett.no> * @author Kristian Knarvik <kristian.knarvik@knett.no>
* @version 0.0.0.1 * @version 0.0.0.1

View File

@ -84,9 +84,6 @@ public class Server {
return this.process; return this.process;
} }
public void toggle() {
this.enabled = !this.enabled;
}
public void toggle(boolean value) { public void toggle(boolean value) {
this.enabled = value; this.enabled = value;
} }
@ -300,8 +297,8 @@ public class Server {
* Reads a file from a website. * Reads a file from a website.
* This is used to find the newest version of the software. * This is used to find the newest version of the software.
* *
* @param path The full url of the file to read. * @param path The full url of the file to read
* @return True if successful. False otherwise. * @return True if successful. False otherwise
*/ */
private static String readFile(String path) throws IOException { private static String readFile(String path) throws IOException {
URL url = new URL(path); URL url = new URL(path);
@ -312,8 +309,8 @@ public class Server {
* Downloads a file from a website. * Downloads a file from a website.
* *
* @param path The full url of the file to download. * @param path The full url of the file to download.
* @param outfile The file to save to. * @param outfile The file to save to
* @return True if successful. False otherwise. * @return True if successful. False otherwise
*/ */
private static boolean downloadFile(String path, Path outfile) { private static boolean downloadFile(String path, Path outfile) {
try { try {
@ -329,9 +326,9 @@ public class Server {
/** /**
* Finds a substring between two substrings in a string. * Finds a substring between two substrings in a string.
* *
* @param string The string containing the substrings. * @param string The string containing the substrings
* @param start The substring before the wanted substring. * @param start The substring before the wanted substring
* @param end The substring after the wanted substring. * @param end The substring after the wanted substring
* @return The wanted substring. * @return The wanted substring.
*/ */
private String stringBetween(String string, String start, String end) { private String stringBetween(String string, String start, String end) {
@ -339,6 +336,12 @@ public class Server {
return string.substring(startPos, string.indexOf(end, startPos)); 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 { public void sendCommand(String command) throws IOException {
if (this.process != null && this.writer != null) { if (this.process != null && this.writer != null) {
this.writer.write(command + "\n"); this.writer.write(command + "\n");

View File

@ -20,7 +20,7 @@ import java.util.Scanner;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
/** /**
* Generates a GUI * Generates a GUI.
* *
* @author Kristian Knarvik <kristian.knarvik@knett.no> * @author Kristian Knarvik <kristian.knarvik@knett.no>
* @version 0.0.0.1 * @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. //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() { public GUI() {
initialize(); initialize();
@ -68,10 +68,6 @@ public class GUI implements ActionListener {
gui = this; gui = this;
} }
public JFrame getFrame() {
return this.frame;
}
public void setStatus(String text) { public void setStatus(String text) {
this.lblStatuslabel.setText(text); this.lblStatuslabel.setText(text);
} }
@ -92,8 +88,9 @@ public class GUI implements ActionListener {
Object selected = profiles.getSelectedItem(); Object selected = profiles.getSelectedItem();
if (selected != null) { if (selected != null) {
return Profile.getProfile(selected.toString()); return Profile.getProfile(selected.toString());
} else {
return null;
} }
return null;
} }
public static GUI getGUI() { public static GUI getGUI() {
@ -118,9 +115,6 @@ public class GUI implements ActionListener {
} }
/**
* Initialize the contents of the frame.
*/
private void initialize() { private void initialize() {
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 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() { private void save() {
currentProfile().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() { private void background() {
Object selected = profiles.getSelectedItem(); 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() { private void downloadJars() {
Object selected = profiles.getSelectedItem(); 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() { private void backup() {
JFileChooser chooser = new JFileChooser(); 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 * @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() { private void loadMessages() {
try (Scanner in = new Scanner(new File("config/menumsg.csv"))) { Scanner file;
while (in.hasNextLine()) { try {
String[] line = in.nextLine().split("="); file = new Scanner(new File("config/menumsg.csv"));
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;
}
}
} catch (FileNotFoundException e) { } 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;
}
} }
} }

View File

@ -5,9 +5,9 @@ import javax.swing.JTabbedPane;
import java.awt.BorderLayout; import java.awt.BorderLayout;
/** /**
* A parent window for server consoles * A parent window for server consoles.
* Should be toggled with the "View server consoles" button * Should be toggled with the "View server consoles" button.
* Keeps track of all consoles * Keeps track of all consoles.
* *
* @author Kristian Knarvik <kristian.knarvik@knett.no> * @author Kristian Knarvik <kristian.knarvik@knett.no>
* @version 0.0.0.1 * @version 0.0.0.1

View File

@ -8,8 +8,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
/** /**
* Contains all buttons for configuring a server * Contains all buttons for configuring a server.
* Does some visual stuff by itself, but otherwise reads boxes and stuff * Does some visual stuff by itself, but otherwise reads user inputs.
* *
* @author Kristian Knarvik <kristian.knarvik@knett.no> * @author Kristian Knarvik <kristian.knarvik@knett.no>
* @version 0.0.0.1 * @version 0.0.0.1

View File

@ -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 <kristian.knarvik@knett.no>
* @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);
}
}
}