Started implementing GPU functionality
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
package net.knarcraft.serverlauncher.server;
|
||||
|
||||
import net.knarcraft.serverlauncher.userinterface.GUI;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.Buffer;
|
||||
import java.util.Scanner;
|
||||
import java.nio.file.*;
|
||||
import java.util.ArrayList;
|
||||
@ -18,6 +21,7 @@ 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 final ArrayList<Server> servers = new ArrayList<>();
|
||||
private static GUI gui;
|
||||
|
||||
private final String name;
|
||||
private String path;
|
||||
@ -27,8 +31,9 @@ public class Server {
|
||||
private String serverVersion;
|
||||
private String maxRam;
|
||||
private Process process;
|
||||
private BufferedWriter writer;
|
||||
|
||||
public Server(String name) {
|
||||
public Server(String name, GUI window) {
|
||||
this.name = name;
|
||||
this.path = "";
|
||||
this.enabled = false;
|
||||
@ -38,6 +43,7 @@ public class Server {
|
||||
this.maxRam = ramList[0];
|
||||
this.process = null;
|
||||
servers.add(this);
|
||||
window.addServer(name, this);
|
||||
}
|
||||
|
||||
public void addPlayer(String name) {
|
||||
@ -53,6 +59,10 @@ public class Server {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setGui(GUI _gui) {
|
||||
gui = _gui;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A representation of the name of a jarfile.
|
||||
*/
|
||||
@ -80,6 +90,24 @@ public class Server {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static String[] getRamList() {
|
||||
return ramList;
|
||||
}
|
||||
|
||||
public static void stop() throws IOException {
|
||||
for (Server server : servers) {
|
||||
if (server.writer != null) {
|
||||
if (server.type.getName() == "Bungee") {
|
||||
server.writer.write("end\n");
|
||||
} else {
|
||||
server.writer.write("stop\n");
|
||||
}
|
||||
server.writer.flush();
|
||||
server.writer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the server's server version to a valid version, or ignores the request.
|
||||
*
|
||||
@ -113,26 +141,31 @@ public class Server {
|
||||
/**
|
||||
* Runs the Minecraft server.
|
||||
*/
|
||||
private void run() {
|
||||
private boolean run() {
|
||||
if (this.enabled) {
|
||||
try {
|
||||
System.out.println("Downloading jar...");
|
||||
gui.setStatus("Downloading jar...");
|
||||
this.downloadJar();
|
||||
System.out.println("File downloaded.");
|
||||
gui.setStatus("File downloaded");
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("File was not found.");
|
||||
return;
|
||||
System.out.println("File was not found");
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
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);
|
||||
this.process = builder.start();
|
||||
System.out.println("Success");
|
||||
OutputStream stdin = this.process.getOutputStream ();
|
||||
this.writer = new BufferedWriter(new OutputStreamWriter(stdin));
|
||||
gui.setStatus("Servers are running");
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error");
|
||||
gui.setStatus("Could not start server");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,15 @@ public class ServerType {
|
||||
return serverTypes;
|
||||
}
|
||||
|
||||
public static String[] getTypeNames(){
|
||||
ArrayList<ServerType> types = ServerType.getServerTypes();
|
||||
String[] serverTypes = new String[types.size()];
|
||||
for (int i = 0; i < types.size(); i++) {
|
||||
serverTypes[i] = types.get(i).getName();
|
||||
}
|
||||
return serverTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads valid server types and version from a file, and creates their objects.
|
||||
*
|
||||
|
Reference in New Issue
Block a user