Splits the Waterfall and Travertine server types by Minecraft version
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2020-08-19 13:06:27 +02:00
parent 4f60ed5d10
commit 23161c1a8d
6 changed files with 56 additions and 46 deletions

View File

@ -17,8 +17,8 @@ public class ServerVersionContainer {
private String vanillaVersion;
private String snapshotVersion;
private String bungeeVersion;
private String waterfallVersion;
private String travertineVersion;
private Map<String, String> waterfallVersions;
private Map<String, String> travertineVersions;
private Map<String, String> spongeVanillaVersions;
private Map<String, String> spongeForgeVersions;
@ -26,8 +26,10 @@ public class ServerVersionContainer {
* Initializes a new server version container
*/
private ServerVersionContainer() {
spongeVanillaVersions = new HashMap<>();
spongeForgeVersions = new HashMap<>();
this.waterfallVersions = new HashMap<>();
this.travertineVersions = new HashMap<>();
this.spongeVanillaVersions = new HashMap<>();
this.spongeForgeVersions = new HashMap<>();
loadState();
}
@ -50,8 +52,8 @@ public class ServerVersionContainer {
this.vanillaVersion = null;
this.snapshotVersion = null;
this.bungeeVersion = null;
this.waterfallVersion = null;
this.travertineVersion = null;
this.waterfallVersions = new HashMap<>();
this.travertineVersions = new HashMap<>();
this.spongeVanillaVersions = new HashMap<>();
this.spongeForgeVersions = new HashMap<>();
}
@ -61,8 +63,8 @@ public class ServerVersionContainer {
return "vanillaVersion;" + vanillaVersion + "\n" +
"snapshotVersion;" + snapshotVersion + "\n" +
"bungeeVersion;" + bungeeVersion + "\n" +
"waterfallVersion;" + waterfallVersion + "\n" +
"travertineVersion;" + travertineVersion + "\n" +
"waterfallVersions;" + mapToString(waterfallVersions) + "\n" +
"travertineVersions;" + mapToString(travertineVersions) + "\n" +
"spongeVanillaVersions;" + mapToString(spongeVanillaVersions) + "\n" +
"spongeForgeVersions;" + mapToString(spongeForgeVersions);
}
@ -151,17 +153,17 @@ public class ServerVersionContainer {
case "bungeeVersion":
bungeeVersion = variableValue;
break;
case "waterfallVersion":
waterfallVersion = variableValue;
case "waterfallVersions":
parseVersionsToMap(waterfallVersions, variableValue);
break;
case "travertineVersion":
travertineVersion = variableValue;
case "travertineVersions":
parseVersionsToMap(travertineVersions, variableValue);
break;
case "spongeVanillaVersions":
parseSpongeVersions(spongeVanillaVersions, variableValue);
parseVersionsToMap(spongeVanillaVersions, variableValue);
break;
case "spongeForgeVersions":
parseSpongeVersions(spongeForgeVersions, variableValue);
parseVersionsToMap(spongeForgeVersions, variableValue);
break;
default:
throw new IllegalArgumentException("Invalid key encountered in the server version file.");
@ -169,12 +171,12 @@ public class ServerVersionContainer {
}
/**
* Reads sponge versions from a text string and updates the version map
* Reads versions from a text string and updates the version map
*
* @param targetMap <p>The map to update</p>
* @param data <p>The data string to parse</p>
*/
private void parseSpongeVersions(Map<String,String> targetMap, String data) {
private void parseVersionsToMap(Map<String,String> targetMap, String data) {
String[] versions = data.split(",");
for (String version : versions) {
String[] versionData = version.split("!");
@ -241,40 +243,44 @@ public class ServerVersionContainer {
}
/**
* Gets the current waterfall version
* Gets a specific waterfall version
*
* @param versionKey <p>The version to check current version of</p>
* @return <p>The current waterfall version</p>
*/
public String getWaterfallVersion() {
return this.waterfallVersion;
public String getWaterfallVersion(String versionKey) {
return this.waterfallVersions.get(versionKey);
}
/**
* Sets the waterfall server version
* Sets the current version for a given waterfall version
*
* @param newVersion <p>The new waterfall server version</p>
* @param mapKey <p>The version key to set version for</p>
* @param newValue <p>The new current version</p>
*/
public void setWaterfallVersion(String newVersion) {
this.waterfallVersion = newVersion;
public void setWaterfallVersion(String mapKey, String newValue) {
this.waterfallVersions.put(mapKey, newValue);
saveState();
}
/**
* Gets the current travertine server version
* Gets a specific travertine version
*
* @param versionKey <p>The version to check current version of</p>
* @return <p>The current travertine version</p>
*/
public String getTravertineVersion() {
return this.travertineVersion;
public String getTravertineVersion(String versionKey) {
return this.travertineVersions.get(versionKey);
}
/**
* Sets the travertine server version
* Sets the current version for a given travertine version
*
* @param newVersion <p>The new travertine server version</p>
* @param mapKey <p>The version key to set version for</p>
* @param newValue <p>The new current version</p>
*/
public void setTravertineVersion(String newVersion) {
this.travertineVersion = newVersion;
public void setTravertineVersion(String mapKey, String newValue) {
this.travertineVersions.put(mapKey, newValue);
saveState();
}

View File

@ -7,7 +7,6 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.downloadFile;

View File

@ -1,7 +1,5 @@
package net.knarcraft.minecraftserverlauncher.server.servertypes;
import net.knarcraft.minecraftserverlauncher.server.ServerVersionContainer;
/**
* This class represents the Travertine proxy server type
*/
@ -21,7 +19,7 @@ public class Travertine extends Waterfall {
public Travertine(String typeName, boolean isProxy, String[] versions, String versionURL, String srcStart,
String srcEnd, String downloadURL) {
super(typeName, isProxy, versions, versionURL, srcStart, srcEnd, downloadURL);
this.oldVersion = ServerVersionContainer.getInstance().getTravertineVersion();
this.oldVersionFunction = serverVersionContainer::getTravertineVersion;
this.versionUpdateFunction = serverVersionContainer::setTravertineVersion;
}

View File

@ -5,7 +5,8 @@ import net.knarcraft.minecraftserverlauncher.server.ServerVersionContainer;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.function.Consumer;
import java.util.function.BiConsumer;
import java.util.function.Function;
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.downloadFile;
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.readFile;
@ -19,8 +20,8 @@ public class Waterfall extends AbstractServerType {
private final String srcStart;
private final String srcEnd;
private final String versionURL;
String oldVersion;
Consumer<String> versionUpdateFunction;
Function<String, String> oldVersionFunction;
BiConsumer<String, String> versionUpdateFunction;
final ServerVersionContainer serverVersionContainer;
/**
@ -41,7 +42,7 @@ public class Waterfall extends AbstractServerType {
this.srcStart = srcStart;
this.srcEnd = srcEnd;
this.versionURL = versionURL;
this.oldVersion = serverVersionContainer.getWaterfallVersion();
this.oldVersionFunction = serverVersionContainer::getWaterfallVersion;
this.versionUpdateFunction = serverVersionContainer::setWaterfallVersion;
}
@ -49,17 +50,18 @@ public class Waterfall extends AbstractServerType {
public boolean downloadJar(String folder, String version) throws IOException {
String file = this.getName() + version + ".jar";
File filePath = new File(folder + file);
String newestVersion = stringBetween(readFile(versionURL), srcStart, srcEnd);
String fullURL = downloadURL + newestVersion + "/download";
String newestVersion = stringBetween(readFile(versionURL + version), srcStart, srcEnd);
String fullURL = downloadURL + version + "/" + newestVersion + "/download";
String oldVersion = oldVersionFunction.apply(version);
//The file is already the newest version
if (filePath.isFile() && newestVersion.equals(this.oldVersion)) {
if (filePath.isFile() && newestVersion.equals(oldVersion)) {
return true;
}
//The new jar file could not be downloaded
if (!downloadFile(fullURL, Paths.get(filePath.toURI()))) {
return false;
}
versionUpdateFunction.accept(newestVersion);
versionUpdateFunction.accept(version, newestVersion);
return true;
}
}

View File

@ -6,6 +6,6 @@ Craftbukkit;1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.8.8,1.7.10-R0.1,1.6.4-R2.0,1.5.2
SpongeForge;1.12.2,1.11.2,1.10.2;https://dl-api.spongepowered.org/v1/org.spongepowered/spongeforge/downloads?type=stable&minecraft=;"version":";",;https://repo.spongepowered.org/maven/org/spongepowered/spongeforge/;/spongeforge-
MCPCplus;1.6.4,1.6.2,1.5.2,1.4.7;https://static.knarcraft.net/archive/downloads/minecraftserverjars/MCPC+/;mcpcplus
Bungee;Latest,1.7.10,1.6.4,1.5.2,1.4.7;https://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/bootstrap/target/;Artifacts of BungeeCord #; ;http://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/bootstrap/target/BungeeCord.jar;https://static.knarcraft.net/archive/downloads/minecraftserverjars/BungeeCord/;BungeeCord-
Waterfall;Latest;https://papermc.io/api/v1/waterfall/1.16;"latest":";";https://papermc.io/api/v1/waterfall/1.16/
Travertine;Latest;https://papermc.io/api/v1/travertine/1.16;"latest":";";https://papermc.io/api/v1/travertine/1.16/
Waterfall;1.16,1.15,1.14,1.13,1.12,1.11;https://papermc.io/api/v1/waterfall/;"latest":";";https://papermc.io/api/v1/waterfall/
Travertine;1.16,1.15,1.14,1.13,1.12;https://papermc.io/api/v1/travertine/;"latest":";";https://papermc.io/api/v1/travertine/
Custom;;
Can't render this file because it contains an unexpected character in line 1 and column 193.

View File

@ -23,14 +23,19 @@ public class ServerVersionContainerTest {
} catch (FileNotFoundException e) {
e.printStackTrace();
}
File versionFileFile = new File(versionFile);
if (versionFileFile.exists() && !versionFileFile.delete()) {
throw new IllegalArgumentException("Unable to remove old version file.");
}
serverVersionContainer = ServerVersionContainer.getInstance();
}
@Test
public void toStringTest() {
serverVersionContainer.reset();
assertEquals("vanillaVersion;null\nsnapshotVersion;null\nbungeeVersion;null\nwaterfallVersion;null\n" +
"travertineVersion;null\nspongeVanillaVersions;",
System.out.println(serverVersionContainer.toString());
assertEquals("vanillaVersion;null\nsnapshotVersion;null\nbungeeVersion;null\nwaterfallVersions;\n" +
"travertineVersions;\nspongeVanillaVersions;\nspongeForgeVersions;",
serverVersionContainer.toString());
}