Skip to content

Commit

Permalink
Fix the update notification
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Jul 27, 2018
1 parent c742490 commit 47a9ae4
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 100 deletions.
Expand Up @@ -83,7 +83,8 @@ public InternalSubServer(InternalHost host, String name, boolean enabled, int po
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());
Expand All @@ -100,7 +101,8 @@ public InternalSubServer(InternalHost host, String name, boolean enabled, int po
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());
Expand Down
@@ -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;
Expand Down Expand Up @@ -62,6 +64,7 @@ private SubCommand(SubPlugin plugin, String command) {
* @param sender Sender
* @param args Arguments
*/
@SuppressWarnings("unchecked")
public void execute(CommandSender sender, String[] args) {
if (sender instanceof ConsoleCommandSender) {
if (args.length > 0) {
Expand All @@ -84,18 +87,15 @@ public void execute(CommandSender sender, String[] args) {
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) {
Expand Down
18 changes: 8 additions & 10 deletions SubServers.Bungee/src/net/ME1312/SubServers/Bungee/SubPlugin.java
Expand Up @@ -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;
Expand Down Expand Up @@ -503,21 +503,19 @@ private void post() {

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.");
Expand Down
@@ -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;
Expand Down Expand Up @@ -35,6 +37,7 @@ public SubCommand(SubPlugin plugin) {
this.plugin = plugin;
}

@SuppressWarnings("unchecked")
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
label = "/" + label;
Expand Down Expand Up @@ -66,18 +69,15 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
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) {
Expand Down
Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -94,18 +94,15 @@ public void onEnable() {
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.");
Expand Down
@@ -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;
Expand Down Expand Up @@ -151,6 +153,7 @@ public CommandResult execute(CommandSource sender, CommandContext args) throws C
}

public final class VERSION implements CommandExecutor {
@SuppressWarnings("unchecked")
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
if (canRun(sender)) {
boolean build = false;
Expand All @@ -170,18 +173,15 @@ public CommandResult execute(CommandSource sender, CommandContext args) throws C
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) {
Expand Down

0 comments on commit 47a9ae4

Please sign in to comment.