Fix version checker to compare the individual semver numbers instead of combining it together.

(cherry picked from commit ef5cd9d376)
This commit is contained in:
Starmism 2021-06-30 05:05:18 -06:00
parent 0c102a1823
commit 14d885392c

View File

@ -23,6 +23,7 @@ package me.clip.placeholderapi.updatechecker;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Arrays;
import javax.net.ssl.HttpsURLConnection;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.util.Msg;
@ -90,17 +91,22 @@ public class UpdateChecker implements Listener {
return false;
}
String plV = toReadable(pluginVersion);
String spV = toReadable(spigotVersion);
return plV.compareTo(spV) < 0;
int[] plV = toReadable(pluginVersion);
int[] spV = toReadable(spigotVersion);
if (plV[0] < spV[0]) {
return true;
} else if ((plV[1] < spV[1])) {
return true;
} else return plV[2] < spV[2];
}
private String toReadable(String version) {
if (version.contains("-DEV-")) {
version = version.split("-DEV-")[0];
private int[] toReadable(String version) {
if (version.contains("-DEV")) {
version = version.split("-DEV")[0];
}
return version.replaceAll("\\.", "");
return Arrays.stream(version.split("\\.")).mapToInt(Integer::parseInt).toArray();
}
@EventHandler(priority = EventPriority.MONITOR)