Use the Sponge DownloadAPI instead of Maven for version searching

This commit is contained in:
ME1312 2018-10-22 19:25:42 -04:00
parent d3ea124351
commit 207eca411e
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
7 changed files with 20 additions and 49 deletions

View File

@ -1,4 +1,4 @@
name: SubServers-Bungee
main: net.ME1312.SubServers.Bungee.Library.Compatibility.Plugin
version: x.x.xx
version: 2.XX.Xx
author: ME1312

View File

@ -1,5 +1,6 @@
package net.ME1312.SubServers.Bungee.Host.Internal;
import com.google.gson.Gson;
import net.ME1312.SubServers.Bungee.Event.SubCreateEvent;
import net.ME1312.SubServers.Bungee.Host.*;
import net.ME1312.SubServers.Bungee.Library.*;
@ -82,16 +83,14 @@ public class InternalSubCreator extends SubCreator {
Util.copyDirectory(template.getDirectory(), dir);
if (template.getType() == ServerType.FORGE || template.getType() == ServerType.SPONGE) {
System.out.println(name + File.separator + "Creator > Searching Versions...");
Document spongexml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://repo.spongepowered.org/maven/org/spongepowered/sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "/maven-metadata.xml").openStream(), Charset.forName("UTF-8")))))));
YAMLSection spversionmanifest = new YAMLSection(new Gson().fromJson("{\"versions\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://dl-api.spongepowered.org/v1/org.spongepowered/sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "/downloads?type=stable&minecraft=" + version).openStream(), Charset.forName("UTF-8")))) + '}', Map.class));
NodeList spnodeList = spongexml.getElementsByTagName("version");
YAMLSection spprofile = null;
Version spversion = null;
for (int i = 0; i < spnodeList.getLength(); i++) {
Node node = spnodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getTextContent().startsWith(version.toString() + '-') && (spversion == null || new Version(node.getTextContent()).compareTo(spversion) >= 0)) {
spversion = new Version(node.getTextContent());
}
for (YAMLSection profile : spversionmanifest.getSectionList("versions")) {
if (profile.getSection("dependencies").getRawString("minecraft").equalsIgnoreCase(version.toString()) && (spversion == null || new Version(profile.getRawString("version")).compareTo(spversion) >= 0)) {
spprofile = profile;
spversion = new Version(profile.getRawString("version"));
}
}
if (spversion == null)
@ -99,20 +98,7 @@ public class InternalSubCreator extends SubCreator {
System.out.println(name + File.separator + "Creator > Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"');
if (template.getType() == ServerType.FORGE) {
Document forgexml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/maven-metadata.xml").openStream(), Charset.forName("UTF-8")))))));
NodeList mcfnodeList = forgexml.getElementsByTagName("version");
Version mcfversion = null;
for (int i = 0; i < mcfnodeList.getLength(); i++) {
Node node = mcfnodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getTextContent().contains(spversion.toString().split("\\-")[1]) && (mcfversion == null || new Version(node.getTextContent()).compareTo(mcfversion) >= 0)) {
mcfversion = new Version(node.getTextContent());
}
}
}
if (mcfversion == null)
throw new InvalidServerException("Cannot find Forge version for Sponge " + spversion.toString());
Version mcfversion = new Version(spprofile.getSection("dependencies").getRawString("minecraft") + '-' + spprofile.getSection("dependencies").getRawString("forge"));
System.out.println(name + File.separator + "Creator > Found \"forge-" + mcfversion.toString() + '"');
version = new Version(mcfversion.toString() + " " + spversion.toString());

View File

@ -7,4 +7,4 @@ Template:
Shell-Location: 'build.sh'
Permission: '+x'
Settings:
Executable: 'java -Xmx1024M -Dorg.bukkit.craftbukkit.libs.jline.terminal=unix -Djansi.passthrough=true -jar Spigot.jar'
Executable: 'java -Xmx1024M -Dorg.bukkit.craftbukkit.libs.jline.terminal=unix -Djansi.passthrough=true -jar Spigot.jar'

View File

@ -57,7 +57,7 @@ public final class SubPlugin extends BungeeCord implements Listener {
public final SubAPI api = new SubAPI(this);
public SubDataServer subdata = null;
public SubServer sudo = null;
public static final Version version = Version.fromString("2.13.1b");
public static final Version version = Version.fromString("2.13.2a");
public Proxy redis = null;
public boolean canSudo = false;

View File

@ -1,6 +1,6 @@
name: 'SubServers-Client-Bukkit'
main: 'net.ME1312.SubServers.Client.Bukkit.SubPlugin'
version: '2.13.1b'
version: '2.13.2a'
authors: [ME1312]
softdepend: [Vault, TitleManager]
website: 'https://github.com/ME1312/SubServers-2'

View File

@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit;
/**
* SubServers Client Plugin Class
*/
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.13.1b", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
@Plugin(id = "subservers-client-sponge", name = "SubServers-Client-Sponge", authors = "ME1312", version = "2.13.2a", url = "https://github.com/ME1312/SubServers-2", description = "Access your SubServers from Anywhere")
public final class SubPlugin {
protected NamedContainer<Long, Map<String, Map<String, String>>> lang = null;
public YAMLConfig config;

View File

@ -231,16 +231,14 @@ public class SubCreator {
if (template.getType() == ServerType.FORGE || template.getType() == ServerType.SPONGE) {
log.logger.info.println("Searching Versions...");
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Searching Versions..."));
Document spongexml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://repo.spongepowered.org/maven/org/spongepowered/sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "/maven-metadata.xml").openStream(), Charset.forName("UTF-8")))))));
YAMLSection spversionmanifest = new YAMLSection(new JSONObject("{\"versions\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://dl-api.spongepowered.org/v1/org.spongepowered/sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "/downloads?type=stable&minecraft=" + version).openStream(), Charset.forName("UTF-8")))) + '}'));
NodeList spnodeList = spongexml.getElementsByTagName("version");
YAMLSection spprofile = null;
Version spversion = null;
for (int i = 0; i < spnodeList.getLength(); i++) {
Node node = spnodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getTextContent().startsWith(version.toString() + '-') && (spversion == null || new Version(node.getTextContent()).compareTo(spversion) >= 0)) {
spversion = new Version(node.getTextContent());
}
for (YAMLSection profile : spversionmanifest.getSectionList("versions")) {
if (profile.getSection("dependencies").getRawString("minecraft").equalsIgnoreCase(version.toString()) && (spversion == null || new Version(profile.getRawString("version")).compareTo(spversion) >= 0)) {
spprofile = profile;
spversion = new Version(profile.getRawString("version"));
}
}
if (spversion == null)
@ -249,20 +247,7 @@ public class SubCreator {
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Found \"sponge" + ((template.getType() == ServerType.FORGE)?"forge":"vanilla") + "-" + spversion.toString() + '"'));
if (template.getType() == ServerType.FORGE) {
Document forgexml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("http://files.minecraftforge.net/maven/net/minecraftforge/forge/maven-metadata.xml").openStream(), Charset.forName("UTF-8")))))));
NodeList mcfnodeList = forgexml.getElementsByTagName("version");
Version mcfversion = null;
for (int i = 0; i < mcfnodeList.getLength(); i++) {
Node node = mcfnodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getTextContent().contains(spversion.toString().split("\\-")[1]) && (mcfversion == null || new Version(node.getTextContent()).compareTo(mcfversion) >= 0)) {
mcfversion = new Version(node.getTextContent());
}
}
}
if (mcfversion == null)
throw new InvalidServerException("Cannot find Forge version for Sponge " + spversion.toString());
Version mcfversion = new Version(spprofile.getSection("dependencies").getRawString("minecraft") + '-' + spprofile.getSection("dependencies").getRawString("forge"));
log.logger.info.println("Found \"forge-" + mcfversion.toString() + '"');
host.subdata.sendPacket(new PacketOutExLogMessage(address, "Found \"forge-" + mcfversion.toString() + '"'));