From 96987763a5f542c3a975e9a1139e50d07d2f6dec Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Thu, 2 Sep 2021 02:04:19 +0800 Subject: [PATCH] feat: WIP: Fabric API install --- .../org/jackhuang/hmcl/ui/InstallerItem.java | 24 ++++-- .../hmcl/ui/construct/TaskListPane.java | 4 + .../ui/download/AdditionalInstallersPage.java | 5 +- .../hmcl/ui/download/VersionsPage.java | 8 ++ .../resources/assets/lang/I18N.properties | 2 + .../assets/lang/I18N_zh_CN.properties | 2 + .../download/BalancedDownloadProvider.java | 44 ++-------- .../hmcl/download/LibraryAnalyzer.java | 1 + .../hmcl/download/MojangDownloadProvider.java | 5 ++ .../hmcl/download/RemoteVersion.java | 4 + .../download/fabric/FabricAPIInstallTask.java | 69 +++++++++++++++ .../fabric/FabricAPIRemoteVersion.java | 52 +++++++++++ .../download/fabric/FabricAPIVersionList.java | 86 +++++++++++++++++++ 13 files changed, 262 insertions(+), 44 deletions(-) create mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIInstallTask.java create mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIRemoteVersion.java create mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java index 153f75875..3e49109cd 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/InstallerItem.java @@ -50,6 +50,7 @@ public class InstallerItem extends Control { private final String imageUrl; public final StringProperty libraryVersion = new SimpleStringProperty(); public final StringProperty incompatibleLibraryName = new SimpleStringProperty(); + public final StringProperty dependencyName = new SimpleStringProperty(); public final BooleanProperty incompatibleWithGame = new SimpleBooleanProperty(); public final BooleanProperty removable = new SimpleBooleanProperty(); public final BooleanProperty upgradable = new SimpleBooleanProperty(false); @@ -69,6 +70,7 @@ public class InstallerItem extends Control { imageUrl = "/assets/img/grass.png"; break; case "fabric": + case "fabric-api": imageUrl = "/assets/img/fabric.png"; break; case "forge": @@ -104,6 +106,7 @@ public class InstallerItem extends Control { public static class InstallerItemGroup { public final InstallerItem game = new InstallerItem(MINECRAFT); public final InstallerItem fabric = new InstallerItem(FABRIC); + public final InstallerItem fabricApi = new InstallerItem(FABRIC_API); public final InstallerItem forge = new InstallerItem(FORGE); public final InstallerItem liteLoader = new InstallerItem(LITELOADER); public final InstallerItem optiFine = new InstallerItem(OPTIFINE); @@ -124,16 +127,23 @@ public class InstallerItem extends Control { return null; }, fabric.libraryVersion)); - fabric.incompatibleLibraryName.bind(Bindings.createStringBinding(() -> { - if (liteLoader.libraryVersion.get() != null) return LITELOADER.getPatchId(); - if (optiFine.libraryVersion.get() != null) return OPTIFINE.getPatchId(); - if (forge.libraryVersion.get() != null) return FORGE.getPatchId(); - return null; - }, optiFine.libraryVersion, forge.libraryVersion)); + for (InstallerItem fabric : new InstallerItem[]{fabric, fabricApi}) { + fabric.incompatibleLibraryName.bind(Bindings.createStringBinding(() -> { + if (liteLoader.libraryVersion.get() != null) return LITELOADER.getPatchId(); + if (optiFine.libraryVersion.get() != null) return OPTIFINE.getPatchId(); + if (forge.libraryVersion.get() != null) return FORGE.getPatchId(); + return null; + }, optiFine.libraryVersion, forge.libraryVersion)); + } + + fabricApi.dependencyName.bind(Bindings.createStringBinding(() -> { + if (fabric.libraryVersion.get() == null) return FABRIC.getPatchId(); + else return null; + }, fabric.libraryVersion)); } public InstallerItem[] getLibraries() { - return new InstallerItem[]{game, fabric, forge, liteLoader, optiFine}; + return new InstallerItem[]{game, forge, liteLoader, optiFine, fabric, fabricApi}; } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java index e91c2b76d..1a608fb19 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/TaskListPane.java @@ -28,6 +28,7 @@ import javafx.geometry.Pos; import javafx.scene.control.Label; import javafx.scene.layout.BorderPane; import javafx.scene.layout.StackPane; +import org.jackhuang.hmcl.download.fabric.FabricAPIInstallTask; import org.jackhuang.hmcl.download.fabric.FabricInstallTask; import org.jackhuang.hmcl.download.forge.ForgeNewInstallTask; import org.jackhuang.hmcl.download.forge.ForgeOldInstallTask; @@ -119,6 +120,8 @@ public final class TaskListPane extends StackPane { task.setName(i18n("install.installer.install", i18n("install.installer.optifine"))); } else if (task instanceof FabricInstallTask) { task.setName(i18n("install.installer.install", i18n("install.installer.fabric"))); + } else if (task instanceof FabricAPIInstallTask) { + task.setName(i18n("install.installer.install", i18n("install.installer.fabric-api"))); } else if (task instanceof CurseCompletionTask) { task.setName(i18n("modpack.type.curse.completion")); } else if (task instanceof ModpackInstallTask) { @@ -212,6 +215,7 @@ public final class TaskListPane extends StackPane { case "hmcl.install.liteloader": message = i18n("install.installer.install", i18n("install.installer.liteloader") + " " + stageValue); break; case "hmcl.install.optifine": message = i18n("install.installer.install", i18n("install.installer.optifine") + " " + stageValue); break; case "hmcl.install.fabric": message = i18n("install.installer.install", i18n("install.installer.fabric") + " " + stageValue); break; + case "hmcl.install.fabric-api": message = i18n("install.installer.install", i18n("install.installer.fabric-api") + " " + stageValue); break; default: message = i18n(stageKey); break; } // @formatter:on diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java index 36abb3fa1..0b1aecc34 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java @@ -86,13 +86,14 @@ class AdditionalInstallersPage extends InstallersPage { protected void reload() { LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(version.resolvePreservingPatches(repository)); String game = analyzer.getVersion(MINECRAFT).orElse(null); - String fabric = analyzer.getVersion(FABRIC).orElse(null); String forge = analyzer.getVersion(FORGE).orElse(null); String liteLoader = analyzer.getVersion(LITELOADER).orElse(null); String optiFine = analyzer.getVersion(OPTIFINE).orElse(null); + String fabric = analyzer.getVersion(FABRIC).orElse(null); + String fabricApi = analyzer.getVersion(FABRIC_API).orElse(null); InstallerItem[] libraries = group.getLibraries(); - String[] versions = new String[]{game, fabric, forge, liteLoader, optiFine}; + String[] versions = new String[]{game, forge, liteLoader, optiFine, fabric, fabricApi}; String currentGameVersion = Lang.nonNull(getVersion("game"), game); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java index a50b4ad6d..d6c8faa67 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java @@ -32,6 +32,7 @@ import javafx.scene.layout.StackPane; import org.jackhuang.hmcl.download.DownloadProvider; import org.jackhuang.hmcl.download.RemoteVersion; import org.jackhuang.hmcl.download.VersionList; +import org.jackhuang.hmcl.download.fabric.FabricAPIRemoteVersion; import org.jackhuang.hmcl.download.fabric.FabricRemoteVersion; import org.jackhuang.hmcl.download.forge.ForgeRemoteVersion; import org.jackhuang.hmcl.download.game.GameRemoteVersion; @@ -180,6 +181,13 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres } else { content.setSubtitle(remoteVersion.getGameVersion()); } + } else if (remoteVersion instanceof FabricAPIRemoteVersion) { + content.setImage(new Image("/assets/img/fabric.png", 32, 32, false, true)); + if (StringUtils.isNotBlank(content.getSubtitle())) { + content.getTags().setAll(remoteVersion.getGameVersion()); + } else { + content.setSubtitle(remoteVersion.getGameVersion()); + } } } }); diff --git a/HMCL/src/main/resources/assets/lang/I18N.properties b/HMCL/src/main/resources/assets/lang/I18N.properties index a9c7bd0f2..1cd828c6d 100644 --- a/HMCL/src/main/resources/assets/lang/I18N.properties +++ b/HMCL/src/main/resources/assets/lang/I18N.properties @@ -275,7 +275,9 @@ install.failed.optifine_conflict=Fabric, OptiFine and Forge are installed simult install.failed.version_mismatch=The library requires the game version %s, but the actual version is %s. install.installer.change_version=%s, this version is not compatible with current game version. Click here to choose another one. install.installer.choose=Choose a %s version +install.installer.depend=Depends on %s install.installer.fabric=Fabric +install.installer.fabric-api=Fabric API install.installer.forge=Forge install.installer.game=Minecraft install.installer.incompatible=Incompatible with %s diff --git a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties index a8563bbf6..404e073f9 100644 --- a/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties +++ b/HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties @@ -279,7 +279,9 @@ install.failed.optifine_conflict=暂不支持 OptiFine, Fabric 与 Forge 同时 install.failed.version_mismatch=该软件需要的游戏版本为 %s,但实际的游戏版本为 %s。 install.installer.change_version=%s,该版本与当前游戏不兼容,您需要点击此处更换版本或删除 install.installer.choose=选择 %s 版本 +install.installer.depend=需要先安装 %s install.installer.fabric=Fabric +install.installer.fabric-api=Fabric API install.installer.forge=Forge install.installer.game=Minecraft install.installer.incompatible=与 %s 不兼容 diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/BalancedDownloadProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/BalancedDownloadProvider.java index feee75c81..c8ef40f8d 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/BalancedDownloadProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/BalancedDownloadProvider.java @@ -17,7 +17,9 @@ */ package org.jackhuang.hmcl.download; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -29,31 +31,10 @@ import java.util.stream.Collectors; public class BalancedDownloadProvider implements DownloadProvider { List candidates; - VersionList game, fabric, forge, liteLoader, optifine; + Map> versionLists = new HashMap<>(); public BalancedDownloadProvider(List candidates) { this.candidates = candidates; - - this.game = new MultipleSourceVersionList( - candidates.stream() - .map(downloadProvider -> downloadProvider.getVersionListById("game")) - .collect(Collectors.toList())); - this.fabric = new MultipleSourceVersionList( - candidates.stream() - .map(downloadProvider -> downloadProvider.getVersionListById("fabric")) - .collect(Collectors.toList())); - this.forge = new MultipleSourceVersionList( - candidates.stream() - .map(downloadProvider -> downloadProvider.getVersionListById("forge")) - .collect(Collectors.toList())); - this.liteLoader = new MultipleSourceVersionList( - candidates.stream() - .map(downloadProvider -> downloadProvider.getVersionListById("liteloader")) - .collect(Collectors.toList())); - this.optifine = new MultipleSourceVersionList( - candidates.stream() - .map(downloadProvider -> downloadProvider.getVersionListById("optifine")) - .collect(Collectors.toList())); } @Override @@ -73,20 +54,13 @@ public class BalancedDownloadProvider implements DownloadProvider { @Override public VersionList getVersionListById(String id) { - switch (id) { - case "game": - return game; - case "fabric": - return fabric; - case "forge": - return forge; - case "liteloader": - return liteLoader; - case "optifine": - return optifine; - default: - throw new IllegalArgumentException("Unrecognized version list id: " + id); + if (!versionLists.containsKey(id)) { + versionLists.put(id, new MultipleSourceVersionList( + candidates.stream() + .map(downloadProvider -> downloadProvider.getVersionListById(id)) + .collect(Collectors.toList()))); } + return versionLists.get(id); } @Override diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java index b283d45aa..172aecc93 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/LibraryAnalyzer.java @@ -157,6 +157,7 @@ public final class LibraryAnalyzer implements Iterable[0-9.]+)(-([0-9.]+))?$"); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java index 870ec9e27..9b5dd049d 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/MojangDownloadProvider.java @@ -17,6 +17,7 @@ */ package org.jackhuang.hmcl.download; +import org.jackhuang.hmcl.download.fabric.FabricAPIVersionList; import org.jackhuang.hmcl.download.fabric.FabricVersionList; import org.jackhuang.hmcl.download.forge.ForgeBMCLVersionList; import org.jackhuang.hmcl.download.game.GameVersionList; @@ -30,6 +31,7 @@ import org.jackhuang.hmcl.download.optifine.OptiFineBMCLVersionList; public class MojangDownloadProvider implements DownloadProvider { private final GameVersionList game; private final FabricVersionList fabric; + private final FabricAPIVersionList fabricApi; private final ForgeBMCLVersionList forge; private final LiteLoaderVersionList liteLoader; private final OptiFineBMCLVersionList optifine; @@ -39,6 +41,7 @@ public class MojangDownloadProvider implements DownloadProvider { this.game = new GameVersionList(this); this.fabric = new FabricVersionList(this); + this.fabricApi = new FabricAPIVersionList(this); this.forge = new ForgeBMCLVersionList(apiRoot); this.liteLoader = new LiteLoaderVersionList(this); this.optifine = new OptiFineBMCLVersionList(apiRoot); @@ -61,6 +64,8 @@ public class MojangDownloadProvider implements DownloadProvider { return game; case "fabric": return fabric; + case "fabric-api": + return fabricApi; case "forge": return forge; case "liteloader": diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/RemoteVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/RemoteVersion.java index ec5c0f1da..6b4421907 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/RemoteVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/RemoteVersion.java @@ -79,6 +79,10 @@ public class RemoteVersion implements Comparable { return selfVersion; } + public String getFullVersion() { + return getSelfVersion(); + } + public Instant getReleaseDate() { return releaseDate; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIInstallTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIInstallTask.java new file mode 100644 index 000000000..f080441af --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIInstallTask.java @@ -0,0 +1,69 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2021 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jackhuang.hmcl.download.fabric; + +import org.jackhuang.hmcl.download.DefaultDependencyManager; +import org.jackhuang.hmcl.download.LibraryAnalyzer; +import org.jackhuang.hmcl.game.*; +import org.jackhuang.hmcl.task.Task; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; + +/** + * Note: Fabric should be installed first. + * + * @author huangyuhui + */ +public final class FabricAPIInstallTask extends Task { + + private final DefaultDependencyManager dependencyManager; + private final Version version; + private final FabricAPIRemoteVersion remote; + private final List> dependencies = new LinkedList<>(); + + public FabricAPIInstallTask(DefaultDependencyManager dependencyManager, Version version, FabricAPIRemoteVersion remoteVersion) { + this.dependencyManager = dependencyManager; + this.version = version; + this.remote = remoteVersion; + } + + @Override + public Collection> getDependencies() { + return dependencies; + } + + @Override + public boolean isRelyingOnDependencies() { + return false; + } + + @Override + public void execute() { + List libraries = new ArrayList<>(); + libraries.add(new Library(new Artifact("net", "fabricmc", "fabric-api"), null, + new LibrariesDownloadInfo(new LibraryDownloadInfo( + "net/fabricmc/fabric-api/" + remote.getFullVersion() + "/fabric-api-" + remote.getFullVersion() + ".jar", + remote.getUrls().get(0))))); + + setResult(new Version(LibraryAnalyzer.LibraryType.FABRIC_API.getPatchId(), remote.getSelfVersion(), 31000, new Arguments(), null, libraries)); + dependencies.add(dependencyManager.checkLibraryCompletionAsync(getResult(), true)); + } +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIRemoteVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIRemoteVersion.java new file mode 100644 index 000000000..479d48497 --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIRemoteVersion.java @@ -0,0 +1,52 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2021 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jackhuang.hmcl.download.fabric; + +import org.jackhuang.hmcl.download.*; +import org.jackhuang.hmcl.game.Version; +import org.jackhuang.hmcl.task.Task; + +import java.util.List; + +public class FabricAPIRemoteVersion extends RemoteVersion { + private final String fullVersion; + + /** + * Constructor. + * + * @param gameVersion the Minecraft version that this remote version suits. + * @param selfVersion the version string of the remote version. + * @param urls the installer or universal jar original URL. + */ + FabricAPIRemoteVersion(String gameVersion, String selfVersion, String fullVersion, List urls) { + super(LibraryAnalyzer.LibraryType.FABRIC_API.getPatchId(), gameVersion, selfVersion, null, urls); + + this.fullVersion = fullVersion; + } + + @Override + public String getFullVersion() { + return fullVersion; + } + + @Override + public Task getInstallTask(DefaultDependencyManager dependencyManager, Version baseVersion) { + return new FabricAPIInstallTask(dependencyManager, baseVersion, this); + } + +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java new file mode 100644 index 000000000..218f4ae8c --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/fabric/FabricAPIVersionList.java @@ -0,0 +1,86 @@ +/* + * Hello Minecraft! Launcher + * Copyright (C) 2021 huangyuhui and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.jackhuang.hmcl.download.fabric; + +import org.jackhuang.hmcl.download.DownloadProvider; +import org.jackhuang.hmcl.download.VersionList; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.util.Collection; +import java.util.Collections; +import java.util.concurrent.CompletableFuture; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.jackhuang.hmcl.util.Lang.wrap; + +public class FabricAPIVersionList extends VersionList { + + private final DownloadProvider downloadProvider; + + public FabricAPIVersionList(DownloadProvider downloadProvider) { + this.downloadProvider = downloadProvider; + } + + @Override + public boolean hasType() { + return false; + } + + @Override + public CompletableFuture refreshAsync() { + return CompletableFuture.runAsync(wrap(() -> { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document doc = builder.parse(downloadProvider.injectURL("https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml")); + Element r = doc.getDocumentElement(); + NodeList versionElements = r.getElementsByTagName("version"); + for (int i = 0; i < versionElements.getLength(); i++) { + String versionName = versionElements.item(i).getTextContent(); + + Matcher matcher = FABRIC_VERSION_PATTERN.matcher(versionName); + if (matcher.find()) { + String fabricVersion = matcher.group("version"); + if (matcher.group("build") != null) { + fabricVersion += "." + matcher.group("build"); + } + String gameVersion = matcher.group("mcversion"); + versions.put(gameVersion, new FabricAPIRemoteVersion(gameVersion, fabricVersion, versionName, + Collections.singletonList(String.format( + "https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/%1$s/fabric-api-%1$s.jar", versionName)))); + } + } + })); + } + + @Override + protected Collection getVersionsImpl(String gameVersion) { + Matcher matcher = GAME_VERSION_PATTERN.matcher(gameVersion); + if (matcher.find()) { + return super.getVersionsImpl(String.format("%s.%s", matcher.group("major"), matcher.group("minor"))); + } + return super.getVersionsImpl(gameVersion); + } + + private static final Pattern FABRIC_VERSION_PATTERN = Pattern.compile("^(?[0-9.]+)\\+(build\\.(?\\d+)-)?(?[0-9.]+)$"); + private static final Pattern GAME_VERSION_PATTERN = Pattern.compile("^(?[0-9]+)\\.(?[0-9]+)"); +}