mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-23 01:27:40 +01:00
Make VersionUtil not explode when patch is not present
This commit is contained in:
parent
04ec013407
commit
da89efb79f
@ -49,7 +49,16 @@ public class VersionUtil {
|
||||
matcher = VERSION_PATTERN.matcher(v1_13_2_R01.toString());
|
||||
Preconditions.checkArgument(matcher.matches(), string + " is not in valid version format. e.g. 1.8.8-R0.1");
|
||||
}
|
||||
return new BukkitVersion(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3)), Double.parseDouble(matcher.group(4)));
|
||||
|
||||
return from(matcher.group(1), matcher.group(2), matcher.group(3), matcher.group(4));
|
||||
}
|
||||
|
||||
private static BukkitVersion from(String major, String minor, String patch, String revision) {
|
||||
if (patch.isEmpty()) patch = "0";
|
||||
return new BukkitVersion(Integer.parseInt(major),
|
||||
Integer.parseInt(minor),
|
||||
Integer.parseInt(patch),
|
||||
Double.parseDouble(revision));
|
||||
}
|
||||
|
||||
private BukkitVersion(int major, int minor, int patch, double revision) {
|
||||
|
@ -2,6 +2,7 @@ package com.earth2me.essentials;
|
||||
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.LocationUtil;
|
||||
import com.earth2me.essentials.utils.VersionUtil;
|
||||
import junit.framework.TestCase;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.plugin.InvalidDescriptionException;
|
||||
@ -190,4 +191,18 @@ public class UtilTest extends TestCase {
|
||||
b = new GregorianCalendar(2000, 3, 7, 10, 0, 0);
|
||||
assertEquals("10 years 6 months 10 days", DateUtil.formatDateDiff(a, b));
|
||||
}
|
||||
|
||||
public void testVer() {
|
||||
VersionUtil.BukkitVersion v;
|
||||
v = VersionUtil.BukkitVersion.fromString("1.13.2-R0.1");
|
||||
assertEquals(v.getMajor(), 1);
|
||||
assertEquals(v.getMinor(), 13);
|
||||
assertEquals(v.getPatch(), 2);
|
||||
assertEquals(v.getRevision(), 0.1);
|
||||
v = VersionUtil.BukkitVersion.fromString("1.9-R1.4");
|
||||
assertEquals(v.getMajor(), 1);
|
||||
assertEquals(v.getMinor(), 9);
|
||||
assertEquals(v.getPatch(), 0);
|
||||
assertEquals(v.getRevision(), 1.4);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user