Skip to content

Commit 2cdc706

Browse files
committed
Add GameVersionNumber.isKnown method and use it in CurseAddon
1 parent ebf253b commit 2cdc706

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

HMCLCore/src/main/java/org/jackhuang/hmcl/mod/curse/CurseAddon.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.jackhuang.hmcl.util.Lang;
2626
import org.jackhuang.hmcl.util.Pair;
2727
import org.jackhuang.hmcl.util.StringUtils;
28+
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
2829
import org.jetbrains.annotations.Nullable;
2930

3031
import java.io.IOException;
@@ -592,7 +593,7 @@ public RemoteMod.Version toVersion() {
592593
}
593594
return RemoteMod.Dependency.ofGeneral(RELATION_TYPE.get(dependency.getRelationType()), CurseForgeRemoteModRepository.MODS, Integer.toString(dependency.getModId()));
594595
}).distinct().filter(Objects::nonNull).collect(Collectors.toList()),
595-
gameVersions.stream().filter(ver -> ver.startsWith("1.") || ver.contains("w")).collect(Collectors.toList()),
596+
gameVersions.stream().filter(GameVersionNumber::isKnown).toList(),
596597
gameVersions.stream().flatMap(version -> {
597598
if ("fabric".equalsIgnoreCase(version)) return Stream.of(ModLoaderType.FABRIC);
598599
else if ("forge".equalsIgnoreCase(version)) return Stream.of(ModLoaderType.FORGE);

HMCLCore/src/main/java/org/jackhuang/hmcl/util/versioning/GameVersionNumber.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ public static VersionRange<GameVersionNumber> atMost(String maximum) {
9595
return VersionRange.atMost(asGameVersion(maximum));
9696
}
9797

98+
99+
/// Determines whether the given version string corresponds to a known Minecraft version.
100+
///
101+
/// If the version string cannot be parsed as any known version type (release, snapshot, pre-release, etc.)
102+
/// and is not a known April Fools snapshot, it is considered an unknown version.
103+
///
104+
/// @param version the version string to check, e.g. `"1.21.4"`, `"25w14craftmine"`, etc.
105+
/// @return {@code true} if the version string corresponds to a known Minecraft version, {@code false} otherwise
106+
/// @see #asGameVersion(String)
107+
public static boolean isKnown(String version) {
108+
return !(asGameVersion(version) instanceof Special special && special.prev == null);
109+
}
110+
98111
final String value;
99112
final String normalized;
100113

@@ -151,7 +164,7 @@ public boolean isAtLeast(@NotNull String releaseVersion, @NotNull String snapsho
151164
///
152165
/// ```java
153166
/// GameVersionNumber.asVersion("...").isAtLeast("1.13", "17w43a");
154-
///```
167+
/// ```
155168
///
156169
/// @param strictReleaseVersion When `strictReleaseVersion` is `false`, `releaseVersion` is considered less than
157170
/// its corresponding pre/rc versions.

0 commit comments

Comments
 (0)