Fabric server support
This commit is contained in:
parent
97251ea548
commit
5ff7f6b608
|
@ -24,7 +24,6 @@ import java.nio.file.Files;
|
|||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
|
||||
//TODO generate gitignore
|
||||
//TODO mods browser
|
||||
//TODO allow instance sync through metadata
|
||||
//TODO update checker
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.gitlab.jfronny.inceptum.util.Utils;
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
|
||||
public class LaunchCommand extends Command {
|
||||
|
@ -51,6 +52,12 @@ public class LaunchCommand extends Command {
|
|||
Inceptum.showError("Not a valid instance", e);
|
||||
return;
|
||||
}
|
||||
if (args.length > 3) {
|
||||
instance.gameArgsCustom = instance.gameArgsCustom == null ? new ArrayList<>() : new ArrayList<>(instance.gameArgsCustom);
|
||||
for (int i = 3, argsLength = args.length; i < argsLength; i++) {
|
||||
instance.gameArgsCustom.add(args[i]);
|
||||
}
|
||||
}
|
||||
if (args.length >= 3 && "server".equals(args[1].toLowerCase(Locale.ROOT)))
|
||||
ServerLauncher.launch(instanceDir, instance);
|
||||
else ClientLauncher.launch(instanceDir, instance);
|
||||
|
|
|
@ -3,14 +3,20 @@ package io.gitlab.jfronny.inceptum.install.steps;
|
|||
import io.gitlab.jfronny.inceptum.Inceptum;
|
||||
import io.gitlab.jfronny.inceptum.install.SetupStepInfo;
|
||||
import io.gitlab.jfronny.inceptum.install.Step;
|
||||
import io.gitlab.jfronny.inceptum.model.fabric.FabricInstallerVersion;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.LoaderInfo;
|
||||
import io.gitlab.jfronny.inceptum.model.mojang.MojangFileDownload;
|
||||
import io.gitlab.jfronny.inceptum.model.mojang.VersionInfo;
|
||||
import io.gitlab.jfronny.inceptum.util.Utils;
|
||||
import io.gitlab.jfronny.inceptum.util.api.FabricMetaApi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class DownloadClientStep implements Step {
|
||||
|
@ -18,10 +24,15 @@ public class DownloadClientStep implements Step {
|
|||
public void execute(SetupStepInfo info, AtomicBoolean stopThread) throws IOException {
|
||||
Path clientPath = Inceptum.LIBRARIES_DIR.resolve("net/minecraft/client");
|
||||
Path serverPath = Inceptum.LIBRARIES_DIR.resolve("net/minecraft/server");
|
||||
Path installerPath = Inceptum.LIBRARIES_DIR.resolve("net/fabricmc/fabric-installer");
|
||||
if (!Files.exists(clientPath)) Files.createDirectories(clientPath);
|
||||
if (!Files.exists(serverPath)) Files.createDirectories(serverPath);
|
||||
clientPath = clientPath.resolve(InstanceMeta.getMinecraftVersion(info.version().id) + ".jar");
|
||||
serverPath = serverPath.resolve(InstanceMeta.getMinecraftVersion(info.version().id) + ".jar");
|
||||
if (!Files.exists(installerPath)) Files.createDirectories(installerPath);
|
||||
String minecraftVersion = InstanceMeta.getMinecraftVersion(info.version().id);
|
||||
clientPath = clientPath.resolve(minecraftVersion + ".jar");
|
||||
serverPath = serverPath.resolve(minecraftVersion + ".jar");
|
||||
FabricInstallerVersion installerVersion = FabricMetaApi.getInstallerVersion();
|
||||
installerPath = installerPath.resolve("fabric-installer-" + installerVersion.version + "-" + minecraftVersion + ".jar");
|
||||
if (!Files.exists(clientPath)) {
|
||||
MojangFileDownload client = info.version().downloads.client;
|
||||
info.setState("Downloading Client");
|
||||
|
@ -32,5 +43,19 @@ public class DownloadClientStep implements Step {
|
|||
info.setState("Downloading Server");
|
||||
Utils.downloadFile(client.url, client.sha1, serverPath);
|
||||
}
|
||||
//TODO simplify once https://github.com/FabricMC/fabric-meta/pull/16 is merged
|
||||
if (!Files.exists(installerPath) && info.loader().type() == LoaderInfo.Type.Fabric) {
|
||||
info.setState("Downloading Fabric Installer");
|
||||
Utils.downloadFile(installerVersion.url.replace(".jar", "-server.jar"), installerPath);
|
||||
try (FileSystem fs = FileSystems.newFileSystem(new URI("jar", installerPath.toUri().toString(), null), Map.of("create", "true"))) {
|
||||
Files.writeString(fs.getPath("install.properties"),
|
||||
String.format("fabric-loader-version=%s\ngame-version=%s", info.loader().version(), minecraftVersion)
|
||||
);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
Files.delete(installerPath);
|
||||
throw new IOException("Could not create fabric installer", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package io.gitlab.jfronny.inceptum.model.fabric;
|
||||
|
||||
public class FabricInstallerVersion {
|
||||
public String url;
|
||||
public String maven;
|
||||
public String version;
|
||||
public boolean stable;
|
||||
}
|
|
@ -7,7 +7,7 @@ import java.util.List;
|
|||
public class InstanceMeta {
|
||||
@GsonIgnore public static final String floaderPrefix = "fabric-loader-";
|
||||
public String version;
|
||||
public String java; //TODO allow configuring
|
||||
public String java;
|
||||
public Long minMem;
|
||||
public Long maxMem;
|
||||
public List<String> jvmArgsCustom; //TODO allow configuring
|
||||
|
|
|
@ -30,11 +30,7 @@ public class ServerLauncher {
|
|||
try {
|
||||
List<String> args = new ArrayList<>();
|
||||
VersionInfo info = McApi.getVersionInfo(version);
|
||||
String mainClass = null;
|
||||
if (instance.isFabric()) {
|
||||
FabricMetaApi.addFabric(info, instance.getLoaderVersion(), FabricMetaApi.FabricVersionInfoType.Server);
|
||||
mainClass = info.mainClass;
|
||||
}
|
||||
info.libraries = new ArrayList<>();
|
||||
args.add(Objects.requireNonNullElseGet(instance.java, () ->
|
||||
Utils.getJvmMain(Inceptum.NATIVES_DIR
|
||||
.resolve(info.javaVersion.component)
|
||||
|
@ -46,20 +42,21 @@ public class ServerLauncher {
|
|||
classPath.append(Inceptum.LIBRARIES_DIR.resolve(artifact.path).toAbsolutePath());
|
||||
classPath.append(':');
|
||||
}
|
||||
Path serverJar = Inceptum.LIBRARIES_DIR.resolve("net/minecraft/server").resolve(version.id + ".jar").toAbsolutePath();
|
||||
classPath.append(serverJar);
|
||||
Path serverJar = instance.isFabric()
|
||||
? Inceptum.LIBRARIES_DIR.resolve("net/fabricmc/fabric-installer").resolve("fabric-installer-" + FabricMetaApi.getInstallerVersion().version + "-" + version.id + ".jar")
|
||||
: Inceptum.LIBRARIES_DIR.resolve("net/minecraft/server").resolve(version.id + ".jar");
|
||||
classPath.append(serverJar.toAbsolutePath()).append(':');
|
||||
if (instance.minMem != null) args.add("-Xms" + instance.minMem);
|
||||
if (instance.maxMem != null) args.add("-Xmx" + instance.maxMem);
|
||||
if (instance.jvmArgsCustom != null) args.addAll(instance.jvmArgsCustom);
|
||||
args.add("-cp");
|
||||
args.add(classPath.toString());
|
||||
if (mainClass == null) {
|
||||
final String linePrefix = "Main-Class: ";
|
||||
try (FileSystem fs = FileSystems.newFileSystem(new URI("jar", serverJar.toUri().toString(), null), new HashMap<>())) {
|
||||
for (String line : Files.readAllLines(fs.getPath("META-INF/MANIFEST.MF"))) {
|
||||
if (line.startsWith(linePrefix)) {
|
||||
mainClass = line.substring(linePrefix.length());
|
||||
}
|
||||
args.add(classPath.substring(0, classPath.length() - 1));
|
||||
String mainClass = null;
|
||||
final String linePrefix = "Main-Class: ";
|
||||
try (FileSystem fs = FileSystems.newFileSystem(new URI("jar", serverJar.toUri().toString(), null), new HashMap<>())) {
|
||||
for (String line : Files.readAllLines(fs.getPath("META-INF/MANIFEST.MF"))) {
|
||||
if (line.startsWith(linePrefix)) {
|
||||
mainClass = line.substring(linePrefix.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,10 @@ public class Utils {
|
|||
return new String(downloadData(url, sha1), StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
public static void downloadFile(String url, Path path) throws IOException {
|
||||
Files.write(path, downloadData(url));
|
||||
}
|
||||
|
||||
public static void downloadFile(String url, String sha1, Path path) throws IOException {
|
||||
Files.write(path, downloadData(url, sha1));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.gitlab.jfronny.inceptum.util.api;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import io.gitlab.jfronny.inceptum.model.fabric.FabricInstallerVersion;
|
||||
import io.gitlab.jfronny.inceptum.model.fabric.FabricVersionLoaderInfo;
|
||||
import io.gitlab.jfronny.inceptum.model.inceptum.InstanceMeta;
|
||||
import io.gitlab.jfronny.inceptum.model.mojang.Rules;
|
||||
|
@ -8,6 +9,7 @@ import io.gitlab.jfronny.inceptum.model.mojang.VersionInfo;
|
|||
import io.gitlab.jfronny.inceptum.model.mojang.VersionsListInfo;
|
||||
import io.gitlab.jfronny.inceptum.util.Utils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
@ -16,6 +18,7 @@ import java.util.List;
|
|||
|
||||
public class FabricMetaApi {
|
||||
private static final Type fabricLoaderVersionListType = new TypeToken<List<FabricVersionLoaderInfo>>() {}.getType();
|
||||
private static final Type fabricInstallerVersionListType = new TypeToken<List<FabricInstallerVersion>>() {}.getType();
|
||||
private static final String META_URL = "https://meta.fabricmc.net/";
|
||||
|
||||
public static List<FabricVersionLoaderInfo> getLoaderVersions(VersionsListInfo version) {
|
||||
|
@ -51,10 +54,21 @@ public class FabricMetaApi {
|
|||
floader.name = "net.fabricmc:fabric-loader:" + fabricVersion;
|
||||
floader.url = "https://maven.fabricmc.net/";
|
||||
libs.add(convertLib(floader));
|
||||
floader.name = ver.intermediary.maven;
|
||||
libs.add(convertLib(floader));//https://maven.fabricmc.net/net/fabricmc/fabric-installer/0.8.3/fabric-installer-0.8.3-server.jar
|
||||
version.libraries = List.copyOf(libs);
|
||||
version.id = InstanceMeta.floaderPrefix + fabricVersion + "-" + version.id;
|
||||
}
|
||||
|
||||
public static FabricInstallerVersion getInstallerVersion() throws IOException {
|
||||
List<FabricInstallerVersion> installerVersions = Utils.downloadObject(META_URL + "v2/versions/installer", fabricInstallerVersionListType);
|
||||
for (FabricInstallerVersion installerVersion : installerVersions) {
|
||||
if (installerVersion.stable)
|
||||
return installerVersion;
|
||||
}
|
||||
throw new FileNotFoundException("No stable installer was found");
|
||||
}
|
||||
|
||||
private static VersionInfo.Library convertLib(FabricVersionLoaderInfo.WithMeta.LauncherMeta.Libraries.Library library) {
|
||||
VersionInfo.Library res = new VersionInfo.Library();
|
||||
res.name = library.name;
|
||||
|
|
|
@ -46,7 +46,6 @@ public class InstanceEditWindow extends Window {
|
|||
});
|
||||
imc.snapshotsBox();
|
||||
imc.versionBox(ver -> {
|
||||
//TODO ensure version is downloaded
|
||||
reDownload = true;
|
||||
instance.version = ver;
|
||||
save();
|
||||
|
|
Loading…
Reference in New Issue