mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-02-22 14:41:48 +01:00
Upgraded version checker
This commit is contained in:
parent
5346266e5f
commit
d222be242e
@ -43,7 +43,7 @@ public class SpigotPlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
if (version.equals(plugin.getDescription().getVersion()))
|
||||
if (isOlderThan(version, plugin.getDescription().getVersion()))
|
||||
return;
|
||||
|
||||
plugin.getLogger().log(Level.INFO, "A new build is available: " + version + " (you are running " + plugin.getDescription().getVersion() + ")");
|
||||
@ -65,6 +65,43 @@ public class SpigotPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isOlderThan(String v1, String v2) {
|
||||
String[] netVersion = v1.replaceAll("[^0-9.]", "").split("\\.");
|
||||
String[] localVersion = v2.replaceAll("[^0-9.]", "").split("\\.");
|
||||
|
||||
int netVersionFirst = parse(netVersion[0]);
|
||||
int localVersionFirst = parse(localVersion[0]);
|
||||
|
||||
if(netVersionFirst > localVersionFirst)
|
||||
return false;
|
||||
else {
|
||||
int netVersionMiddle = parse(netVersion[1]);
|
||||
int localVersionMiddle = parse(localVersion[1]);
|
||||
|
||||
if(netVersionMiddle > localVersionMiddle)
|
||||
return false;
|
||||
else {
|
||||
int netVersionLast = netVersion.length > 2 ? parse(netVersion[2]) : 0;
|
||||
int localVersionLast = localVersion.length > 2 ? parse(localVersion[2]) : 0;
|
||||
|
||||
if(netVersionLast > localVersionLast)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private int parse(String s) {
|
||||
try {
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
plugin.getLogger().warning("Something went wrong checking the version numbers!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getOutOfDateMessage() {
|
||||
return Arrays.asList("&8--------------------------------------------", "&a" + plugin.getName() + " " + version + " is available!", "&a" + getResourceUrl(), "&7&oYou can disable this notification in the config file.", "&8--------------------------------------------");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user