Adds the SpongeForge server type
This commit is contained in:
parent
d06cf4114a
commit
2008ec8fd1
@ -1,16 +1,6 @@
|
||||
package net.knarcraft.minecraftserverlauncher.server;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.BungeeCord;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.CraftBukkit;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Custom;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.MCPCPlus;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Paper;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Spigot;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.SpongeVanilla;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Travertine;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Vanilla;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.Waterfall;
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.*;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.io.FileNotFoundException;
|
||||
@ -146,6 +136,10 @@ public class ServerTypeHandler {
|
||||
newType = new SpongeVanilla("SpongeVanilla", false, serverVersions,
|
||||
serverTypeInfo[2], serverTypeInfo[3], serverTypeInfo[4], serverTypeInfo[5], serverTypeInfo[6]);
|
||||
break;
|
||||
case "SpongeForge":
|
||||
newType = new SpongeForge("SpongeForge", false, serverVersions,
|
||||
serverTypeInfo[2], serverTypeInfo[3], serverTypeInfo[4], serverTypeInfo[5], serverTypeInfo[6]);
|
||||
break;
|
||||
case "Custom":
|
||||
newType = new Custom("Custom");
|
||||
break;
|
||||
|
@ -20,12 +20,14 @@ public class ServerVersionContainer {
|
||||
private String waterfallVersion;
|
||||
private String travertineVersion;
|
||||
private Map<String, String> spongeVanillaVersions;
|
||||
private Map<String, String> spongeForgeVersions;
|
||||
|
||||
/**
|
||||
* Initializes a new server version container
|
||||
*/
|
||||
private ServerVersionContainer() {
|
||||
spongeVanillaVersions = new HashMap<>();
|
||||
spongeForgeVersions = new HashMap<>();
|
||||
loadState();
|
||||
}
|
||||
|
||||
@ -51,6 +53,7 @@ public class ServerVersionContainer {
|
||||
this.waterfallVersion = null;
|
||||
this.travertineVersion = null;
|
||||
this.spongeVanillaVersions = new HashMap<>();
|
||||
this.spongeForgeVersions = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,8 +63,8 @@ public class ServerVersionContainer {
|
||||
"bungeeVersion;" + bungeeVersion + "\n" +
|
||||
"waterfallVersion;" + waterfallVersion + "\n" +
|
||||
"travertineVersion;" + travertineVersion + "\n" +
|
||||
"spongeVanillaVersions;" +
|
||||
mapToString(spongeVanillaVersions);
|
||||
"spongeVanillaVersions;" + mapToString(spongeVanillaVersions) + "\n" +
|
||||
"spongeForgeVersions;" + mapToString(spongeForgeVersions);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,11 +95,9 @@ public class ServerVersionContainer {
|
||||
PrintWriter file;
|
||||
try {
|
||||
if (!saveFile.exists()) {
|
||||
if (!saveFile.getParentFile().exists()) {
|
||||
if (!saveFile.getParentFile().mkdirs()) {
|
||||
if (!saveFile.getParentFile().exists() && !saveFile.getParentFile().mkdirs()) {
|
||||
throw new FileNotFoundException("Unable to create folder for version file");
|
||||
}
|
||||
}
|
||||
if (!saveFile.createNewFile()) {
|
||||
throw new FileNotFoundException("Unable to create version file");
|
||||
}
|
||||
@ -157,7 +158,10 @@ public class ServerVersionContainer {
|
||||
travertineVersion = variableValue;
|
||||
break;
|
||||
case "spongeVanillaVersions":
|
||||
parseSpongeVanillaVersions(variableValue);
|
||||
parseSpongeVersions(spongeVanillaVersions, variableValue);
|
||||
break;
|
||||
case "spongeForgeVersions":
|
||||
parseSpongeVersions(spongeForgeVersions, variableValue);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid key encountered in the server version file.");
|
||||
@ -165,15 +169,16 @@ public class ServerVersionContainer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads spongeVanilla versions from a text string and updates the version map
|
||||
* Reads sponge 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 parseSpongeVanillaVersions(String data) {
|
||||
private void parseSpongeVersions(Map<String,String> targetMap, String data) {
|
||||
String[] versions = data.split(",");
|
||||
for (String version : versions) {
|
||||
String[] versionData = version.split("!");
|
||||
spongeVanillaVersions.put(versionData[0], versionData[1]);
|
||||
targetMap.put(versionData[0], versionData[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,5 +299,25 @@ public class ServerVersionContainer {
|
||||
saveState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a specific sponge forge version
|
||||
*
|
||||
* @param versionKey <p>The version to check current version of</p>
|
||||
* @return <p>The current sponge forge version</p>
|
||||
*/
|
||||
public String getSpongeForgeVersion(String versionKey) {
|
||||
return spongeForgeVersions.get(versionKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current version for a given sponge forge version
|
||||
*
|
||||
* @param mapKey <p>The version key to set version for</p>
|
||||
* @param newValue <p>The new current version</p>
|
||||
*/
|
||||
public void setSpongeForgeVersion(String mapKey, String newValue) {
|
||||
spongeForgeVersions.put(mapKey, newValue);
|
||||
saveState();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,26 @@
|
||||
package net.knarcraft.minecraftserverlauncher.server.servertypes;
|
||||
|
||||
/**
|
||||
* This class represents the SpongeForge Minecraft server type
|
||||
*/
|
||||
public class SpongeForge extends SpongeVanilla {
|
||||
|
||||
/**
|
||||
* Instantiates a new SpongeForge server type
|
||||
*
|
||||
* @param typeName <p>The name of this server type</p>
|
||||
* @param isProxy <p>Whether this server type is a proxy server</p>
|
||||
* @param versions <p>Available versions for this server type</p>
|
||||
* @param versionURL <p>The URL used for downloading the version document</p>
|
||||
* @param srcStart <p>The string to search for to determine newest version</p>
|
||||
* @param srcEnd <p>The string marking the end of the newest version statement</p>
|
||||
* @param downloadURL <p>The URL used for downloading the new file</p>
|
||||
* @param downloadURLPart <p>A string used after the download url as an additional part of the URL</p>
|
||||
*/
|
||||
public SpongeForge(String typeName, boolean isProxy, String[] versions, String versionURL, String srcStart, String srcEnd, String downloadURL, String downloadURLPart) {
|
||||
super(typeName, isProxy, versions, versionURL, srcStart, srcEnd, downloadURL, downloadURLPart);
|
||||
this.oldVersionFunction = serverVersionContainer::getSpongeForgeVersion;
|
||||
this.versionUpdateFunction = serverVersionContainer::setSpongeForgeVersion;
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,9 @@ import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
|
||||
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;
|
||||
|
||||
@ -18,6 +21,9 @@ public class SpongeVanilla extends AbstractServerType {
|
||||
private final String srcStart;
|
||||
private final String srcEnd;
|
||||
private final String downloadURLPart;
|
||||
Function<String,String> oldVersionFunction;
|
||||
BiConsumer<String,String> versionUpdateFunction;
|
||||
final ServerVersionContainer serverVersionContainer;
|
||||
|
||||
/**
|
||||
* Instantiates a new SpongeVanilla server type
|
||||
@ -34,15 +40,17 @@ public class SpongeVanilla extends AbstractServerType {
|
||||
public SpongeVanilla(String typeName, boolean isProxy, String[] versions, String versionURL, String srcStart, String srcEnd,
|
||||
String downloadURL, String downloadURLPart) {
|
||||
super(typeName, isProxy, versions, downloadURL);
|
||||
this.serverVersionContainer = ServerVersionContainer.getInstance();
|
||||
this.versionURL = versionURL;
|
||||
this.srcStart = srcStart;
|
||||
this.srcEnd = srcEnd;
|
||||
this.downloadURLPart = downloadURLPart;
|
||||
this.oldVersionFunction = serverVersionContainer::getSpongeVanillaVersion;
|
||||
this.versionUpdateFunction = serverVersionContainer::setSpongeVanillaVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean downloadJar(String folder, String version) throws IOException {
|
||||
ServerVersionContainer versionContainer = ServerVersionContainer.getInstance();
|
||||
String file = this.getName() + version + ".jar";
|
||||
File filePath = new File(folder + file);
|
||||
|
||||
@ -51,7 +59,7 @@ public class SpongeVanilla extends AbstractServerType {
|
||||
|
||||
String jarURL = downloadURL + newestVersion + downloadURLPart + newestVersion + ".jar";
|
||||
|
||||
String oldVersion = versionContainer.getSpongeVanillaVersion(version);
|
||||
String oldVersion = this.oldVersionFunction.apply(version);
|
||||
//The file is already the newest version
|
||||
if (filePath.isFile() && newestVersion.equals(oldVersion)) {
|
||||
return true;
|
||||
@ -60,7 +68,7 @@ public class SpongeVanilla extends AbstractServerType {
|
||||
if (!downloadFile(jarURL, Paths.get(filePath.toURI()))) {
|
||||
return false;
|
||||
}
|
||||
versionContainer.setSpongeVanillaVersion(version, newestVersion);
|
||||
versionUpdateFunction.accept(version, newestVersion);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
SpongeVanilla;1.12.2,1.11.2,1.10.2,1.8.9;https://dl-api.spongepowered.org/v1/org.spongepowered/spongevanilla/downloads?type=stable&minecraft=;"version":";",;https://repo.spongepowered.org/maven/org/spongepowered/spongevanilla/;/spongevanilla-
|
||||
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-
|
||||
Spigot;1.16.1,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.9.4,1.8.8,1.7.10,1.6.4-R2.1,1.5.2-R1.1,1.4.7-R1.1;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Spigot/;spigot-
|
||||
MCPCplus;1.6.4,1.6.2,1.5.2,1.4.7;https://static.knarcraft.net/archive/downloads/minecraftserverjars/MCPC+/;mcpcplus
|
||||
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-R1.0,1.4.6-R0.3,1.3.2-R3.0,1.2.5-R2.0,1.1-R6,1.0.1-R1;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Bukkit/;craftbukkit-
|
||||
|
Can't render this file because it contains an unexpected character in line 1 and column 151.
|
@ -41,6 +41,11 @@ public class JarDownloaderTest {
|
||||
singleDownloadTest(ServerTypeHandler.getByName("SpongeVanilla"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spongeForgeDownloadTest() throws IOException, ConfigurationException {
|
||||
singleDownloadTest(ServerTypeHandler.getByName("SpongeForge"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spigotDownloadTest() throws ConfigurationException, IOException {
|
||||
singleDownloadTest(ServerTypeHandler.getByName("Spigot"));
|
||||
|
Loading…
Reference in New Issue
Block a user