Fix the update notification

This commit is contained in:
ME1312 2018-07-27 15:36:51 -04:00
parent c742490956
commit 47a9ae4ced
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
12 changed files with 91 additions and 100 deletions

View File

@ -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());

View File

@ -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,20 +87,17 @@ 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());
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) {
sender.sendMessage("You are on the latest version.");
} else {

View File

@ -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,23 +503,21 @@ 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());
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.");
} catch (Exception e) {}
}

View File

@ -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,20 +69,17 @@ 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());
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) {
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Version.Latest"));
} else {

View File

@ -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,20 +94,17 @@ 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());
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.");
} catch (Exception e) {}
}, 0, TimeUnit.DAYS.toSeconds(2) * 20);

View File

@ -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,20 +173,17 @@ 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());
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) {
sender.sendMessage(Text.of(plugin.api.getLang("SubServers", "Command.Version.Latest")));
} else {

View File

@ -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,20 +109,17 @@ 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());
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.");
} catch (Exception e) {}
}).delay(0, TimeUnit.MILLISECONDS).interval(2, TimeUnit.DAYS).submit(plugin);

View File

@ -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,20 +416,17 @@ 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());
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.");
} catch (Exception e) {}
}

View File

@ -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());

View File

@ -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,20 +50,17 @@ 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());
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) {
host.log.message.println("You are on the latest version.");
} else {

View File

@ -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,20 +87,17 @@ 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());
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) {
sender.sendMessage("You are on the latest version.");
} else {

View File

@ -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,23 +130,21 @@ 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());
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.");
} catch (Exception e) {}
}