Fix #4325: 修复未将 15w14a 识别为愚人节版本的问题 (#4327)

This commit is contained in:
Glavo 2025-08-24 22:27:49 +08:00 committed by GitHub
parent 933b7cab2f
commit 06b7b1e574
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 4 deletions

View File

@ -200,7 +200,7 @@ public final class VersionsPage extends Control implements WizardPage, Refreshab
case PENDING: case PENDING:
case SNAPSHOT: case SNAPSHOT:
if (versionType == RemoteVersion.Type.SNAPSHOT if (versionType == RemoteVersion.Type.SNAPSHOT
&& GameVersionNumber.asGameVersion(remoteVersion.getGameVersion()).isSpecial()) { && GameVersionNumber.asGameVersion(remoteVersion.getGameVersion()).isAprilFools()) {
content.getTags().setAll(i18n("version.game.april_fools")); content.getTags().setAll(i18n("version.game.april_fools"));
content.setImage(VersionIconType.APRIL_FOOLS.getIcon()); content.setImage(VersionIconType.APRIL_FOOLS.getIcon());
} else { } else {
@ -492,7 +492,7 @@ public final class VersionsPage extends Control implements WizardPage, Refreshab
|| versionType == RemoteVersion.Type.PENDING; || versionType == RemoteVersion.Type.PENDING;
case APRIL_FOOLS: case APRIL_FOOLS:
return versionType == RemoteVersion.Type.SNAPSHOT return versionType == RemoteVersion.Type.SNAPSHOT
&& GameVersionNumber.asGameVersion(it.getGameVersion()).isSpecial(); && GameVersionNumber.asGameVersion(it.getGameVersion()).isAprilFools();
case OLD: case OLD:
return versionType == RemoteVersion.Type.OLD; return versionType == RemoteVersion.Type.OLD;
case ALL: case ALL:

View File

@ -98,8 +98,16 @@ public abstract class GameVersionNumber implements Comparable<GameVersionNumber>
this.value = value; this.value = value;
} }
public boolean isSpecial() { public boolean isAprilFools() {
return this instanceof Special; if (this instanceof Special)
return true;
if (this instanceof Snapshot) {
Snapshot snapshot = (Snapshot) this;
return snapshot.intValue == Snapshot.toInt(15, 14, 'a');
}
return false;
} }
enum Type { enum Type {

View File

@ -99,6 +99,29 @@ public final class GameVersionNumberTest {
assertEquals(VersionNumber.asVersion(versionNumber), old.versionNumber); assertEquals(VersionNumber.asVersion(versionNumber), old.versionNumber);
} }
private static boolean isAprilFools(String version) {
return GameVersionNumber.asGameVersion(version).isAprilFools();
}
@Test
public void testIsAprilFools() {
assertTrue(isAprilFools("15w14a"));
assertTrue(isAprilFools("1.RV-Pre1"));
assertTrue(isAprilFools("3D Shareware v1.34"));
assertTrue(isAprilFools("2.0"));
assertTrue(isAprilFools("20w14infinite"));
assertTrue(isAprilFools("22w13oneBlockAtATime"));
assertTrue(isAprilFools("23w13a_or_b"));
assertTrue(isAprilFools("24w14potato"));
assertTrue(isAprilFools("25w14craftmine"));
assertFalse(isAprilFools("1.21.8"));
assertFalse(isAprilFools("1.21.8-rc1"));
assertFalse(isAprilFools("25w21a"));
assertFalse(isAprilFools("13w12~"));
assertFalse(isAprilFools("15w14b"));
}
@Test @Test
public void testParseOld() { public void testParseOld() {
assertOldVersion("rd-132211", GameVersionNumber.Type.PRE_CLASSIC, "132211"); assertOldVersion("rd-132211", GameVersionNumber.Type.PRE_CLASSIC, "132211");