Splits the Waterfall and Travertine server types by Minecraft version
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
This commit is contained in:
parent
4f60ed5d10
commit
23161c1a8d
@ -17,8 +17,8 @@ public class ServerVersionContainer {
|
|||||||
private String vanillaVersion;
|
private String vanillaVersion;
|
||||||
private String snapshotVersion;
|
private String snapshotVersion;
|
||||||
private String bungeeVersion;
|
private String bungeeVersion;
|
||||||
private String waterfallVersion;
|
private Map<String, String> waterfallVersions;
|
||||||
private String travertineVersion;
|
private Map<String, String> travertineVersions;
|
||||||
private Map<String, String> spongeVanillaVersions;
|
private Map<String, String> spongeVanillaVersions;
|
||||||
private Map<String, String> spongeForgeVersions;
|
private Map<String, String> spongeForgeVersions;
|
||||||
|
|
||||||
@ -26,8 +26,10 @@ public class ServerVersionContainer {
|
|||||||
* Initializes a new server version container
|
* Initializes a new server version container
|
||||||
*/
|
*/
|
||||||
private ServerVersionContainer() {
|
private ServerVersionContainer() {
|
||||||
spongeVanillaVersions = new HashMap<>();
|
this.waterfallVersions = new HashMap<>();
|
||||||
spongeForgeVersions = new HashMap<>();
|
this.travertineVersions = new HashMap<>();
|
||||||
|
this.spongeVanillaVersions = new HashMap<>();
|
||||||
|
this.spongeForgeVersions = new HashMap<>();
|
||||||
loadState();
|
loadState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,8 +52,8 @@ public class ServerVersionContainer {
|
|||||||
this.vanillaVersion = null;
|
this.vanillaVersion = null;
|
||||||
this.snapshotVersion = null;
|
this.snapshotVersion = null;
|
||||||
this.bungeeVersion = null;
|
this.bungeeVersion = null;
|
||||||
this.waterfallVersion = null;
|
this.waterfallVersions = new HashMap<>();
|
||||||
this.travertineVersion = null;
|
this.travertineVersions = new HashMap<>();
|
||||||
this.spongeVanillaVersions = new HashMap<>();
|
this.spongeVanillaVersions = new HashMap<>();
|
||||||
this.spongeForgeVersions = new HashMap<>();
|
this.spongeForgeVersions = new HashMap<>();
|
||||||
}
|
}
|
||||||
@ -61,8 +63,8 @@ public class ServerVersionContainer {
|
|||||||
return "vanillaVersion;" + vanillaVersion + "\n" +
|
return "vanillaVersion;" + vanillaVersion + "\n" +
|
||||||
"snapshotVersion;" + snapshotVersion + "\n" +
|
"snapshotVersion;" + snapshotVersion + "\n" +
|
||||||
"bungeeVersion;" + bungeeVersion + "\n" +
|
"bungeeVersion;" + bungeeVersion + "\n" +
|
||||||
"waterfallVersion;" + waterfallVersion + "\n" +
|
"waterfallVersions;" + mapToString(waterfallVersions) + "\n" +
|
||||||
"travertineVersion;" + travertineVersion + "\n" +
|
"travertineVersions;" + mapToString(travertineVersions) + "\n" +
|
||||||
"spongeVanillaVersions;" + mapToString(spongeVanillaVersions) + "\n" +
|
"spongeVanillaVersions;" + mapToString(spongeVanillaVersions) + "\n" +
|
||||||
"spongeForgeVersions;" + mapToString(spongeForgeVersions);
|
"spongeForgeVersions;" + mapToString(spongeForgeVersions);
|
||||||
}
|
}
|
||||||
@ -151,17 +153,17 @@ public class ServerVersionContainer {
|
|||||||
case "bungeeVersion":
|
case "bungeeVersion":
|
||||||
bungeeVersion = variableValue;
|
bungeeVersion = variableValue;
|
||||||
break;
|
break;
|
||||||
case "waterfallVersion":
|
case "waterfallVersions":
|
||||||
waterfallVersion = variableValue;
|
parseVersionsToMap(waterfallVersions, variableValue);
|
||||||
break;
|
break;
|
||||||
case "travertineVersion":
|
case "travertineVersions":
|
||||||
travertineVersion = variableValue;
|
parseVersionsToMap(travertineVersions, variableValue);
|
||||||
break;
|
break;
|
||||||
case "spongeVanillaVersions":
|
case "spongeVanillaVersions":
|
||||||
parseSpongeVersions(spongeVanillaVersions, variableValue);
|
parseVersionsToMap(spongeVanillaVersions, variableValue);
|
||||||
break;
|
break;
|
||||||
case "spongeForgeVersions":
|
case "spongeForgeVersions":
|
||||||
parseSpongeVersions(spongeForgeVersions, variableValue);
|
parseVersionsToMap(spongeForgeVersions, variableValue);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Invalid key encountered in the server version file.");
|
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 targetMap <p>The map to update</p>
|
||||||
* @param data <p>The data string to parse</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(",");
|
String[] versions = data.split(",");
|
||||||
for (String version : versions) {
|
for (String version : versions) {
|
||||||
String[] versionData = version.split("!");
|
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>
|
* @return <p>The current waterfall version</p>
|
||||||
*/
|
*/
|
||||||
public String getWaterfallVersion() {
|
public String getWaterfallVersion(String versionKey) {
|
||||||
return this.waterfallVersion;
|
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) {
|
public void setWaterfallVersion(String mapKey, String newValue) {
|
||||||
this.waterfallVersion = newVersion;
|
this.waterfallVersions.put(mapKey, newValue);
|
||||||
saveState();
|
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>
|
* @return <p>The current travertine version</p>
|
||||||
*/
|
*/
|
||||||
public String getTravertineVersion() {
|
public String getTravertineVersion(String versionKey) {
|
||||||
return this.travertineVersion;
|
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) {
|
public void setTravertineVersion(String mapKey, String newValue) {
|
||||||
this.travertineVersion = newVersion;
|
this.travertineVersions.put(mapKey, newValue);
|
||||||
saveState();
|
saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.downloadFile;
|
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.downloadFile;
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.knarcraft.minecraftserverlauncher.server.servertypes;
|
package net.knarcraft.minecraftserverlauncher.server.servertypes;
|
||||||
|
|
||||||
import net.knarcraft.minecraftserverlauncher.server.ServerVersionContainer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the Travertine proxy server type
|
* 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,
|
public Travertine(String typeName, boolean isProxy, String[] versions, String versionURL, String srcStart,
|
||||||
String srcEnd, String downloadURL) {
|
String srcEnd, String downloadURL) {
|
||||||
super(typeName, isProxy, versions, versionURL, srcStart, srcEnd, downloadURL);
|
super(typeName, isProxy, versions, versionURL, srcStart, srcEnd, downloadURL);
|
||||||
this.oldVersion = ServerVersionContainer.getInstance().getTravertineVersion();
|
this.oldVersionFunction = serverVersionContainer::getTravertineVersion;
|
||||||
this.versionUpdateFunction = serverVersionContainer::setTravertineVersion;
|
this.versionUpdateFunction = serverVersionContainer::setTravertineVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,8 @@ import net.knarcraft.minecraftserverlauncher.server.ServerVersionContainer;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Paths;
|
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.downloadFile;
|
||||||
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.readFile;
|
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.readFile;
|
||||||
@ -19,8 +20,8 @@ public class Waterfall extends AbstractServerType {
|
|||||||
private final String srcStart;
|
private final String srcStart;
|
||||||
private final String srcEnd;
|
private final String srcEnd;
|
||||||
private final String versionURL;
|
private final String versionURL;
|
||||||
String oldVersion;
|
Function<String, String> oldVersionFunction;
|
||||||
Consumer<String> versionUpdateFunction;
|
BiConsumer<String, String> versionUpdateFunction;
|
||||||
final ServerVersionContainer serverVersionContainer;
|
final ServerVersionContainer serverVersionContainer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,7 +42,7 @@ public class Waterfall extends AbstractServerType {
|
|||||||
this.srcStart = srcStart;
|
this.srcStart = srcStart;
|
||||||
this.srcEnd = srcEnd;
|
this.srcEnd = srcEnd;
|
||||||
this.versionURL = versionURL;
|
this.versionURL = versionURL;
|
||||||
this.oldVersion = serverVersionContainer.getWaterfallVersion();
|
this.oldVersionFunction = serverVersionContainer::getWaterfallVersion;
|
||||||
this.versionUpdateFunction = serverVersionContainer::setWaterfallVersion;
|
this.versionUpdateFunction = serverVersionContainer::setWaterfallVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,17 +50,18 @@ public class Waterfall extends AbstractServerType {
|
|||||||
public boolean downloadJar(String folder, String version) throws IOException {
|
public boolean downloadJar(String folder, String version) throws IOException {
|
||||||
String file = this.getName() + version + ".jar";
|
String file = this.getName() + version + ".jar";
|
||||||
File filePath = new File(folder + file);
|
File filePath = new File(folder + file);
|
||||||
String newestVersion = stringBetween(readFile(versionURL), srcStart, srcEnd);
|
String newestVersion = stringBetween(readFile(versionURL + version), srcStart, srcEnd);
|
||||||
String fullURL = downloadURL + newestVersion + "/download";
|
String fullURL = downloadURL + version + "/" + newestVersion + "/download";
|
||||||
|
String oldVersion = oldVersionFunction.apply(version);
|
||||||
//The file is already the newest version
|
//The file is already the newest version
|
||||||
if (filePath.isFile() && newestVersion.equals(this.oldVersion)) {
|
if (filePath.isFile() && newestVersion.equals(oldVersion)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//The new jar file could not be downloaded
|
//The new jar file could not be downloaded
|
||||||
if (!downloadFile(fullURL, Paths.get(filePath.toURI()))) {
|
if (!downloadFile(fullURL, Paths.get(filePath.toURI()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
versionUpdateFunction.accept(newestVersion);
|
versionUpdateFunction.accept(version, newestVersion);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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-
|
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
|
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-
|
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/
|
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;Latest;https://papermc.io/api/v1/travertine/1.16;"latest":";";https://papermc.io/api/v1/travertine/1.16/
|
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;;
|
Custom;;
|
Can't render this file because it contains an unexpected character in line 1 and column 193.
|
@ -23,14 +23,19 @@ public class ServerVersionContainerTest {
|
|||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
File versionFileFile = new File(versionFile);
|
||||||
|
if (versionFileFile.exists() && !versionFileFile.delete()) {
|
||||||
|
throw new IllegalArgumentException("Unable to remove old version file.");
|
||||||
|
}
|
||||||
serverVersionContainer = ServerVersionContainer.getInstance();
|
serverVersionContainer = ServerVersionContainer.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toStringTest() {
|
public void toStringTest() {
|
||||||
serverVersionContainer.reset();
|
serverVersionContainer.reset();
|
||||||
assertEquals("vanillaVersion;null\nsnapshotVersion;null\nbungeeVersion;null\nwaterfallVersion;null\n" +
|
System.out.println(serverVersionContainer.toString());
|
||||||
"travertineVersion;null\nspongeVanillaVersions;",
|
assertEquals("vanillaVersion;null\nsnapshotVersion;null\nbungeeVersion;null\nwaterfallVersions;\n" +
|
||||||
|
"travertineVersions;\nspongeVanillaVersions;\nspongeForgeVersions;",
|
||||||
serverVersionContainer.toString());
|
serverVersionContainer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user