Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-08 22:02:50 +02:00
SemVer compatibility, also change up the messages a bit.
Dieser Commit ist enthalten in:
Ursprung
ed311e4059
Commit
f159a2250c
@ -23,7 +23,7 @@ public class UpdateUtil {
|
|||||||
public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN;
|
public final static String PREFIX = ChatColor.GREEN + "" + ChatColor.BOLD + "[ViaVersion] " + ChatColor.GREEN;
|
||||||
private final static String URL = "http://api.spiget.org/v2/resources/";
|
private final static String URL = "http://api.spiget.org/v2/resources/";
|
||||||
private final static int PLUGIN = 19254;
|
private final static int PLUGIN = 19254;
|
||||||
private final static String LATEST_VERSION = "/versions/latest";
|
private final static String LATEST_VERSION = "/versions/latest";
|
||||||
|
|
||||||
public static void sendUpdateMessage(final UUID uuid, final Plugin plugin) {
|
public static void sendUpdateMessage(final UUID uuid, final Plugin plugin) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@ -82,13 +82,17 @@ public class UpdateUtil {
|
|||||||
try {
|
try {
|
||||||
current = new Version(ViaVersion.getInstance().getVersion());
|
current = new Version(ViaVersion.getInstance().getVersion());
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return "You are using a debug/custom version, consider updating.";
|
return "You are using a custom version, consider updating.";
|
||||||
}
|
}
|
||||||
Version newest = new Version(newestString);
|
Version newest = new Version(newestString);
|
||||||
if (current.compareTo(newest) < 0)
|
if (current.compareTo(newest) < 0)
|
||||||
return "There is a newer version available: " + newest.toString();
|
return "There is a newer version available: " + newest.toString() + ", you're on: " + current.toString();
|
||||||
else if (console && current.compareTo(newest) != 0) {
|
else if (console && current.compareTo(newest) != 0) {
|
||||||
return "You are running a newer version than is released!";
|
if (current.getTag().toLowerCase().startsWith("dev") || current.getTag().toLowerCase().startsWith("snapshot")) {
|
||||||
|
return "You are running a development version, please report any bugs to GitHub.";
|
||||||
|
} else {
|
||||||
|
return "You are running a newer version than is released!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -2,21 +2,26 @@ package us.myles.ViaVersion.update;
|
|||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Version implements Comparable<Version> {
|
public class Version implements Comparable<Version> {
|
||||||
private int[] parts;
|
private static Pattern semVer = Pattern.compile("(?<a>0|[1-9]\\d*)\\.(?<b>0|[1-9]\\d*)(?:\\.(?<c>0|[1-9]\\d*))?(?:-(?<tag>[A-z0-9.-]*))?");
|
||||||
|
private int[] parts = new int[3];
|
||||||
|
private String tag;
|
||||||
|
|
||||||
public Version(String value) {
|
public Version(String value) {
|
||||||
if (value == null)
|
if (value == null)
|
||||||
throw new IllegalArgumentException("Version can not be null");
|
throw new IllegalArgumentException("Version can not be null");
|
||||||
|
|
||||||
if (!value.matches("^[0-9]+(\\.[0-9]+)*$"))
|
Matcher matcher = semVer.matcher(value);
|
||||||
|
if (!matcher.matches())
|
||||||
throw new IllegalArgumentException("Invalid version format");
|
throw new IllegalArgumentException("Invalid version format");
|
||||||
|
parts[0] = Integer.parseInt(matcher.group("a"));
|
||||||
|
parts[1] = Integer.parseInt(matcher.group("b"));
|
||||||
|
parts[2] = matcher.group("c") == null ? 0 : Integer.parseInt(matcher.group("c"));
|
||||||
|
|
||||||
String[] split = value.split("\\.");
|
tag = matcher.group("tag") == null ? "" : matcher.group("tag");
|
||||||
parts = new int[split.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < split.length; i += 1)
|
|
||||||
parts[i] = Integer.parseInt(split[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int compare(Version verA, Version verB) {
|
public static int compare(Version verA, Version verB) {
|
||||||
@ -33,6 +38,12 @@ public class Version implements Comparable<Version> {
|
|||||||
if (partA > partB) return 1;
|
if (partA > partB) return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Simple tag check
|
||||||
|
if (verA.tag.length() == 0 && verB.tag.length() > 0)
|
||||||
|
return 1;
|
||||||
|
if (verA.tag.length() > 0 && verB.tag.length() == 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +58,7 @@ public class Version implements Comparable<Version> {
|
|||||||
for (int i = 0; i < parts.length; i += 1)
|
for (int i = 0; i < parts.length; i += 1)
|
||||||
split[i] = String.valueOf(parts[i]);
|
split[i] = String.valueOf(parts[i]);
|
||||||
|
|
||||||
return StringUtils.join(split, ".");
|
return StringUtils.join(split, ".") + (tag.length() != 0 ? "-" + tag : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,4 +70,8 @@ public class Version implements Comparable<Version> {
|
|||||||
public boolean equals(Object that) {
|
public boolean equals(Object that) {
|
||||||
return that instanceof Version && equals(this, (Version) that);
|
return that instanceof Version && equals(this, (Version) that);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTag() {
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
}
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren