mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-21 23:12:15 +00:00
Update config version checker
Update config output Add enableCape in config
This commit is contained in:
1 parent
a3fb3cd770
commit
3b07b5ccca
2 files changed
+81
-34
No files matched your search
@@ -0,0 +1,50 @@
|
||||
package customskinloader.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class Version implements Comparable {
|
||||
private String version;
|
||||
private int sub[];
|
||||
|
||||
public Version(String version) {
|
||||
if (version == null) version = "";
|
||||
this.version = version;
|
||||
|
||||
//Parse Subversion
|
||||
String[] split = version.split("\\.");
|
||||
sub = new int[split.length];
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
if (StringUtils.isNumeric(split[i]))
|
||||
sub[i] = Integer.parseInt(split[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static Version of(String version) {
|
||||
return new Version(version);
|
||||
}
|
||||
|
||||
public static int compare(String version, String anotherVersion) {
|
||||
return Version.of(version).compareTo(anotherVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Object o) {
|
||||
if (o instanceof String) o = Version.of((String) o);//Parse String version
|
||||
if (!(o instanceof Version)) throw new IllegalArgumentException(String.format("'%s' is not a Version.", o));
|
||||
|
||||
Version v = (Version) o;
|
||||
int i = 0;
|
||||
//Skip same subversion
|
||||
while (i < sub.length && i < v.sub.length && sub[i] == v.sub[i]) i++;
|
||||
//Compare first non-equal number
|
||||
if (i < sub.length && i < v.sub.length)
|
||||
return (sub[i] < v.sub[i]) ? -1 : ((sub[i] == v.sub[i]) ? 0 : 1); //Integer.compare(sub[i], v.sub[i]);
|
||||
//Compare length if all subversion is same
|
||||
return Integer.signum(sub.length - v.sub.length);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user