Server version combo is updated on server type change
This commit is contained in:
parent
1c00ae9bab
commit
559e7bb38a
@ -140,4 +140,37 @@ public class Profile {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setVersion(String type, String version) {
|
||||
if (!version.equals("")) {
|
||||
switch (type) {
|
||||
case "Vanilla":
|
||||
this.vanillaVersion = version;
|
||||
break;
|
||||
case "Snapshot":
|
||||
this.snapshotVersion = version;
|
||||
break;
|
||||
case "SpongeVanilla":
|
||||
this.spongeVanillaVersion = version;
|
||||
break;
|
||||
case "Bungee":
|
||||
this.bungeeVersion = version;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getVersion(String type) {
|
||||
switch (type) {
|
||||
case "Vanilla":
|
||||
return this.vanillaVersion;
|
||||
case "Snapshot":
|
||||
return this.snapshotVersion;
|
||||
case "SpongeVanilla":
|
||||
return this.spongeVanillaVersion;
|
||||
case "Bungee":
|
||||
return this.bungeeVersion;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.knarcraft.serverlauncher.server;
|
||||
|
||||
import net.knarcraft.serverlauncher.profile.Profile;
|
||||
import net.knarcraft.serverlauncher.userinterface.GUI;
|
||||
|
||||
import java.io.*;
|
||||
@ -18,7 +19,9 @@ 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 final String[] ramList = {
|
||||
"512M", "1G", "2G", "3G", "4G", "5G", "6G", "7G", "8G", "9G", "10G","11G", "12G", "13G", "14G", "15G", "16G"
|
||||
};
|
||||
|
||||
private final String name;
|
||||
private String path;
|
||||
@ -60,7 +63,11 @@ public class Server {
|
||||
* @return A representation of the name of a jarfile.
|
||||
*/
|
||||
private String getType() {
|
||||
return this.type.getName() + this.serverVersion + ".jar";
|
||||
if (this.type.getName().equals("Custom")) {
|
||||
return this.serverVersion;
|
||||
} else {
|
||||
return this.type.getName() + this.serverVersion + ".jar";
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -155,7 +162,15 @@ public class Server {
|
||||
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() + "\"");
|
||||
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();
|
||||
@ -182,12 +197,15 @@ public class Server {
|
||||
AdvancedServerType type;
|
||||
File file = new File(this.path + "\\" + this.getType());
|
||||
Path filePath = Paths.get(this.path + "\\" + this.getType());
|
||||
Profile currentProfile = GUI.getGUI().currentProfile();
|
||||
String versionText;
|
||||
String newestVersion;
|
||||
String url = this.type.getDownloadURL();
|
||||
String name = this.type.getName();
|
||||
String ver = this.serverVersion;
|
||||
boolean success;
|
||||
switch (this.type.getName()) {
|
||||
case "Custom":
|
||||
//TODO: Change Custom to use path as serverdir + input.
|
||||
if (!file.isFile()) {
|
||||
throw new FileNotFoundException("Specified custom jar was not found.");
|
||||
}
|
||||
@ -196,8 +214,8 @@ public class Server {
|
||||
case "Craftbukkit":
|
||||
case "MCPCplus":
|
||||
if (!file.isFile()) {
|
||||
success = downloadFile(this.type.getDownloadURL() + this.type.getName() + this.serverVersion + ".jar", filePath);
|
||||
System.out.println(this.type.getDownloadURL() + this.type.getName() + this.serverVersion + ".jar");
|
||||
success = downloadFile(url + name + ver + ".jar", filePath);
|
||||
System.out.println(url + name + ver + ".jar");
|
||||
if (!success) {
|
||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||
}
|
||||
@ -213,14 +231,16 @@ public class Server {
|
||||
throw new FileNotFoundException("Version file could not be downloaded.");
|
||||
}
|
||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
||||
success = downloadFile(this.type.getDownloadURL() + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath);
|
||||
//TODO: Register the new version number, and only download if version mismatch or missing file.
|
||||
if (!success) {
|
||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||
if (!file.isFile() || !newestVersion.equals(currentProfile.getVersion(name))) {
|
||||
success = downloadFile(url + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath);
|
||||
GUI.getGUI().currentProfile().setVersion(this.type.getName(), newestVersion);
|
||||
if (!success) {
|
||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!file.isFile()) {
|
||||
success = downloadFile(this.type.getDownloadURL() + this.serverVersion + type.getDownloadURLPart() + this.serverVersion + ".jar", filePath);
|
||||
success = downloadFile(url + ver + type.getDownloadURLPart() + ver + ".jar", filePath);
|
||||
if (!success) {
|
||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||
}
|
||||
@ -235,24 +255,28 @@ public class Server {
|
||||
throw new FileNotFoundException("Version file could not be downloaded.");
|
||||
}
|
||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
||||
success = downloadFile(this.type.getDownloadURL() + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath);
|
||||
//TODO: Register the new version number, and only download if version mismatch or missing file.
|
||||
if (!success) {
|
||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||
if (!file.isFile() || !newestVersion.equals(currentProfile.getVersion(name))) {
|
||||
success = downloadFile(url + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath);
|
||||
currentProfile.setVersion(name, newestVersion);
|
||||
if (!success) {
|
||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "Bungee":
|
||||
/*type = (AdvancedServerType) this.type;
|
||||
type = (AdvancedServerType) this.type;
|
||||
try {
|
||||
versionText = readFile(this.type.getVersionURL());
|
||||
versionText = readFile(type.getVersionURL());
|
||||
} catch (IOException e) {
|
||||
throw new FileNotFoundException("Version file could not be downloaded.");
|
||||
}
|
||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());*/
|
||||
success = downloadFile(this.type.getDownloadURL(), filePath);
|
||||
//TODO: Register the new version number, and only download if version mismatch or missing file.
|
||||
if (!success) {
|
||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
||||
if (!file.isFile() || !newestVersion.equals(currentProfile.getVersion(name))) {
|
||||
success = downloadFile(url, filePath);
|
||||
currentProfile.setVersion(name, newestVersion);
|
||||
if (!success) {
|
||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,10 @@ public class GUI implements ActionListener {
|
||||
return gui;
|
||||
}
|
||||
|
||||
public ArrayList<ServerTab> getServerTabs() {
|
||||
return this.serverTabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a server's tab, removes it from the list of tabs, and removes the server from Profile.java
|
||||
*
|
||||
@ -101,7 +105,6 @@ public class GUI implements ActionListener {
|
||||
*/
|
||||
public void removeServer(ServerTab tab) {
|
||||
for (int i = 0; i < this.serverTabs.size(); i++) {
|
||||
System.out.println(this.serverTabs.get(i));
|
||||
if(this.serverTabs.get(i) == tab) {
|
||||
serversPane.remove(i);
|
||||
currentProfile().removeServer(i);
|
||||
@ -473,6 +476,7 @@ public class GUI implements ActionListener {
|
||||
*/
|
||||
private void save() {
|
||||
//TODO: Finish save
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,7 @@ class ServerTab implements ActionListener {
|
||||
private final JButton btnBrowse;
|
||||
private final JTextField directory;
|
||||
|
||||
//TODO: Add custom input field + update combo boxes on version change.
|
||||
|
||||
public ServerTab(String name) {
|
||||
JPanel panel = new JPanel();
|
||||
@ -113,6 +114,31 @@ class ServerTab implements ActionListener {
|
||||
if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
directory.setText(chooser.getSelectedFile().toString());
|
||||
}
|
||||
} else if (e.getSource() == serverTypes) {
|
||||
serverVersions.removeAllItems();
|
||||
String selectedserverTypes = null;
|
||||
Object selectedType = serverTypes.getSelectedItem();
|
||||
if (selectedType != null) {
|
||||
selectedserverTypes = selectedType.toString();
|
||||
}
|
||||
if (selectedserverTypes != null) {
|
||||
if (selectedserverTypes.equals("Custom")) {
|
||||
serverVersions.setEditable(true);
|
||||
} else {
|
||||
serverVersions.setEditable(false);
|
||||
ServerType current = null;
|
||||
for (ServerType servertype : ServerType.getServerTypes()) {
|
||||
if (servertype.getName().equals(selectedserverTypes)) {
|
||||
current = servertype;
|
||||
}
|
||||
}
|
||||
if (current != null) {
|
||||
for (String version : current.getVersions()) {
|
||||
serverVersions.addItem(version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user