diff --git a/Essentials/src/com/earth2me/essentials/utils/VersionUtil.java b/Essentials/src/com/earth2me/essentials/utils/VersionUtil.java index 0101f7db2..658123048 100644 --- a/Essentials/src/com/earth2me/essentials/utils/VersionUtil.java +++ b/Essentials/src/com/earth2me/essentials/utils/VersionUtil.java @@ -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) { diff --git a/Essentials/test/com/earth2me/essentials/UtilTest.java b/Essentials/test/com/earth2me/essentials/UtilTest.java index 9bf4717ef..da58aa9fe 100644 --- a/Essentials/test/com/earth2me/essentials/UtilTest.java +++ b/Essentials/test/com/earth2me/essentials/UtilTest.java @@ -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); + } }