Bugfixes and optimizations
Fixes a bug where the server version is not updated on load. Optimized downloading of all jar files.
This commit is contained in:
parent
46bb3a9e29
commit
5ac22babab
@ -461,6 +461,12 @@ public class Profile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a profile, and creates a profile with the data.
|
||||||
|
*
|
||||||
|
* @param profileData The data of the new profile
|
||||||
|
* @return The new profile
|
||||||
|
*/
|
||||||
private static Profile parseProfile(String[] profileData) {
|
private static Profile parseProfile(String[] profileData) {
|
||||||
return new Profile(
|
return new Profile(
|
||||||
profileData[0],
|
profileData[0],
|
||||||
@ -470,6 +476,12 @@ public class Profile {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a server, and creates a new collection.
|
||||||
|
*
|
||||||
|
* @param profile The profile which to add the collection
|
||||||
|
* @param serverData The data to parse
|
||||||
|
*/
|
||||||
private static void parseServer(Profile profile, String[] serverData) {
|
private static void parseServer(Profile profile, String[] serverData) {
|
||||||
profile.collections.add(new Collection(
|
profile.collections.add(new Collection(
|
||||||
serverData[0],
|
serverData[0],
|
||||||
@ -485,6 +497,11 @@ public class Profile {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Downloads all jars to the program directory.
|
||||||
|
*
|
||||||
|
* @throws IOException On version file failure or folder creation failure
|
||||||
|
*/
|
||||||
public static void downloadJars() throws IOException {
|
public static void downloadJars() throws IOException {
|
||||||
if (!new File(jarDir).exists() && !new File(jarDir).mkdirs()) {
|
if (!new File(jarDir).exists() && !new File(jarDir).mkdirs()) {
|
||||||
JOptionPane.showMessageDialog(
|
JOptionPane.showMessageDialog(
|
||||||
@ -495,146 +512,64 @@ public class Profile {
|
|||||||
);
|
);
|
||||||
throw new FileNotFoundException("Unable to create jars folder");
|
throw new FileNotFoundException("Unable to create jars folder");
|
||||||
}
|
}
|
||||||
downloadSimple("Spigot");
|
try {
|
||||||
downloadSimple("Craftbukkit");
|
downloadAll();
|
||||||
downloadSimple("MCPCplus");
|
|
||||||
downloadMixed("Vanilla");
|
|
||||||
downloadMixed("Snapshot");
|
|
||||||
downloadSponge();
|
|
||||||
downloadBungee();
|
|
||||||
gui.setStatus("Finished downloading jars");
|
gui.setStatus("Finished downloading jars");
|
||||||
}
|
} catch (FileNotFoundException e) {
|
||||||
|
gui.setStatus("One or more downloads failed: " + e.getMessage());
|
||||||
private static void downloadSimple(String typeName) throws FileNotFoundException {
|
|
||||||
ServerType type = ServerType.getByName(typeName);
|
|
||||||
String url = Objects.requireNonNull(type).getDownloadURL();
|
|
||||||
String name = type.getName();
|
|
||||||
Boolean success;
|
|
||||||
for (String version : type.getVersions()) {
|
|
||||||
File file = new File(jarDir + type.getName() + version + ".jar");
|
|
||||||
if (!file.isFile()) {
|
|
||||||
Path filePath = Paths.get(jarDir + type.getName() + version + ".jar");
|
|
||||||
if (gui != null) {
|
|
||||||
gui.setStatus("Downloading: " + name + version + ".jar");
|
|
||||||
}
|
|
||||||
success = downloadFile(url + name + version + ".jar", filePath);
|
|
||||||
if (!success) {
|
|
||||||
if (gui != null) {
|
|
||||||
gui.setStatus("Error downloading: " + name + version + ".jar");
|
|
||||||
}
|
|
||||||
throw new FileNotFoundException("Error downloading: " + name + version + ".jar");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void downloadMixed(String typeName) throws IOException {
|
/**
|
||||||
AdvancedServerType type = (AdvancedServerType) ServerType.getByName(typeName);
|
* Downloads jar files for all possible server versions.
|
||||||
String url = Objects.requireNonNull(type).getDownloadURL();
|
*
|
||||||
String name = type.getName();
|
* @throws IOException If a jar fails to download.
|
||||||
String versionText;
|
*/
|
||||||
String newestVersion;
|
private static void downloadAll() throws IOException {
|
||||||
Boolean success;
|
for (ServerType type : ServerType.getServerTypes()) {
|
||||||
|
String url = Objects.requireNonNull(type).getDownloadURL(), name = type.getName(), newestVersion;
|
||||||
|
AdvancedServerType advType = type instanceof AdvancedServerType ? (AdvancedServerType) type : null;
|
||||||
for (String version : type.getVersions()) {
|
for (String version : type.getVersions()) {
|
||||||
File file = new File(jarDir + type.getName() + version + ".jar");
|
Boolean success;
|
||||||
Path filePath = Paths.get(jarDir + type.getName() + version + ".jar");
|
|
||||||
if (gui != null) {
|
if (gui != null) {
|
||||||
gui.setStatus("Downloading: " + name + version + ".jar");
|
gui.setStatus("Downloading: " + name + version + ".jar");
|
||||||
}
|
}
|
||||||
|
File file = new File(jarDir + type.getName() + version + ".jar");
|
||||||
|
Path filePath = Paths.get(jarDir + type.getName() + version + ".jar");
|
||||||
|
switch (type.getName()) {
|
||||||
|
case "Vanilla":
|
||||||
|
case "Snapshot":
|
||||||
if (version.equals("Latest")) {
|
if (version.equals("Latest")) {
|
||||||
try {
|
newestVersion = stringBetween(readFile(Objects.requireNonNull(advType).getVersionURL()), advType.getSrcStart(), advType.getSrcEnd());
|
||||||
versionText = readFile(type.getVersionURL());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IOException("Error reading: " + type.getVersionURL());
|
|
||||||
}
|
|
||||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
|
||||||
if (!file.isFile() || !newestVersion.equals(getVersion(name))) {
|
|
||||||
success = downloadFile(
|
|
||||||
url + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar",
|
|
||||||
filePath
|
|
||||||
);
|
|
||||||
setVersion(name, newestVersion);
|
setVersion(name, newestVersion);
|
||||||
if (!success) {
|
success = (file.isFile() && newestVersion.equals(getVersion(name))) || downloadFile(url + newestVersion + advType.getDownloadURLPart() + newestVersion + ".jar", filePath);
|
||||||
if (gui != null) {
|
|
||||||
gui.setStatus("Error downloading: " + name + version + ".jar");
|
|
||||||
}
|
|
||||||
throw new FileNotFoundException("Error downloading: " + name + version + ".jar");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (!file.isFile()) {
|
success = file.isFile() || downloadFile(url + version + Objects.requireNonNull(advType).getDownloadURLPart() + version + ".jar", filePath);
|
||||||
success = downloadFile(url + version + type.getDownloadURLPart() + version + ".jar", filePath);
|
|
||||||
if (!success) {
|
|
||||||
if (gui != null) {
|
|
||||||
gui.setStatus("Error downloading: " + name + version + ".jar");
|
|
||||||
}
|
}
|
||||||
throw new FileNotFoundException("Error downloading: " + name + version + ".jar");
|
break;
|
||||||
}
|
case "Spigot":
|
||||||
}
|
case "Craftbukkit":
|
||||||
}
|
case "MCPCplus":
|
||||||
}
|
success = file.isFile() || downloadFile(url + name + version + ".jar", filePath);
|
||||||
}
|
break;
|
||||||
|
case "SpongeVanilla":
|
||||||
private static void downloadSponge() throws IOException {
|
newestVersion = stringBetween(readFile(Objects.requireNonNull(advType).getVersionURL() + version), advType.getSrcStart(), advType.getSrcEnd());
|
||||||
AdvancedServerType type = (AdvancedServerType) ServerType.getByName("SpongeVanilla");
|
success = file.isFile() || downloadFile(url + newestVersion + advType.getDownloadURLPart() + newestVersion + ".jar", filePath);
|
||||||
String url = Objects.requireNonNull(type).getDownloadURL();
|
break;
|
||||||
String name = type.getName();
|
case "Bungee":
|
||||||
String versionText;
|
newestVersion = stringBetween(readFile(Objects.requireNonNull(advType).getVersionURL()), advType.getSrcStart(), advType.getSrcEnd());
|
||||||
String newestVersion;
|
|
||||||
Boolean success;
|
|
||||||
for (String version : type.getVersions()) {
|
|
||||||
File file = new File(jarDir + name + version + ".jar");
|
|
||||||
Path filePath = Paths.get(jarDir + name + version + ".jar");
|
|
||||||
if (gui != null) {
|
|
||||||
gui.setStatus("Downloading: " + name + version + ".jar");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
versionText = readFile(type.getVersionURL() + version);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IOException("Error reading: " + type.getVersionURL());
|
|
||||||
}
|
|
||||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
|
||||||
if (!file.isFile()) {
|
|
||||||
success = downloadFile(
|
|
||||||
url + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar",
|
|
||||||
filePath
|
|
||||||
);
|
|
||||||
if (!success) {
|
|
||||||
if (gui != null) {
|
|
||||||
gui.setStatus("Error downloading: " + name + version + ".jar");
|
|
||||||
}
|
|
||||||
throw new FileNotFoundException("Error downloading: " + name + version + ".jar");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void downloadBungee() throws IOException {
|
|
||||||
AdvancedServerType type = (AdvancedServerType) ServerType.getByName("Bungee");
|
|
||||||
String url = Objects.requireNonNull(type).getDownloadURL();
|
|
||||||
String name = type.getName();
|
|
||||||
String versionText;
|
|
||||||
String newestVersion;
|
|
||||||
Boolean success;
|
|
||||||
File file = new File(jarDir + type.getName() + ".jar");
|
|
||||||
Path filePath = Paths.get(jarDir + type.getName() + ".jar");
|
|
||||||
if (gui != null) {
|
|
||||||
gui.setStatus("Downloading: " + name + ".jar");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
versionText = readFile(type.getVersionURL());
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IOException("Error reading: " + type.getVersionURL());
|
|
||||||
}
|
|
||||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
|
||||||
if (!file.isFile() || !newestVersion.equals(getVersion(name))) {
|
|
||||||
success = downloadFile(url, filePath);
|
|
||||||
setVersion(name, newestVersion);
|
setVersion(name, newestVersion);
|
||||||
|
success = (file.isFile() && newestVersion.equals(getVersion(name))) || downloadFile(url, filePath);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
if (!success) {
|
if (!success) {
|
||||||
if (gui != null) {
|
if (gui != null) {
|
||||||
gui.setStatus("Error downloading: " + name + ".jar");
|
gui.setStatus("Error downloading: " + name + version + ".jar");
|
||||||
|
}
|
||||||
|
throw new FileNotFoundException("Error downloading: " + name + version + ".jar");
|
||||||
}
|
}
|
||||||
throw new FileNotFoundException("Error downloading: " + name + ".jar");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,12 +351,7 @@ public class Server {
|
|||||||
AdvancedServerType type;
|
AdvancedServerType type;
|
||||||
File file = new File(this.path + File.separator + this.getType());
|
File file = new File(this.path + File.separator + this.getType());
|
||||||
Path filePath = Paths.get(this.path + File.separator + this.getType());
|
Path filePath = Paths.get(this.path + File.separator + this.getType());
|
||||||
String versionText;
|
String versionText, newestVersion, url = this.type.getDownloadURL(), name = this.type.getName(), ver = this.serverVersion;
|
||||||
String newestVersion;
|
|
||||||
String url = this.type.getDownloadURL();
|
|
||||||
String name = this.type.getName();
|
|
||||||
String ver = this.serverVersion;
|
|
||||||
boolean success;
|
|
||||||
switch (this.type.getName()) {
|
switch (this.type.getName()) {
|
||||||
case "Custom":
|
case "Custom":
|
||||||
if (!file.isFile()) {
|
if (!file.isFile()) {
|
||||||
@ -366,12 +361,9 @@ public class Server {
|
|||||||
case "Spigot":
|
case "Spigot":
|
||||||
case "Craftbukkit":
|
case "Craftbukkit":
|
||||||
case "MCPCplus":
|
case "MCPCplus":
|
||||||
if (!file.isFile()) {
|
if (!(file.isFile() || downloadFile(url + name + ver + ".jar", filePath))) {
|
||||||
success = downloadFile(url + name + ver + ".jar", filePath);
|
|
||||||
if (!success) {
|
|
||||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "Vanilla":
|
case "Vanilla":
|
||||||
case "Snapshot":
|
case "Snapshot":
|
||||||
@ -384,23 +376,16 @@ public class Server {
|
|||||||
}
|
}
|
||||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
||||||
if (!file.isFile() || !newestVersion.equals(this.getVersion(name))) {
|
if (!file.isFile() || !newestVersion.equals(this.getVersion(name))) {
|
||||||
success = downloadFile(
|
|
||||||
url + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar",
|
|
||||||
filePath
|
|
||||||
);
|
|
||||||
this.setVersion(name, newestVersion);
|
this.setVersion(name, newestVersion);
|
||||||
if (!success) {
|
if (!downloadFile(url + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath)) {
|
||||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!file.isFile()) {
|
if (!(file.isFile() || downloadFile(url + ver + type.getDownloadURLPart() + ver + ".jar", filePath))) {
|
||||||
success = downloadFile(url + ver + type.getDownloadURLPart() + ver + ".jar", filePath);
|
|
||||||
if (!success) {
|
|
||||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "SpongeVanilla":
|
case "SpongeVanilla":
|
||||||
type = (AdvancedServerType) this.type;
|
type = (AdvancedServerType) this.type;
|
||||||
@ -411,12 +396,8 @@ public class Server {
|
|||||||
}
|
}
|
||||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
||||||
if (!file.isFile() || !newestVersion.equals(this.getVersion(name))) {
|
if (!file.isFile() || !newestVersion.equals(this.getVersion(name))) {
|
||||||
success = downloadFile(
|
|
||||||
url + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar",
|
|
||||||
filePath
|
|
||||||
);
|
|
||||||
this.setVersion(name, newestVersion);
|
this.setVersion(name, newestVersion);
|
||||||
if (!success) {
|
if (!downloadFile(url + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath)) {
|
||||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -430,9 +411,8 @@ public class Server {
|
|||||||
}
|
}
|
||||||
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
|
||||||
if (!file.isFile() || !newestVersion.equals(this.getVersion(name))) {
|
if (!file.isFile() || !newestVersion.equals(this.getVersion(name))) {
|
||||||
success = downloadFile(url, filePath);
|
|
||||||
this.setVersion(name, newestVersion);
|
this.setVersion(name, newestVersion);
|
||||||
if (!success) {
|
if (!downloadFile(url, filePath)) {
|
||||||
throw new FileNotFoundException("Jar file could not be downloaded.");
|
throw new FileNotFoundException("Jar file could not be downloaded.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ public class ServerTab implements ActionListener {
|
|||||||
this.chckbxEnabled.setSelected(enabled);
|
this.chckbxEnabled.setSelected(enabled);
|
||||||
this.serverTypes.setSelectedItem(typeName);
|
this.serverTypes.setSelectedItem(typeName);
|
||||||
this.serverTypes();
|
this.serverTypes();
|
||||||
this.serverTypes.setSelectedItem(serverVersion);
|
this.serverVersions.setSelectedItem(serverVersion);
|
||||||
this.maxRam.setSelectedItem(maxRam);
|
this.maxRam.setSelectedItem(maxRam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user