mirror of
https://github.com/ME1312/SubServers-2.git
synced 2025-02-17 20:21:33 +01:00
Rewrite what compares layered versions
This commit is contained in:
parent
bb7cfa9e57
commit
12a74b3474
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -125,17 +125,6 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
this.string = string;
|
this.string = string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* The internal toString() method
|
|
||||||
* new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7") would return:
|
|
||||||
* 5 1.0.0 0 7
|
|
||||||
*/
|
|
||||||
private String toInternalString() {
|
|
||||||
String str = type.id + ' ' + string;
|
|
||||||
if (parent != null) str = parent.toInternalString()+' '+str;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default toString() method<br>
|
* The default toString() method<br>
|
||||||
* <br>
|
* <br>
|
||||||
@ -223,14 +212,27 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
* @param version The version to compare to
|
* @param version The version to compare to
|
||||||
*/
|
*/
|
||||||
public int compareTo(Version version) {
|
public int compareTo(Version version) {
|
||||||
String version1 = toInternalString();
|
// Compare parent versions first
|
||||||
String version2 = version.toInternalString();
|
if (this.parent != null || version.parent != null) {
|
||||||
|
int parent = ((this.parent == null)?this:this.parent).compareTo((version.parent == null)?version:version.parent);
|
||||||
|
if (parent != 0) return parent;
|
||||||
|
}
|
||||||
|
|
||||||
VersionTokenizer tokenizer1 = new VersionTokenizer(version1);
|
if (this.parent != null && version.parent == null) {
|
||||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version2);
|
// Version one has a parent version and version two does not, making version two the official version
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int number1 = 0, number2 = 0;
|
if (this.parent == null && version.parent != null) {
|
||||||
String suffix1 = "", suffix2 = "";
|
// Version one does not have a parent version and version two does, making version one the official version
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionTokenizer tokenizer1 = new VersionTokenizer(string);
|
||||||
|
VersionTokenizer tokenizer2 = new VersionTokenizer(version.string);
|
||||||
|
|
||||||
|
int number1, number2;
|
||||||
|
String suffix1, suffix2;
|
||||||
|
|
||||||
while (tokenizer1.MoveNext()) {
|
while (tokenizer1.MoveNext()) {
|
||||||
if (!tokenizer2.MoveNext()) {
|
if (!tokenizer2.MoveNext()) {
|
||||||
@ -313,71 +315,6 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
* @param ver2 Version to Compare
|
* @param ver2 Version to Compare
|
||||||
*/
|
*/
|
||||||
public static int compare(Version ver1, Version ver2) {
|
public static int compare(Version ver1, Version ver2) {
|
||||||
String version1 = ver1.toInternalString();
|
return ver1.compareTo(ver2);
|
||||||
String version2 = ver2.toInternalString();
|
|
||||||
|
|
||||||
VersionTokenizer tokenizer1 = new VersionTokenizer(version1);
|
|
||||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version2);
|
|
||||||
|
|
||||||
int number1 = 0, number2 = 0;
|
|
||||||
String suffix1 = "", suffix2 = "";
|
|
||||||
|
|
||||||
while (tokenizer1.MoveNext()) {
|
|
||||||
if (!tokenizer2.MoveNext()) {
|
|
||||||
do {
|
|
||||||
number1 = tokenizer1.getNumber();
|
|
||||||
suffix1 = tokenizer1.getSuffix();
|
|
||||||
if (number1 != 0 || suffix1.length() != 0) {
|
|
||||||
// Version one is longer than number two, and non-zero
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (tokenizer1.MoveNext());
|
|
||||||
|
|
||||||
// Version one is longer than version two, but zero
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
number1 = tokenizer1.getNumber();
|
|
||||||
suffix1 = tokenizer1.getSuffix();
|
|
||||||
number2 = tokenizer2.getNumber();
|
|
||||||
suffix2 = tokenizer2.getSuffix();
|
|
||||||
|
|
||||||
if (number1 < number2) {
|
|
||||||
// Number one is less than number two
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (number1 > number2) {
|
|
||||||
// Number one is greater than number two
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean empty1 = suffix1.length() == 0;
|
|
||||||
boolean empty2 = suffix2.length() == 0;
|
|
||||||
|
|
||||||
if (empty1 && empty2) continue; // No suffixes
|
|
||||||
if (empty1) return 1; // First suffix is empty (1.2 > 1.2b)
|
|
||||||
if (empty2) return -1; // Second suffix is empty (1.2a < 1.2)
|
|
||||||
|
|
||||||
// Lexical comparison of suffixes
|
|
||||||
int result = suffix1.compareTo(suffix2);
|
|
||||||
if (result != 0) return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
if (tokenizer2.MoveNext()) {
|
|
||||||
do {
|
|
||||||
number2 = tokenizer2.getNumber();
|
|
||||||
suffix2 = tokenizer2.getSuffix();
|
|
||||||
if (number2 != 0 || suffix2.length() != 0) {
|
|
||||||
// Version one is longer than version two, and non-zero
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (tokenizer2.MoveNext());
|
|
||||||
|
|
||||||
// Version two is longer than version one, but zero
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -73,17 +73,17 @@ public final class SubCommand extends CommandX {
|
|||||||
|
|
||||||
NodeList updnodeList = updxml.getElementsByTagName("version");
|
NodeList updnodeList = updxml.getElementsByTagName("version");
|
||||||
Version updversion = plugin.version;
|
Version updversion = plugin.version;
|
||||||
int updcount = -1;
|
int updcount = 0;
|
||||||
for (int i = 0; i < updnodeList.getLength(); i++) {
|
for (int i = 0; i < updnodeList.getLength(); i++) {
|
||||||
Node node = updnodeList.item(i);
|
Node node = updnodeList.item(i);
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
if (!node.getTextContent().startsWith("-") && new Version(node.getTextContent()).compareTo(updversion) >= 0) {
|
if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(plugin.version.toString()) && new Version(node.getTextContent()).compareTo(updversion) > 0) {
|
||||||
updversion = new Version(node.getTextContent());
|
updversion = new Version(node.getTextContent());
|
||||||
updcount++;
|
updcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (updversion.equals(plugin.version)) {
|
if (updcount == 0) {
|
||||||
sender.sendMessage("You are on the latest version.");
|
sender.sendMessage("You are on the latest version.");
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
sender.sendMessage("You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
||||||
|
@ -498,17 +498,17 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
|
|
||||||
NodeList updnodeList = updxml.getElementsByTagName("version");
|
NodeList updnodeList = updxml.getElementsByTagName("version");
|
||||||
Version updversion = version;
|
Version updversion = version;
|
||||||
int updcount = -1;
|
int updcount = 0;
|
||||||
for (int i = 0; i < updnodeList.getLength(); i++) {
|
for (int i = 0; i < updnodeList.getLength(); i++) {
|
||||||
Node node = updnodeList.item(i);
|
Node node = updnodeList.item(i);
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
if (!node.getTextContent().startsWith("-") && new Version(node.getTextContent()).compareTo(updversion) >= 0) {
|
if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(version.toString()) && new Version(node.getTextContent()).compareTo(updversion) > 0) {
|
||||||
updversion = new Version(node.getTextContent());
|
updversion = new Version(node.getTextContent());
|
||||||
updcount++;
|
updcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!updversion.equals(version)) System.out.println("SubServers > SubServers.Bungee v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
if (updcount > 0) System.out.println("SubServers > SubServers.Bungee v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
}, 0, TimeUnit.DAYS.toMillis(2));
|
}, 0, TimeUnit.DAYS.toMillis(2));
|
||||||
|
Binary file not shown.
@ -125,17 +125,6 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
this.string = string;
|
this.string = string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* The internal toString() method
|
|
||||||
* new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7") would return:
|
|
||||||
* 5 1.0.0 0 7
|
|
||||||
*/
|
|
||||||
private String toInternalString() {
|
|
||||||
String str = type.id + ' ' + string;
|
|
||||||
if (parent != null) str = parent.toInternalString()+' '+str;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default toString() method<br>
|
* The default toString() method<br>
|
||||||
* <br>
|
* <br>
|
||||||
@ -144,12 +133,12 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
*
|
*
|
||||||
* @return Version as a String
|
* @return Version as a String
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String str = (parent == null)?"":parent.toString()+'/'+type.shortname;
|
String str = (parent == null)?"":parent.toString()+'/'+type.shortname;
|
||||||
str += string;
|
str += string;
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The full toString() method<br>
|
* The full toString() method<br>
|
||||||
@ -193,7 +182,7 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if (object instanceof Version) {
|
if (object instanceof Version) {
|
||||||
return equals((Version) object);
|
return equals((Version) object);
|
||||||
@ -211,11 +200,11 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
public boolean equals(Version version) {
|
public boolean equals(Version version) {
|
||||||
return compareTo(version) == 0;
|
return compareTo(version) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns 1 if Greater than
|
* Returns 1 if Greater than
|
||||||
* Returns 0 if Equal
|
* Returns 0 if Equal
|
||||||
* Returns -1 if Less than
|
* Returns -1 if Less than
|
||||||
*//**
|
*//**
|
||||||
*
|
*
|
||||||
* Compare Versions
|
* Compare Versions
|
||||||
@ -223,14 +212,27 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
* @param version The version to compare to
|
* @param version The version to compare to
|
||||||
*/
|
*/
|
||||||
public int compareTo(Version version) {
|
public int compareTo(Version version) {
|
||||||
String version1 = toInternalString();
|
// Compare parent versions first
|
||||||
String version2 = version.toInternalString();
|
if (this.parent != null || version.parent != null) {
|
||||||
|
int parent = ((this.parent == null)?this:this.parent).compareTo((version.parent == null)?version:version.parent);
|
||||||
|
if (parent != 0) return parent;
|
||||||
|
}
|
||||||
|
|
||||||
VersionTokenizer tokenizer1 = new VersionTokenizer(version1);
|
if (this.parent != null && version.parent == null) {
|
||||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version2);
|
// Version one has a parent version and version two does not, making version two the official version
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int number1 = 0, number2 = 0;
|
if (this.parent == null && version.parent != null) {
|
||||||
String suffix1 = "", suffix2 = "";
|
// Version one does not have a parent version and version two does, making version one the official version
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionTokenizer tokenizer1 = new VersionTokenizer(string);
|
||||||
|
VersionTokenizer tokenizer2 = new VersionTokenizer(version.string);
|
||||||
|
|
||||||
|
int number1, number2;
|
||||||
|
String suffix1, suffix2;
|
||||||
|
|
||||||
while (tokenizer1.MoveNext()) {
|
while (tokenizer1.MoveNext()) {
|
||||||
if (!tokenizer2.MoveNext()) {
|
if (!tokenizer2.MoveNext()) {
|
||||||
@ -313,71 +315,6 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
* @param ver2 Version to Compare
|
* @param ver2 Version to Compare
|
||||||
*/
|
*/
|
||||||
public static int compare(Version ver1, Version ver2) {
|
public static int compare(Version ver1, Version ver2) {
|
||||||
String version1 = ver1.toInternalString();
|
return ver1.compareTo(ver2);
|
||||||
String version2 = ver2.toInternalString();
|
|
||||||
|
|
||||||
VersionTokenizer tokenizer1 = new VersionTokenizer(version1);
|
|
||||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version2);
|
|
||||||
|
|
||||||
int number1 = 0, number2 = 0;
|
|
||||||
String suffix1 = "", suffix2 = "";
|
|
||||||
|
|
||||||
while (tokenizer1.MoveNext()) {
|
|
||||||
if (!tokenizer2.MoveNext()) {
|
|
||||||
do {
|
|
||||||
number1 = tokenizer1.getNumber();
|
|
||||||
suffix1 = tokenizer1.getSuffix();
|
|
||||||
if (number1 != 0 || suffix1.length() != 0) {
|
|
||||||
// Version one is longer than number two, and non-zero
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (tokenizer1.MoveNext());
|
|
||||||
|
|
||||||
// Version one is longer than version two, but zero
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
number1 = tokenizer1.getNumber();
|
|
||||||
suffix1 = tokenizer1.getSuffix();
|
|
||||||
number2 = tokenizer2.getNumber();
|
|
||||||
suffix2 = tokenizer2.getSuffix();
|
|
||||||
|
|
||||||
if (number1 < number2) {
|
|
||||||
// Number one is less than number two
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (number1 > number2) {
|
|
||||||
// Number one is greater than number two
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean empty1 = suffix1.length() == 0;
|
|
||||||
boolean empty2 = suffix2.length() == 0;
|
|
||||||
|
|
||||||
if (empty1 && empty2) continue; // No suffixes
|
|
||||||
if (empty1) return 1; // First suffix is empty (1.2 > 1.2b)
|
|
||||||
if (empty2) return -1; // Second suffix is empty (1.2a < 1.2)
|
|
||||||
|
|
||||||
// Lexical comparison of suffixes
|
|
||||||
int result = suffix1.compareTo(suffix2);
|
|
||||||
if (result != 0) return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
if (tokenizer2.MoveNext()) {
|
|
||||||
do {
|
|
||||||
number2 = tokenizer2.getNumber();
|
|
||||||
suffix2 = tokenizer2.getSuffix();
|
|
||||||
if (number2 != 0 || suffix2.length() != 0) {
|
|
||||||
// Version one is longer than version two, and non-zero
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (tokenizer2.MoveNext());
|
|
||||||
|
|
||||||
// Version two is longer than version one, but zero
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -55,17 +55,17 @@ public final class SubCommand implements CommandExecutor {
|
|||||||
|
|
||||||
NodeList updnodeList = updxml.getElementsByTagName("version");
|
NodeList updnodeList = updxml.getElementsByTagName("version");
|
||||||
Version updversion = plugin.version;
|
Version updversion = plugin.version;
|
||||||
int updcount = -1;
|
int updcount = 0;
|
||||||
for (int i = 0; i < updnodeList.getLength(); i++) {
|
for (int i = 0; i < updnodeList.getLength(); i++) {
|
||||||
Node node = updnodeList.item(i);
|
Node node = updnodeList.item(i);
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
if (!node.getTextContent().startsWith("-") && new Version(node.getTextContent()).compareTo(updversion) >= 0) {
|
if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(plugin.version.toString()) && new Version(node.getTextContent()).compareTo(updversion) > 0) {
|
||||||
updversion = new Version(node.getTextContent());
|
updversion = new Version(node.getTextContent());
|
||||||
updcount++;
|
updcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (updversion.equals(plugin.version)) {
|
if (updcount == 0) {
|
||||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Version.Latest"));
|
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Version.Latest"));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Version.Outdated").replace("$int$", Integer.toString(updcount)));
|
sender.sendMessage(plugin.api.getLang("SubServers", "Command.Version.Outdated").replace("$int$", Integer.toString(updcount)));
|
||||||
|
@ -94,17 +94,17 @@ public final class SubPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
NodeList updnodeList = updxml.getElementsByTagName("version");
|
NodeList updnodeList = updxml.getElementsByTagName("version");
|
||||||
Version updversion = version;
|
Version updversion = version;
|
||||||
int updcount = -1;
|
int updcount = 0;
|
||||||
for (int i = 0; i < updnodeList.getLength(); i++) {
|
for (int i = 0; i < updnodeList.getLength(); i++) {
|
||||||
Node node = updnodeList.item(i);
|
Node node = updnodeList.item(i);
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
if (!node.getTextContent().startsWith("-") && new Version(node.getTextContent()).compareTo(updversion) >= 0) {
|
if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(version.toString()) && new Version(node.getTextContent()).compareTo(updversion) > 0) {
|
||||||
updversion = new Version(node.getTextContent());
|
updversion = new Version(node.getTextContent());
|
||||||
updcount++;
|
updcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!updversion.equals(version)) System.out.println("SubServers > SubServers.Client.Bukkit v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
if (updcount > 0) System.out.println("SubServers > SubServers.Client.Bukkit v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
}, 0, TimeUnit.DAYS.toSeconds(2) * 20);
|
}, 0, TimeUnit.DAYS.toSeconds(2) * 20);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Binary file not shown.
@ -387,17 +387,17 @@ public final class ExHost {
|
|||||||
|
|
||||||
NodeList updnodeList = updxml.getElementsByTagName("version");
|
NodeList updnodeList = updxml.getElementsByTagName("version");
|
||||||
Version updversion = version;
|
Version updversion = version;
|
||||||
int updcount = -1;
|
int updcount = 0;
|
||||||
for (int i = 0; i < updnodeList.getLength(); i++) {
|
for (int i = 0; i < updnodeList.getLength(); i++) {
|
||||||
Node node = updnodeList.item(i);
|
Node node = updnodeList.item(i);
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
if (!node.getTextContent().startsWith("-") && new Version(node.getTextContent()).compareTo(updversion) >= 0) {
|
if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(version.toString()) && new Version(node.getTextContent()).compareTo(updversion) > 0) {
|
||||||
updversion = new Version(node.getTextContent());
|
updversion = new Version(node.getTextContent());
|
||||||
updcount++;
|
updcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!updversion.equals(version)) log.info.println("SubServers.Host v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
if (updcount > 0) log.info.println("SubServers.Host v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
}, 0, TimeUnit.DAYS.toMillis(2));
|
}, 0, TimeUnit.DAYS.toMillis(2));
|
||||||
|
@ -125,17 +125,6 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
this.string = string;
|
this.string = string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* The internal toString() method
|
|
||||||
* new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7") would return:
|
|
||||||
* 5 1.0.0 0 7
|
|
||||||
*/
|
|
||||||
private String toInternalString() {
|
|
||||||
String str = type.id + ' ' + string;
|
|
||||||
if (parent != null) str = parent.toInternalString()+' '+str;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default toString() method<br>
|
* The default toString() method<br>
|
||||||
* <br>
|
* <br>
|
||||||
@ -144,12 +133,12 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
*
|
*
|
||||||
* @return Version as a String
|
* @return Version as a String
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String str = (parent == null)?"":parent.toString()+'/'+type.shortname;
|
String str = (parent == null)?"":parent.toString()+'/'+type.shortname;
|
||||||
str += string;
|
str += string;
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The full toString() method<br>
|
* The full toString() method<br>
|
||||||
@ -193,7 +182,7 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if (object instanceof Version) {
|
if (object instanceof Version) {
|
||||||
return equals((Version) object);
|
return equals((Version) object);
|
||||||
@ -211,11 +200,11 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
public boolean equals(Version version) {
|
public boolean equals(Version version) {
|
||||||
return compareTo(version) == 0;
|
return compareTo(version) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns 1 if Greater than
|
* Returns 1 if Greater than
|
||||||
* Returns 0 if Equal
|
* Returns 0 if Equal
|
||||||
* Returns -1 if Less than
|
* Returns -1 if Less than
|
||||||
*//**
|
*//**
|
||||||
*
|
*
|
||||||
* Compare Versions
|
* Compare Versions
|
||||||
@ -223,14 +212,27 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
* @param version The version to compare to
|
* @param version The version to compare to
|
||||||
*/
|
*/
|
||||||
public int compareTo(Version version) {
|
public int compareTo(Version version) {
|
||||||
String version1 = toInternalString();
|
// Compare parent versions first
|
||||||
String version2 = version.toInternalString();
|
if (this.parent != null || version.parent != null) {
|
||||||
|
int parent = ((this.parent == null)?this:this.parent).compareTo((version.parent == null)?version:version.parent);
|
||||||
|
if (parent != 0) return parent;
|
||||||
|
}
|
||||||
|
|
||||||
VersionTokenizer tokenizer1 = new VersionTokenizer(version1);
|
if (this.parent != null && version.parent == null) {
|
||||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version2);
|
// Version one has a parent version and version two does not, making version two the official version
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int number1 = 0, number2 = 0;
|
if (this.parent == null && version.parent != null) {
|
||||||
String suffix1 = "", suffix2 = "";
|
// Version one does not have a parent version and version two does, making version one the official version
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionTokenizer tokenizer1 = new VersionTokenizer(string);
|
||||||
|
VersionTokenizer tokenizer2 = new VersionTokenizer(version.string);
|
||||||
|
|
||||||
|
int number1, number2;
|
||||||
|
String suffix1, suffix2;
|
||||||
|
|
||||||
while (tokenizer1.MoveNext()) {
|
while (tokenizer1.MoveNext()) {
|
||||||
if (!tokenizer2.MoveNext()) {
|
if (!tokenizer2.MoveNext()) {
|
||||||
@ -313,71 +315,6 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
* @param ver2 Version to Compare
|
* @param ver2 Version to Compare
|
||||||
*/
|
*/
|
||||||
public static int compare(Version ver1, Version ver2) {
|
public static int compare(Version ver1, Version ver2) {
|
||||||
String version1 = ver1.toInternalString();
|
return ver1.compareTo(ver2);
|
||||||
String version2 = ver2.toInternalString();
|
|
||||||
|
|
||||||
VersionTokenizer tokenizer1 = new VersionTokenizer(version1);
|
|
||||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version2);
|
|
||||||
|
|
||||||
int number1 = 0, number2 = 0;
|
|
||||||
String suffix1 = "", suffix2 = "";
|
|
||||||
|
|
||||||
while (tokenizer1.MoveNext()) {
|
|
||||||
if (!tokenizer2.MoveNext()) {
|
|
||||||
do {
|
|
||||||
number1 = tokenizer1.getNumber();
|
|
||||||
suffix1 = tokenizer1.getSuffix();
|
|
||||||
if (number1 != 0 || suffix1.length() != 0) {
|
|
||||||
// Version one is longer than number two, and non-zero
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (tokenizer1.MoveNext());
|
|
||||||
|
|
||||||
// Version one is longer than version two, but zero
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
number1 = tokenizer1.getNumber();
|
|
||||||
suffix1 = tokenizer1.getSuffix();
|
|
||||||
number2 = tokenizer2.getNumber();
|
|
||||||
suffix2 = tokenizer2.getSuffix();
|
|
||||||
|
|
||||||
if (number1 < number2) {
|
|
||||||
// Number one is less than number two
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (number1 > number2) {
|
|
||||||
// Number one is greater than number two
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean empty1 = suffix1.length() == 0;
|
|
||||||
boolean empty2 = suffix2.length() == 0;
|
|
||||||
|
|
||||||
if (empty1 && empty2) continue; // No suffixes
|
|
||||||
if (empty1) return 1; // First suffix is empty (1.2 > 1.2b)
|
|
||||||
if (empty2) return -1; // Second suffix is empty (1.2a < 1.2)
|
|
||||||
|
|
||||||
// Lexical comparison of suffixes
|
|
||||||
int result = suffix1.compareTo(suffix2);
|
|
||||||
if (result != 0) return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
if (tokenizer2.MoveNext()) {
|
|
||||||
do {
|
|
||||||
number2 = tokenizer2.getNumber();
|
|
||||||
suffix2 = tokenizer2.getSuffix();
|
|
||||||
if (number2 != 0 || suffix2.length() != 0) {
|
|
||||||
// Version one is longer than version two, and non-zero
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (tokenizer2.MoveNext());
|
|
||||||
|
|
||||||
// Version two is longer than version one, but zero
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -40,17 +40,17 @@ public class SubCommand {
|
|||||||
|
|
||||||
NodeList updnodeList = updxml.getElementsByTagName("version");
|
NodeList updnodeList = updxml.getElementsByTagName("version");
|
||||||
Version updversion = host.version;
|
Version updversion = host.version;
|
||||||
int updcount = -1;
|
int updcount = 0;
|
||||||
for (int i = 0; i < updnodeList.getLength(); i++) {
|
for (int i = 0; i < updnodeList.getLength(); i++) {
|
||||||
Node node = updnodeList.item(i);
|
Node node = updnodeList.item(i);
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
if (!node.getTextContent().startsWith("-") && new Version(node.getTextContent()).compareTo(updversion) >= 0) {
|
if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(host.version.toString()) && new Version(node.getTextContent()).compareTo(updversion) > 0) {
|
||||||
updversion = new Version(node.getTextContent());
|
updversion = new Version(node.getTextContent());
|
||||||
updcount++;
|
updcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (updversion.equals(host.version)) {
|
if (updcount == 0) {
|
||||||
host.log.message.println("You are on the latest version.");
|
host.log.message.println("You are on the latest version.");
|
||||||
} else {
|
} else {
|
||||||
host.log.message.println("You are " + updcount + " version" + ((updcount == 1) ? "" : "s") + " behind.");
|
host.log.message.println("You are " + updcount + " version" + ((updcount == 1) ? "" : "s") + " behind.");
|
||||||
|
Binary file not shown.
@ -125,17 +125,6 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
this.string = string;
|
this.string = string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* The internal toString() method
|
|
||||||
* new Version(new Version("1.0.0"), VersionType.PRE_ALPHA, "7") would return:
|
|
||||||
* 5 1.0.0 0 7
|
|
||||||
*/
|
|
||||||
private String toInternalString() {
|
|
||||||
String str = type.id + ' ' + string;
|
|
||||||
if (parent != null) str = parent.toInternalString()+' '+str;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default toString() method<br>
|
* The default toString() method<br>
|
||||||
* <br>
|
* <br>
|
||||||
@ -144,12 +133,12 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
*
|
*
|
||||||
* @return Version as a String
|
* @return Version as a String
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String str = (parent == null)?"":parent.toString()+'/'+type.shortname;
|
String str = (parent == null)?"":parent.toString()+'/'+type.shortname;
|
||||||
str += string;
|
str += string;
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The full toString() method<br>
|
* The full toString() method<br>
|
||||||
@ -193,7 +182,7 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if (object instanceof Version) {
|
if (object instanceof Version) {
|
||||||
return equals((Version) object);
|
return equals((Version) object);
|
||||||
@ -211,11 +200,11 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
public boolean equals(Version version) {
|
public boolean equals(Version version) {
|
||||||
return compareTo(version) == 0;
|
return compareTo(version) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns 1 if Greater than
|
* Returns 1 if Greater than
|
||||||
* Returns 0 if Equal
|
* Returns 0 if Equal
|
||||||
* Returns -1 if Less than
|
* Returns -1 if Less than
|
||||||
*//**
|
*//**
|
||||||
*
|
*
|
||||||
* Compare Versions
|
* Compare Versions
|
||||||
@ -223,14 +212,27 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
* @param version The version to compare to
|
* @param version The version to compare to
|
||||||
*/
|
*/
|
||||||
public int compareTo(Version version) {
|
public int compareTo(Version version) {
|
||||||
String version1 = toInternalString();
|
// Compare parent versions first
|
||||||
String version2 = version.toInternalString();
|
if (this.parent != null || version.parent != null) {
|
||||||
|
int parent = ((this.parent == null)?this:this.parent).compareTo((version.parent == null)?version:version.parent);
|
||||||
|
if (parent != 0) return parent;
|
||||||
|
}
|
||||||
|
|
||||||
VersionTokenizer tokenizer1 = new VersionTokenizer(version1);
|
if (this.parent != null && version.parent == null) {
|
||||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version2);
|
// Version one has a parent version and version two does not, making version two the official version
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int number1 = 0, number2 = 0;
|
if (this.parent == null && version.parent != null) {
|
||||||
String suffix1 = "", suffix2 = "";
|
// Version one does not have a parent version and version two does, making version one the official version
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionTokenizer tokenizer1 = new VersionTokenizer(string);
|
||||||
|
VersionTokenizer tokenizer2 = new VersionTokenizer(version.string);
|
||||||
|
|
||||||
|
int number1, number2;
|
||||||
|
String suffix1, suffix2;
|
||||||
|
|
||||||
while (tokenizer1.MoveNext()) {
|
while (tokenizer1.MoveNext()) {
|
||||||
if (!tokenizer2.MoveNext()) {
|
if (!tokenizer2.MoveNext()) {
|
||||||
@ -313,71 +315,6 @@ public class Version implements Serializable, Comparable<Version> {
|
|||||||
* @param ver2 Version to Compare
|
* @param ver2 Version to Compare
|
||||||
*/
|
*/
|
||||||
public static int compare(Version ver1, Version ver2) {
|
public static int compare(Version ver1, Version ver2) {
|
||||||
String version1 = ver1.toInternalString();
|
return ver1.compareTo(ver2);
|
||||||
String version2 = ver2.toInternalString();
|
|
||||||
|
|
||||||
VersionTokenizer tokenizer1 = new VersionTokenizer(version1);
|
|
||||||
VersionTokenizer tokenizer2 = new VersionTokenizer(version2);
|
|
||||||
|
|
||||||
int number1 = 0, number2 = 0;
|
|
||||||
String suffix1 = "", suffix2 = "";
|
|
||||||
|
|
||||||
while (tokenizer1.MoveNext()) {
|
|
||||||
if (!tokenizer2.MoveNext()) {
|
|
||||||
do {
|
|
||||||
number1 = tokenizer1.getNumber();
|
|
||||||
suffix1 = tokenizer1.getSuffix();
|
|
||||||
if (number1 != 0 || suffix1.length() != 0) {
|
|
||||||
// Version one is longer than number two, and non-zero
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (tokenizer1.MoveNext());
|
|
||||||
|
|
||||||
// Version one is longer than version two, but zero
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
number1 = tokenizer1.getNumber();
|
|
||||||
suffix1 = tokenizer1.getSuffix();
|
|
||||||
number2 = tokenizer2.getNumber();
|
|
||||||
suffix2 = tokenizer2.getSuffix();
|
|
||||||
|
|
||||||
if (number1 < number2) {
|
|
||||||
// Number one is less than number two
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (number1 > number2) {
|
|
||||||
// Number one is greater than number two
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean empty1 = suffix1.length() == 0;
|
|
||||||
boolean empty2 = suffix2.length() == 0;
|
|
||||||
|
|
||||||
if (empty1 && empty2) continue; // No suffixes
|
|
||||||
if (empty1) return 1; // First suffix is empty (1.2 > 1.2b)
|
|
||||||
if (empty2) return -1; // Second suffix is empty (1.2a < 1.2)
|
|
||||||
|
|
||||||
// Lexical comparison of suffixes
|
|
||||||
int result = suffix1.compareTo(suffix2);
|
|
||||||
if (result != 0) return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
if (tokenizer2.MoveNext()) {
|
|
||||||
do {
|
|
||||||
number2 = tokenizer2.getNumber();
|
|
||||||
suffix2 = tokenizer2.getSuffix();
|
|
||||||
if (number2 != 0 || suffix2.length() != 0) {
|
|
||||||
// Version one is longer than version two, and non-zero
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (tokenizer2.MoveNext());
|
|
||||||
|
|
||||||
// Version two is longer than version one, but zero
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -73,17 +73,17 @@ public final class SubCommand extends CommandX {
|
|||||||
|
|
||||||
NodeList updnodeList = updxml.getElementsByTagName("version");
|
NodeList updnodeList = updxml.getElementsByTagName("version");
|
||||||
Version updversion = plugin.version;
|
Version updversion = plugin.version;
|
||||||
int updcount = -1;
|
int updcount = 0;
|
||||||
for (int i = 0; i < updnodeList.getLength(); i++) {
|
for (int i = 0; i < updnodeList.getLength(); i++) {
|
||||||
Node node = updnodeList.item(i);
|
Node node = updnodeList.item(i);
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
if (!node.getTextContent().startsWith("-") && new Version(node.getTextContent()).compareTo(updversion) >= 0) {
|
if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(plugin.version.toString()) && new Version(node.getTextContent()).compareTo(updversion) > 0) {
|
||||||
updversion = new Version(node.getTextContent());
|
updversion = new Version(node.getTextContent());
|
||||||
updcount++;
|
updcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (updversion.equals(plugin.version)) {
|
if (updcount == 0) {
|
||||||
sender.sendMessage("You are on the latest version.");
|
sender.sendMessage("You are on the latest version.");
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("You are " + updcount + " version" + ((updcount == 1) ? "" : "s") + " behind.");
|
sender.sendMessage("You are " + updcount + " version" + ((updcount == 1) ? "" : "s") + " behind.");
|
||||||
|
@ -135,17 +135,17 @@ public final class SubPlugin extends BungeeCord implements Listener {
|
|||||||
|
|
||||||
NodeList updnodeList = updxml.getElementsByTagName("version");
|
NodeList updnodeList = updxml.getElementsByTagName("version");
|
||||||
Version updversion = version;
|
Version updversion = version;
|
||||||
int updcount = -1;
|
int updcount = 0;
|
||||||
for (int i = 0; i < updnodeList.getLength(); i++) {
|
for (int i = 0; i < updnodeList.getLength(); i++) {
|
||||||
Node node = updnodeList.item(i);
|
Node node = updnodeList.item(i);
|
||||||
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
if (node.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
if (!node.getTextContent().startsWith("-") && new Version(node.getTextContent()).compareTo(updversion) >= 0) {
|
if (!node.getTextContent().startsWith("-") && !node.getTextContent().equals(version.toString()) && new Version(node.getTextContent()).compareTo(updversion) > 0) {
|
||||||
updversion = new Version(node.getTextContent());
|
updversion = new Version(node.getTextContent());
|
||||||
updcount++;
|
updcount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!updversion.equals(version)) System.out.println("SubServers > SubServers.Sync v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
if (updcount > 0) System.out.println("SubServers > SubServers.Sync v" + updversion + " is available. You are " + updcount + " version" + ((updcount == 1)?"":"s") + " behind.");
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
}, 0, TimeUnit.DAYS.toMillis(2));
|
}, 0, TimeUnit.DAYS.toMillis(2));
|
||||||
|
Loading…
Reference in New Issue
Block a user