diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java index 00ab50df..04104bbc 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/Host/Internal/InternalSubServer.java @@ -83,7 +83,8 @@ public class InternalSubServer extends SubServerContainer { JarInputStream updated = new JarInputStream(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/client.jar")); JarFile existing = new JarFile(new UniversalFile(this.directory, "plugins:SubServers.Client.jar")); - if (existing.getManifest().getMainAttributes().getValue("Implementation-Title") != null && existing.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && existing.getManifest().getMainAttributes().getValue("Specification-Title") != null) { + if (existing.getManifest().getMainAttributes().getValue("Implementation-Title") != null && existing.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && existing.getManifest().getMainAttributes().getValue("Specification-Title") != null && + updated.getManifest().getMainAttributes().getValue("Implementation-Title") != null && updated.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && updated.getManifest().getMainAttributes().getValue("Specification-Title") != null) { if (new Version(existing.getManifest().getMainAttributes().getValue("Specification-Title")).compareTo(new Version(updated.getManifest().getMainAttributes().getValue("Specification-Title"))) < 0) { new UniversalFile(this.directory, "plugins:SubServers.Client.jar").delete(); Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(this.directory, "plugins:SubServers.Client.jar").getPath()); @@ -100,7 +101,8 @@ public class InternalSubServer extends SubServerContainer { JarInputStream updated = new JarInputStream(SubPlugin.class.getResourceAsStream("/net/ME1312/SubServers/Bungee/Library/Files/client.jar")); JarFile existing = new JarFile(new UniversalFile(this.directory, "mods:SubServers.Client.jar")); - if (existing.getManifest().getMainAttributes().getValue("Implementation-Title") != null && existing.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && existing.getManifest().getMainAttributes().getValue("Specification-Title") != null) { + if (existing.getManifest().getMainAttributes().getValue("Implementation-Title") != null && existing.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && existing.getManifest().getMainAttributes().getValue("Specification-Title") != null && + updated.getManifest().getMainAttributes().getValue("Implementation-Title") != null && updated.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && updated.getManifest().getMainAttributes().getValue("Specification-Title") != null) { if (new Version(existing.getManifest().getMainAttributes().getValue("Specification-Title")).compareTo(new Version(updated.getManifest().getMainAttributes().getValue("Specification-Title"))) < 0) { new UniversalFile(this.directory, "mods:SubServers.Client.jar").delete(); Util.copyFromJar(SubPlugin.class.getClassLoader(), "net/ME1312/SubServers/Bungee/Library/Files/client.jar", new UniversalFile(this.directory, "mods:SubServers.Client.jar").getPath()); diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java index 957db928..f453e43f 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubCommand.java @@ -1,10 +1,12 @@ package net.ME1312.SubServers.Bungee; +import com.google.gson.Gson; import net.ME1312.SubServers.Bungee.Host.Host; import net.ME1312.SubServers.Bungee.Host.Server; import net.ME1312.SubServers.Bungee.Host.SubCreator; import net.ME1312.SubServers.Bungee.Host.SubServer; import net.ME1312.SubServers.Bungee.Library.Compatibility.CommandX; +import net.ME1312.SubServers.Bungee.Library.Config.YAMLSection; import net.ME1312.SubServers.Bungee.Library.NamedContainer; import net.ME1312.SubServers.Bungee.Library.Util; import net.ME1312.SubServers.Bungee.Library.Version.Version; @@ -62,6 +64,7 @@ public final class SubCommand extends CommandX { * @param sender Sender * @param args Arguments */ + @SuppressWarnings("unchecked") public void execute(CommandSender sender, String[] args) { if (sender instanceof ConsoleCommandSender) { if (args.length > 0) { @@ -84,18 +87,15 @@ public final class SubCommand extends CommandX { sender.sendMessage(""); new Thread(() -> { try { - Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Bungee/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); + YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class)); - NodeList updnodeList = updxml.getElementsByTagName("version"); Version updversion = plugin.version; int updcount = 0; - for (int i = 0; i < updnodeList.getLength(); i++) { - Node node = updnodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(plugin.version.toString()) && Version.fromString(node.getTextContent()).compareTo(updversion) > 0) { - updversion = Version.fromString(node.getTextContent()); - updcount++; - } + for (YAMLSection tag : tags.getSectionList("tags")) { + Version version = Version.fromString(tag.getString("ref").substring(10)); + if (!version.equals(version) && version.compareTo(updversion) > 0) { + updversion = version; + updcount++; } } if (updcount == 0) { diff --git a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java index 37b9f8ac..522fa55f 100644 --- a/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java +++ b/SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java @@ -59,7 +59,7 @@ public final class SubPlugin extends BungeeCord implements Listener { public SubDataServer subdata = null; public SubServer sudo = null; //public static final Version version = Version.fromString("2.13a/pr5"); - public static final Version version = new Version(Version.fromString("2.13a/pr5"), VersionType.SNAPSHOT, (SubPlugin.class.getPackage().getSpecificationTitle() == null)?"undefined":SubPlugin.class.getPackage().getSpecificationTitle()); // TODO Snapshot Version + public static final Version version = new Version(Version.fromString("2.13a/pr5"), VersionType.SNAPSHOT, (SubPlugin.class.getPackage().getSpecificationTitle() == null)?"custom":SubPlugin.class.getPackage().getSpecificationTitle()); // TODO Snapshot Version public boolean redis = false; public boolean canSudo = false; @@ -503,21 +503,19 @@ public final class SubPlugin extends BungeeCord implements Listener { new Metrics(this); new Timer().schedule(new TimerTask() { + @SuppressWarnings("unchecked") @Override public void run() { try { - Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Bungee/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); + YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class)); - NodeList updnodeList = updxml.getElementsByTagName("version"); Version updversion = version; int updcount = 0; - for (int i = 0; i < updnodeList.getLength(); i++) { - Node node = updnodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(version.toString()) && Version.fromString(node.getTextContent()).compareTo(updversion) > 0) { - updversion = Version.fromString(node.getTextContent()); - updcount++; - } + for (YAMLSection tag : tags.getSectionList("tags")) { + Version version = Version.fromString(tag.getString("ref").substring(10)); + if (!version.equals(version) && version.compareTo(updversion) > 0) { + updversion = version; + updcount++; } } if (updcount > 0) System.out.println("SubServers > SubServers.Bungee v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind."); diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java index 5dd1baf9..b53d8b81 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubCommand.java @@ -1,6 +1,8 @@ package net.ME1312.SubServers.Client.Bukkit; +import com.google.gson.Gson; import net.ME1312.SubServers.Client.Bukkit.Graphic.UIRenderer; +import net.ME1312.SubServers.Client.Bukkit.Library.Config.YAMLSection; import net.ME1312.SubServers.Client.Bukkit.Library.Container; import net.ME1312.SubServers.Client.Bukkit.Library.Util; import net.ME1312.SubServers.Client.Bukkit.Library.Version.Version; @@ -35,6 +37,7 @@ public final class SubCommand implements CommandExecutor { this.plugin = plugin; } + @SuppressWarnings("unchecked") @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { label = "/" + label; @@ -66,18 +69,15 @@ public final class SubCommand implements CommandExecutor { sender.sendMessage(""); Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { try { - Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Client.Bukkit/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); + YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class)); - NodeList updnodeList = updxml.getElementsByTagName("version"); Version updversion = plugin.version; int updcount = 0; - for (int i = 0; i < updnodeList.getLength(); i++) { - Node node = updnodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(plugin.version.toString()) && Version.fromString(node.getTextContent()).compareTo(updversion) > 0) { - updversion = Version.fromString(node.getTextContent()); - updcount++; - } + for (YAMLSection tag : tags.getSectionList("tags")) { + Version version = Version.fromString(tag.getString("ref").substring(10)); + if (!version.equals(version) && version.compareTo(updversion) > 0) { + updversion = version; + updcount++; } } if (updcount == 0) { diff --git a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java index 2ff26422..a1332f88 100644 --- a/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java +++ b/SubServers.Client/Bukkit/src/net/ME1312/SubServers/Client/Bukkit/SubPlugin.java @@ -47,7 +47,7 @@ public final class SubPlugin extends JavaPlugin { public SubPlugin() { super(); //version = Version.fromString(getDescription().getVersion()); - version = new Version(Version.fromString(getDescription().getVersion()), VersionType.SNAPSHOT, (SubPlugin.class.getPackage().getSpecificationTitle() == null)?"undefined":SubPlugin.class.getPackage().getSpecificationTitle()); // TODO Snapshot Version + version = new Version(Version.fromString(getDescription().getVersion()), VersionType.SNAPSHOT, (SubPlugin.class.getPackage().getSpecificationTitle() == null)?"custom":SubPlugin.class.getPackage().getSpecificationTitle()); // TODO Snapshot Version } /** @@ -94,18 +94,15 @@ public final class SubPlugin extends JavaPlugin { new Metrics(this); Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> { try { - Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Client.Bukkit/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); + YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class)); - NodeList updnodeList = updxml.getElementsByTagName("version"); Version updversion = version; int updcount = 0; - for (int i = 0; i < updnodeList.getLength(); i++) { - Node node = updnodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(version.toString()) && Version.fromString(node.getTextContent()).compareTo(updversion) > 0) { - updversion = Version.fromString(node.getTextContent()); - updcount++; - } + for (YAMLSection tag : tags.getSectionList("tags")) { + Version version = Version.fromString(tag.getString("ref").substring(10)); + if (!version.equals(version) && version.compareTo(updversion) > 0) { + updversion = version; + updcount++; } } if (updcount > 0) Bukkit.getLogger().info("SubServers > SubServers.Client.Bukkit v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind."); diff --git a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubCommand.java b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubCommand.java index 5c04edfb..865cca8e 100644 --- a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubCommand.java +++ b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubCommand.java @@ -1,6 +1,8 @@ package net.ME1312.SubServers.Client.Sponge; +import com.google.gson.Gson; import net.ME1312.SubServers.Client.Sponge.Graphic.UIRenderer; +import net.ME1312.SubServers.Client.Sponge.Library.Config.YAMLSection; import net.ME1312.SubServers.Client.Sponge.Library.Util; import net.ME1312.SubServers.Client.Sponge.Library.Version.Version; import net.ME1312.SubServers.Client.Sponge.Library.Version.VersionType; @@ -151,6 +153,7 @@ public final class SubCommand implements CommandExecutor { } public final class VERSION implements CommandExecutor { + @SuppressWarnings("unchecked") public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException { if (canRun(sender)) { boolean build = false; @@ -170,18 +173,15 @@ public final class SubCommand implements CommandExecutor { sender.sendMessage(Text.EMPTY); plugin.game.getScheduler().createTaskBuilder().async().execute(() -> { try { - Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Client.Sponge/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); + YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class)); - NodeList updnodeList = updxml.getElementsByTagName("version"); Version updversion = plugin.version; int updcount = 0; - for (int i = 0; i < updnodeList.getLength(); i++) { - Node node = updnodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(plugin.version.toString()) && Version.fromString(node.getTextContent()).compareTo(updversion) > 0) { - updversion = Version.fromString(node.getTextContent()); - updcount++; - } + for (YAMLSection tag : tags.getSectionList("tags")) { + Version version = Version.fromString(tag.getString("ref").substring(10)); + if (!version.equals(version) && version.compareTo(updversion) > 0) { + updversion = version; + updcount++; } } if (updcount == 0) { diff --git a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubPlugin.java b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubPlugin.java index f9056144..9d27e3c4 100644 --- a/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubPlugin.java +++ b/SubServers.Client/Sponge/src/net/ME1312/SubServers/Client/Sponge/SubPlugin.java @@ -63,8 +63,8 @@ public final class SubPlugin { public void setup(GamePreInitializationEvent event) { if (plugin.getVersion().isPresent()) { //version = Version.fromString(plugin.getVersion().get()); - version = new Version(Version.fromString(plugin.getVersion().get()), VersionType.SNAPSHOT, (SubPlugin.class.getPackage().getSpecificationTitle() == null)?"undefined":SubPlugin.class.getPackage().getSpecificationTitle()); // TODO Snapshot Version - } else version = new Version("undefined"); + version = new Version(Version.fromString(plugin.getVersion().get()), VersionType.SNAPSHOT, (SubPlugin.class.getPackage().getSpecificationTitle() == null)?"custom":SubPlugin.class.getPackage().getSpecificationTitle()); // TODO Snapshot Version + } else version = new Version("Custom"); } /** @@ -109,18 +109,15 @@ public final class SubPlugin { new Metrics(this); game.getScheduler().createTaskBuilder().async().execute(() -> { try { - Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Client.Sponge/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); + YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class)); - NodeList updnodeList = updxml.getElementsByTagName("version"); Version updversion = version; int updcount = 0; - for (int i = 0; i < updnodeList.getLength(); i++) { - Node node = updnodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(version.toString()) && Version.fromString(node.getTextContent()).compareTo(updversion) > 0) { - updversion = Version.fromString(node.getTextContent()); - updcount++; - } + for (YAMLSection tag : tags.getSectionList("tags")) { + Version version = Version.fromString(tag.getString("ref").substring(10)); + if (!version.equals(version) && version.compareTo(updversion) > 0) { + updversion = version; + updcount++; } } if (updcount > 0) logger.info("SubServers.Client.Sponge v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind."); diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java b/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java index 70134bca..f05f4321 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/ExHost.java @@ -56,7 +56,7 @@ public final class ExHost { public final SubAPI api = new SubAPI(this); //public static final Version version = Version.fromString("2.13a/pr5"); - public static final Version version = new Version(Version.fromString("2.13a/pr5"), VersionType.SNAPSHOT, (ExHost.class.getPackage().getSpecificationTitle() == null)?"undefined":ExHost.class.getPackage().getSpecificationTitle()); // TODO Snapshot Version + public static final Version version = new Version(Version.fromString("2.13a/pr5"), VersionType.SNAPSHOT, (ExHost.class.getPackage().getSpecificationTitle() == null)?"custom":ExHost.class.getPackage().getSpecificationTitle()); // TODO Snapshot Version private ConsoleReader jline; private boolean running = false; @@ -416,18 +416,15 @@ public final class ExHost { @Override public void run() { try { - Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Host/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); + YAMLSection tags = new YAMLSection(new JSONObject("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}')); - NodeList updnodeList = updxml.getElementsByTagName("version"); Version updversion = version; int updcount = 0; - for (int i = 0; i < updnodeList.getLength(); i++) { - Node node = updnodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(version.toString()) && Version.fromString(node.getTextContent()).compareTo(updversion) > 0) { - updversion = Version.fromString(node.getTextContent()); - updcount++; - } + for (YAMLSection tag : tags.getSectionList("tags")) { + Version version = Version.fromString(tag.getString("ref").substring(10)); + if (!version.equals(version) && version.compareTo(updversion) > 0) { + updversion = version; + updcount++; } } if (updcount > 0) log.info.println("SubServers.Host v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind."); diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServer.java b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServer.java index 1a3c6da1..73554614 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServer.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/Executable/SubServer.java @@ -68,7 +68,8 @@ public class SubServer { JarInputStream updated = new JarInputStream(ExHost.class.getResourceAsStream("/net/ME1312/SubServers/Host/Library/Files/client.jar")); JarFile existing = new JarFile(new UniversalFile(this.directory, "plugins:SubServers.Client.jar")); - if (existing.getManifest().getMainAttributes().getValue("Implementation-Title") != null && existing.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && existing.getManifest().getMainAttributes().getValue("Specification-Title") != null) { + if (existing.getManifest().getMainAttributes().getValue("Implementation-Title") != null && existing.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && existing.getManifest().getMainAttributes().getValue("Specification-Title") != null && + updated.getManifest().getMainAttributes().getValue("Implementation-Title") != null && updated.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && updated.getManifest().getMainAttributes().getValue("Specification-Title") != null) { if (new Version(existing.getManifest().getMainAttributes().getValue("Specification-Title")).compareTo(new Version(updated.getManifest().getMainAttributes().getValue("Specification-Title"))) < 0) { new UniversalFile(this.directory, "plugins:SubServers.Client.jar").delete(); Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/client.jar", new UniversalFile(this.directory, "plugins:SubServers.Client.jar").getPath()); @@ -85,7 +86,8 @@ public class SubServer { JarInputStream updated = new JarInputStream(ExHost.class.getResourceAsStream("/net/ME1312/SubServers/Host/Library/Files/client.jar")); JarFile existing = new JarFile(new UniversalFile(this.directory, "mods:SubServers.Client.jar")); - if (existing.getManifest().getMainAttributes().getValue("Implementation-Title") != null && existing.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && existing.getManifest().getMainAttributes().getValue("Specification-Title") != null) { + if (existing.getManifest().getMainAttributes().getValue("Implementation-Title") != null && existing.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && existing.getManifest().getMainAttributes().getValue("Specification-Title") != null && + updated.getManifest().getMainAttributes().getValue("Implementation-Title") != null && updated.getManifest().getMainAttributes().getValue("Implementation-Title").startsWith("SubServers.Client") && updated.getManifest().getMainAttributes().getValue("Specification-Title") != null) { if (new Version(existing.getManifest().getMainAttributes().getValue("Specification-Title")).compareTo(new Version(updated.getManifest().getMainAttributes().getValue("Specification-Title"))) < 0) { new UniversalFile(this.directory, "mods:SubServers.Client.jar").delete(); Util.copyFromJar(ExHost.class.getClassLoader(), "net/ME1312/SubServers/Host/Library/Files/client.jar", new UniversalFile(this.directory, "mods:SubServers.Client.jar").getPath()); diff --git a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java index fb9e302c..6565d80e 100644 --- a/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java +++ b/SubServers.Host/src/net/ME1312/SubServers/Host/SubCommand.java @@ -2,11 +2,13 @@ package net.ME1312.SubServers.Host; import net.ME1312.SubServers.Host.API.Command; import net.ME1312.SubServers.Host.API.SubPluginInfo; +import net.ME1312.SubServers.Host.Library.Config.YAMLSection; import net.ME1312.SubServers.Host.Library.TextColor; import net.ME1312.SubServers.Host.Library.Util; import net.ME1312.SubServers.Host.Library.Version.Version; import net.ME1312.SubServers.Host.Library.Version.VersionType; import net.ME1312.SubServers.Host.Network.Packet.*; +import org.json.JSONObject; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -48,18 +50,15 @@ public class SubCommand { host.log.message.println(""); new Thread(() -> { try { - Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Host/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); + YAMLSection tags = new YAMLSection(new JSONObject("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}')); - NodeList updnodeList = updxml.getElementsByTagName("version"); Version updversion = host.version; int updcount = 0; - for (int i = 0; i < updnodeList.getLength(); i++) { - Node node = updnodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(host.version.toString()) && Version.fromString(node.getTextContent()).compareTo(updversion) > 0) { - updversion = Version.fromString(node.getTextContent()); - updcount++; - } + for (YAMLSection tag : tags.getSectionList("tags")) { + Version version = Version.fromString(tag.getString("ref").substring(10)); + if (!version.equals(version) && version.compareTo(updversion) > 0) { + updversion = version; + updcount++; } } if (updcount == 0) { diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java index 1a1fc471..083ac538 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubCommand.java @@ -1,6 +1,8 @@ package net.ME1312.SubServers.Sync; +import com.google.gson.Gson; import net.ME1312.SubServers.Sync.Library.Compatibility.CommandX; +import net.ME1312.SubServers.Sync.Library.Config.YAMLSection; import net.ME1312.SubServers.Sync.Library.NamedContainer; import net.ME1312.SubServers.Sync.Library.Util; import net.ME1312.SubServers.Sync.Library.Version.Version; @@ -56,6 +58,7 @@ public final class SubCommand extends CommandX { this.label = '/' + command; } + @SuppressWarnings("unchecked") @Override public void execute(CommandSender sender, String[] args) { if (sender instanceof ConsoleCommandSender) { @@ -84,18 +87,15 @@ public final class SubCommand extends CommandX { sender.sendMessage(""); new Thread(() -> { try { - Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Sync/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); + YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class)); - NodeList updnodeList = updxml.getElementsByTagName("version"); Version updversion = plugin.version; int updcount = 0; - for (int i = 0; i < updnodeList.getLength(); i++) { - Node node = updnodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(plugin.version.toString()) && Version.fromString(node.getTextContent()).compareTo(updversion) > 0) { - updversion = Version.fromString(node.getTextContent()); - updcount++; - } + for (YAMLSection tag : tags.getSectionList("tags")) { + Version version = Version.fromString(tag.getString("ref").substring(10)); + if (!version.equals(version) && version.compareTo(updversion) > 0) { + updversion = version; + updcount++; } } if (updcount == 0) { diff --git a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java index 3ec738a1..f663dbde 100644 --- a/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java +++ b/SubServers.Sync/src/net/ME1312/SubServers/Sync/SubPlugin.java @@ -1,5 +1,6 @@ package net.ME1312.SubServers.Sync; +import com.google.gson.Gson; import net.ME1312.SubServers.Sync.Event.*; import net.ME1312.SubServers.Sync.Library.Config.YAMLConfig; import net.ME1312.SubServers.Sync.Library.Config.YAMLSection; @@ -49,7 +50,7 @@ public final class SubPlugin extends BungeeCord implements Listener { public final SubAPI api = new SubAPI(this); public SubDataClient subdata = null; //public static final Version version = Version.fromString("2.13a/pr5"); - public static final Version version = new Version(Version.fromString("2.13a/pr5"), VersionType.SNAPSHOT, (SubPlugin.class.getPackage().getSpecificationTitle() == null)?"undefined":SubPlugin.class.getPackage().getSpecificationTitle()); // TODO Snapshot Version + public static final Version version = new Version(Version.fromString("2.13a/pr5"), VersionType.SNAPSHOT, (SubPlugin.class.getPackage().getSpecificationTitle() == null)?"custom":SubPlugin.class.getPackage().getSpecificationTitle()); // TODO Snapshot Version public final boolean isPatched; public long lastReload = -1; @@ -129,21 +130,19 @@ public final class SubPlugin extends BungeeCord implements Listener { new Metrics(this); new Timer().schedule(new TimerTask() { + @SuppressWarnings("unchecked") @Override public void run() { try { - Document updxml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://src.me1312.net/maven/net/ME1312/SubServers/SubServers.Sync/maven-metadata.xml").openStream(), Charset.forName("UTF-8"))))))); + YAMLSection tags = new YAMLSection(new Gson().fromJson("{\"tags\":" + Util.readAll(new BufferedReader(new InputStreamReader(new URL("https://api.github.com/repos/ME1312/SubServers-2/git/refs/tags").openStream(), Charset.forName("UTF-8")))) + '}', Map.class)); - NodeList updnodeList = updxml.getElementsByTagName("version"); Version updversion = version; int updcount = 0; - for (int i = 0; i < updnodeList.getLength(); i++) { - Node node = updnodeList.item(i); - if (node.getNodeType() == Node.ELEMENT_NODE) { - if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(version.toString()) && Version.fromString(node.getTextContent()).compareTo(updversion) > 0) { - updversion = Version.fromString(node.getTextContent()); - updcount++; - } + for (YAMLSection tag : tags.getSectionList("tags")) { + Version version = Version.fromString(tag.getString("ref").substring(10)); + if (!version.equals(version) && version.compareTo(updversion) > 0) { + updversion = version; + updcount++; } } if (updcount > 0) System.out.println("SubServers > SubServers.Sync v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");