@@ -165,12 +165,9 @@ public static String getSupportStatusClass() {
165165 return supportStatusClass ;
166166 }
167167
168- public static boolean isServerSupported () {
169- return getServerSupportStatus ().isSupported ();
170- }
171-
172168 public static final class BukkitVersion implements Comparable <BukkitVersion > {
173169 private static final Pattern VERSION_PATTERN = Pattern .compile ("^(\\ d+)\\ .(\\ d+)\\ .?([0-9]*)?(?:-pre(\\ d))?(?:-rc(\\ d+))?(?:-?R?([\\ d.]+))?(?:-SNAPSHOT)?" );
170+ private static final Pattern SNAPSHOT_PATTERN = Pattern .compile ("^(\\ d{2})w(\\ d{2})([a-z])(?:-?R?([\\ d.]+))?(?:-SNAPSHOT)?" );
174171
175172 private final int major ;
176173 private final int minor ;
@@ -179,26 +176,66 @@ public static final class BukkitVersion implements Comparable<BukkitVersion> {
179176 private final int patch ;
180177 private final double revision ;
181178
179+ private final boolean snapshot ;
180+ private final int snapshotYear ;
181+ private final int snapshotWeek ;
182+ private final char snapshotLetter ;
183+
182184 private BukkitVersion (final int major , final int minor , final int patch , final double revision , final int preRelease , final int releaseCandidate ) {
183185 this .major = major ;
184186 this .minor = minor ;
185187 this .patch = patch ;
186188 this .revision = revision ;
187189 this .preRelease = preRelease ;
188190 this .releaseCandidate = releaseCandidate ;
191+ this .snapshot = false ;
192+ this .snapshotYear = -1 ;
193+ this .snapshotWeek = -1 ;
194+ this .snapshotLetter = '\0' ;
195+ }
196+
197+ private BukkitVersion (final int major , final int minor , final int patch , final double revision , final int preRelease , final int releaseCandidate ,
198+ final boolean snapshot , final int snapshotYear , final int snapshotWeek , final char snapshotLetter ) {
199+ this .major = major ;
200+ this .minor = minor ;
201+ this .patch = patch ;
202+ this .revision = revision ;
203+ this .preRelease = preRelease ;
204+ this .releaseCandidate = releaseCandidate ;
205+ this .snapshot = snapshot ;
206+ this .snapshotYear = snapshotYear ;
207+ this .snapshotWeek = snapshotWeek ;
208+ this .snapshotLetter = snapshotLetter ;
189209 }
190210
191211 public static BukkitVersion fromString (final String string ) {
192212 Preconditions .checkNotNull (string , "string cannot be null." );
213+
214+ // Try standard release format first
193215 Matcher matcher = VERSION_PATTERN .matcher (string );
194- if (!matcher .matches ()) {
195- if (!Bukkit .getName ().equals ("Essentials Fake Server" )) {
196- throw new IllegalArgumentException (string + " is not in valid version format. e.g. 1.8.8-R0.1" );
216+ if (matcher .matches ()) {
217+ return from (matcher .group (1 ), matcher .group (2 ), matcher .group (3 ), matcher .group (6 ), matcher .group (4 ), matcher .group (5 ));
218+ }
219+
220+ // Try snapshot format (e.g., 25w32a-R0.1-SNAPSHOT)
221+ final Matcher snapshotMatcher = SNAPSHOT_PATTERN .matcher (string );
222+ if (snapshotMatcher .matches ()) {
223+ final int year = Integer .parseInt (snapshotMatcher .group (1 ));
224+ final int week = Integer .parseInt (snapshotMatcher .group (2 ));
225+ final char letter = snapshotMatcher .group (3 ).charAt (0 );
226+ String revision = snapshotMatcher .group (4 );
227+ if (revision == null || revision .isEmpty ()) {
228+ revision = "0" ;
197229 }
198- matcher = VERSION_PATTERN .matcher (v1_16_1_R01 .toString ());
199- Preconditions .checkArgument (matcher .matches (), string + " is not in valid version format. e.g. 1.8.8-R0.1" );
230+ return fromSnapshot (year , week , letter , Double .parseDouble (revision ));
200231 }
201232
233+ // Fallback for fake server environment
234+ if (!Bukkit .getName ().equals ("Essentials Fake Server" )) {
235+ throw new IllegalArgumentException (string + " is not in valid version format. e.g. 1.8.8-R0.1" );
236+ }
237+ matcher = VERSION_PATTERN .matcher (v1_16_1_R01 .toString ());
238+ Preconditions .checkArgument (matcher .matches (), string + " is not in valid version format. e.g. 1.8.8-R0.1" );
202239 return from (matcher .group (1 ), matcher .group (2 ), matcher .group (3 ), matcher .group (6 ), matcher .group (4 ), matcher .group (5 ));
203240 }
204241
@@ -215,6 +252,10 @@ private static BukkitVersion from(final String major, final String minor, String
215252 Integer .parseInt (releaseCandidate ));
216253 }
217254
255+ private static BukkitVersion fromSnapshot (final int year , final int week , final char letter , final double revision ) {
256+ return new BukkitVersion (-1 , -1 , -1 , revision , -1 , -1 , true , year , week , letter );
257+ }
258+
218259 public boolean isHigherThan (final BukkitVersion o ) {
219260 return compareTo (o ) > 0 ;
220261 }
@@ -255,6 +296,10 @@ public int getReleaseCandidate() {
255296 return releaseCandidate ;
256297 }
257298
299+ public boolean isSnapshot () {
300+ return snapshot ;
301+ }
302+
258303 @ Override
259304 public boolean equals (final Object o ) {
260305 if (this == o ) {
@@ -264,6 +309,13 @@ public boolean equals(final Object o) {
264309 return false ;
265310 }
266311 final BukkitVersion that = (BukkitVersion ) o ;
312+ if (snapshot || that .snapshot ) {
313+ return snapshot == that .snapshot &&
314+ snapshotYear == that .snapshotYear &&
315+ snapshotWeek == that .snapshotWeek &&
316+ snapshotLetter == that .snapshotLetter &&
317+ Double .compare (revision , that .revision ) == 0 ;
318+ }
267319 return major == that .major &&
268320 minor == that .minor &&
269321 patch == that .patch &&
@@ -273,11 +325,17 @@ public boolean equals(final Object o) {
273325
274326 @ Override
275327 public int hashCode () {
328+ if (snapshot ) {
329+ return Objects .hashCode ("snapshot" , snapshotYear , snapshotWeek , snapshotLetter , revision );
330+ }
276331 return Objects .hashCode (major , minor , patch , revision , preRelease , releaseCandidate );
277332 }
278333
279334 @ Override
280335 public String toString () {
336+ if (snapshot ) {
337+ return snapshotYear + "w" + snapshotWeek + snapshotLetter ;
338+ }
281339 final StringBuilder sb = new StringBuilder (major + "." + minor );
282340 if (patch != 0 ) {
283341 sb .append ("." ).append (patch );
@@ -293,6 +351,24 @@ public String toString() {
293351
294352 @ Override
295353 public int compareTo (final BukkitVersion o ) {
354+ // Snapshots are always considered the most recent
355+ if (snapshot && !o .snapshot ) {
356+ return 1 ;
357+ } else if (!snapshot && o .snapshot ) {
358+ return -1 ;
359+ } else if (snapshot /* && o.snapshot */ ) {
360+ if (snapshotYear != o .snapshotYear ) {
361+ return Integer .compare (snapshotYear , o .snapshotYear );
362+ }
363+ if (snapshotWeek != o .snapshotWeek ) {
364+ return Integer .compare (snapshotWeek , o .snapshotWeek );
365+ }
366+ if (snapshotLetter != o .snapshotLetter ) {
367+ return Character .compare (snapshotLetter , o .snapshotLetter );
368+ }
369+ return Double .compare (revision , o .revision );
370+ }
371+
296372 if (major < o .major ) {
297373 return -1 ;
298374 } else if (major > o .major ) {
0 commit comments