Adds the ability to download old bungee versions
This commit is contained in:
@ -122,7 +122,7 @@ public class ServerTypeHandler {
|
||||
break;
|
||||
case "Bungee":
|
||||
newType = new BungeeCord("Bungee", true, serverVersions, serverTypeInfo[2],
|
||||
serverTypeInfo[3], serverTypeInfo[4], serverTypeInfo[5]);
|
||||
serverTypeInfo[3], serverTypeInfo[4], serverTypeInfo[5], serverTypeInfo[6], serverTypeInfo[7]);
|
||||
break;
|
||||
case "Travertine":
|
||||
newType = new Travertine("Travertine", true, serverVersions, serverTypeInfo[2],
|
||||
|
@ -18,6 +18,8 @@ public class BungeeCord extends AbstractServerType {
|
||||
private final String versionURL;
|
||||
private final String srcStart;
|
||||
private final String srcEnd;
|
||||
private final String oldVersionsURL;
|
||||
private final String oldVersionsPrefix;
|
||||
|
||||
/**
|
||||
* Instantiates a new BungeeCord server type
|
||||
@ -30,18 +32,39 @@ public class BungeeCord extends AbstractServerType {
|
||||
* @param srcEnd <p>The string marking the end of the version id</p>
|
||||
* @param downloadURL <p>The URL used for downloading the latest version</p>
|
||||
*/
|
||||
public BungeeCord(String typeName, boolean isProxy, String[] versions, String versionURL, String srcStart, String srcEnd, String downloadURL) {
|
||||
public BungeeCord(String typeName, boolean isProxy, String[] versions, String versionURL, String srcStart,
|
||||
String srcEnd, String downloadURL, String oldVersionsURL, String oldVersionsPrefix) {
|
||||
super(typeName, isProxy, versions, downloadURL);
|
||||
this.versionURL = versionURL;
|
||||
this.srcStart = srcStart;
|
||||
this.srcEnd = srcEnd;
|
||||
this.oldVersionsURL = oldVersionsURL;
|
||||
this.oldVersionsPrefix = oldVersionsPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean downloadJar(String folder, String version) throws IOException {
|
||||
String targetFile = this.getName() + version + ".jar";
|
||||
File filePath = new File(folder + targetFile);
|
||||
|
||||
if (version.equals("Latest")) {
|
||||
return downloadLatestJar(filePath);
|
||||
} else {
|
||||
String file = oldVersionsPrefix + version + ".jar";
|
||||
return filePath.isFile() || downloadFile(oldVersionsURL + file, Paths.get(filePath.toURI()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads the latest BungeeCord .jar file
|
||||
*
|
||||
* @param filePath <p>The file path to download the new jar to</p>
|
||||
* @return <p>True if the jar exists or was successfully downloaded</p>
|
||||
* @throws IOException <p>If unable to download the new jar</p>
|
||||
*/
|
||||
private boolean downloadLatestJar(File filePath) throws IOException {
|
||||
ServerVersionContainer versionContainer = ServerVersionContainer.getInstance();
|
||||
String file = this.getName() + version + ".jar";
|
||||
File filePath = new File(folder + file);
|
||||
|
||||
String newestVersion = stringBetween(readFile(versionURL), srcStart, srcEnd);
|
||||
String oldVersion = versionContainer.getBungeeVersion();
|
||||
//The file is already the newest version
|
||||
@ -55,4 +78,5 @@ public class BungeeCord extends AbstractServerType {
|
||||
versionContainer.setBungeeVersion(newestVersion);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user