Adds comments and refactors several classes
All checks were successful
KnarCraft/Minecraft-Server-Launcher/master This commit looks good
All checks were successful
KnarCraft/Minecraft-Server-Launcher/master This commit looks good
Adds comments to Collection Makes some variable and function names more descriptive Adds some new methods for showing messsages and errors Adds a lot of missing comments Enhances some existing comments
This commit is contained in:
@ -13,6 +13,16 @@ public class AdvancedServerType extends ServerType {
|
||||
private final String srcStart;
|
||||
private final String srcEnd;
|
||||
|
||||
/**
|
||||
* Instantiates a new Advanced server type
|
||||
* @param name <p>The name of the server type</p>
|
||||
* @param versions <p>A list of one or more server versions for the type</p>
|
||||
* @param versionURL <p>The URL for checking last version for server type</p>
|
||||
* @param srcStart <p>The string in the version file marking the start of the newest version entry</p>
|
||||
* @param srcEnd <p>The string in the version file marking the end of the newest version entry</p>
|
||||
* @param downloadURL <p>The URL used for downloading .jar files</p>
|
||||
* @param downloadURLPart <p>An extra part for the download URL</p>
|
||||
*/
|
||||
AdvancedServerType(String name, String[] versions, String versionURL, String srcStart, String srcEnd, String downloadURL, String downloadURLPart) {
|
||||
super(name, versions, downloadURL);
|
||||
this.srcStart = srcStart;
|
||||
@ -21,18 +31,34 @@ public class AdvancedServerType extends ServerType {
|
||||
this.downloadURLPart = downloadURLPart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL used for downloading latest version information
|
||||
* @return <p>The latest version URL</p>
|
||||
*/
|
||||
public String getVersionURL() {
|
||||
return this.versionURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an additional part of the download URL
|
||||
* @return <p>Additional download URL part</p>
|
||||
*/
|
||||
public String getDownloadURLPart() {
|
||||
return this.downloadURLPart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string marking the start of the latest server version in the version document
|
||||
* @return <p>A string marking the start of the latest version</p>
|
||||
*/
|
||||
public String getSrcStart() {
|
||||
return this.srcStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string marking the end of the latest server version in the version document
|
||||
* @return <p>A string marking the end of the latest version</p>
|
||||
*/
|
||||
public String getSrcEnd() {
|
||||
return this.srcEnd;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class Server {
|
||||
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 String jarDir = Main.getAppDir() + File.separator + "files" + File.separator + "Jars" + File.separator;
|
||||
private static final String jarDirectory = Main.getApplicationWorkDirectory() + File.separator + "files" + File.separator + "Jars" + File.separator;
|
||||
|
||||
private final String name;
|
||||
private String path;
|
||||
@ -185,11 +185,7 @@ public class Server {
|
||||
* @param name The name of the player to remove
|
||||
*/
|
||||
public void removePlayer(String name) {
|
||||
for (int i = 0; i < playerList.size(); i++) {
|
||||
if (name.equals(playerList.get(i))) {
|
||||
playerList.remove(i);
|
||||
}
|
||||
}
|
||||
playerList.removeIf(player -> player.equals(name));
|
||||
Profile.getGUI().removePlayer(name);
|
||||
}
|
||||
|
||||
@ -271,7 +267,7 @@ public class Server {
|
||||
private boolean run() {
|
||||
if (this.enabled) {
|
||||
this.started = true;
|
||||
if (!Profile.getCurrent().getDownloadJars()) {
|
||||
if (!Profile.getCurrent().getDownloadAllAvailableJARFiles()) {
|
||||
try {
|
||||
Profile.getGUI().setStatus("Downloading jar...");
|
||||
this.downloadJar();
|
||||
@ -295,8 +291,8 @@ public class Server {
|
||||
try {
|
||||
ProcessBuilder builder;
|
||||
String serverPath;
|
||||
if (Profile.getCurrent().getDownloadJars() && !type.getName().equals("Custom")) {
|
||||
serverPath = jarDir + this.getType();
|
||||
if (Profile.getCurrent().getDownloadAllAvailableJARFiles() && !type.getName().equals("Custom")) {
|
||||
serverPath = jarDirectory + this.getType();
|
||||
} else {
|
||||
serverPath = this.path + File.separator + this.getType();
|
||||
}
|
||||
@ -347,7 +343,6 @@ public class Server {
|
||||
/**
|
||||
* Downloads necessary .jar file for the server.
|
||||
* This is unfortunately hardcoded since there is no golden standard, and we only host some jars ourselves.
|
||||
*
|
||||
* @throws FileNotFoundException if the file was not found and could not be acquired.
|
||||
*/
|
||||
private void downloadJar() throws FileNotFoundException {
|
||||
@ -438,9 +433,8 @@ public class Server {
|
||||
|
||||
/**
|
||||
* Returns the current version of a type
|
||||
*
|
||||
* @param type The version type
|
||||
* @return The version string
|
||||
* @param type <p>The version type</p>
|
||||
* @return <p>The version string</p>
|
||||
*/
|
||||
private String getVersion(String type) {
|
||||
switch (type) {
|
||||
@ -459,9 +453,8 @@ public class Server {
|
||||
|
||||
/**
|
||||
* Sets a server type's last downloaded version.
|
||||
*
|
||||
* @param type The version type
|
||||
* @param version The version string
|
||||
* @param type <p>The version type</p>
|
||||
* @param version <p>The version string</p>
|
||||
*/
|
||||
private void setVersion(String type, String version) {
|
||||
if (!type.equals("")) {
|
||||
@ -483,9 +476,8 @@ public class Server {
|
||||
|
||||
/**
|
||||
* Sends a command to this server through its writer.
|
||||
*
|
||||
* @param command Command to send to the server
|
||||
* @throws IOException If write fails
|
||||
* @param command <p>Command to send to the server</p>
|
||||
* @throws IOException <p>If write fails</p>
|
||||
*/
|
||||
public void sendCommand(String command) throws IOException {
|
||||
if (this.process != null && this.writer != null) {
|
||||
|
@ -20,49 +20,69 @@ public class ServerType {
|
||||
private final String[] versions;
|
||||
private final String downloadURL;
|
||||
private static final ArrayList<ServerType> serverTypes = new ArrayList<>();
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new server type
|
||||
* @param name <p>The name of the server type</p>
|
||||
* @param versions <p>A list of one or more server versions for the type</p>
|
||||
* @param downloadURL <p>The URL used for downloading .jar files</p>
|
||||
*/
|
||||
ServerType(String name, String[] versions, String downloadURL) {
|
||||
this.name = name;
|
||||
this.versions = versions;
|
||||
this.downloadURL = downloadURL;
|
||||
serverTypes.add(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the name of the server type
|
||||
* @return <p>Server type name</p>
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets a list of versions available for the server type
|
||||
* @return <p>A list of server versions</p>
|
||||
*/
|
||||
public String[] getVersions() {
|
||||
return this.versions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the url used for downloading JAR files
|
||||
* @return <p>A download URL</p>
|
||||
*/
|
||||
public String getDownloadURL() {
|
||||
return this.downloadURL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all instantiated server types
|
||||
* @return <p>A list of server types</p>
|
||||
*/
|
||||
public static ArrayList<ServerType> getServerTypes() {
|
||||
return serverTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all server types' names.
|
||||
*
|
||||
* @return A list of strings
|
||||
* @return <p>A list of strings</p>
|
||||
*/
|
||||
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();
|
||||
String[] serverTypeNames = new String[types.size()];
|
||||
for (int i = 0; i < types.size(); i++) {
|
||||
serverTypeNames[i] = types.get(i).getName();
|
||||
}
|
||||
return serverTypes;
|
||||
return serverTypeNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a server type by name.
|
||||
*
|
||||
* @param name Then name of the server type
|
||||
* @return A ServerType
|
||||
* Gets a server type by the given name
|
||||
* @param name <p>Then name of the server type</p>
|
||||
* @return <p>A ServerType</p>
|
||||
*/
|
||||
public static ServerType getByName(String name) {
|
||||
for (ServerType serverType : serverTypes) {
|
||||
@ -75,8 +95,7 @@ public class ServerType {
|
||||
|
||||
/**
|
||||
* Reads valid server types and version from a file, and creates their objects.
|
||||
*
|
||||
* @throws ConfigurationException if anything goes wrong.
|
||||
* @throws ConfigurationException <p>If anything goes wrong</p>
|
||||
*/
|
||||
public static void loadServerTypes() throws ConfigurationException {
|
||||
if (serverTypes.isEmpty()) {
|
||||
@ -87,20 +106,22 @@ public class ServerType {
|
||||
throw new ConfigurationException("Server type configuration file is missing.");
|
||||
}
|
||||
while (file.hasNextLine()) {
|
||||
String[] str = file.nextLine().split(";", -1);
|
||||
int len = str.length;
|
||||
String[] ver;
|
||||
if (str[1].contains(",")) {
|
||||
ver = str[1].split(",", -1);
|
||||
//Splits the next file line into arguments
|
||||
String[] fileLine = file.nextLine().split(";", -1);
|
||||
int lineLength = fileLine.length;
|
||||
//Gets list of server versions from file line
|
||||
String[] serverVersion;
|
||||
if (fileLine[1].contains(",")) {
|
||||
serverVersion = fileLine[1].split(",", -1);
|
||||
} else {
|
||||
ver = new String[]{str[1]};
|
||||
serverVersion = new String[]{fileLine[1]};
|
||||
}
|
||||
switch (len) {
|
||||
switch (lineLength) {
|
||||
case 7:
|
||||
new AdvancedServerType(str[0], ver, str[2], str[3], str[4], str[5], str[6]);
|
||||
new AdvancedServerType(fileLine[0], serverVersion, fileLine[2], fileLine[3], fileLine[4], fileLine[5], fileLine[6]);
|
||||
break;
|
||||
case 3:
|
||||
new ServerType(str[0], ver, str[2]);
|
||||
new ServerType(fileLine[0], serverVersion, fileLine[2]);
|
||||
break;
|
||||
default:
|
||||
throw new ConfigurationException("Error: Configuration file invalid.");
|
||||
|
Reference in New Issue
Block a user