Skip to content

Commit

Permalink
Auto include MC Jar
Browse files Browse the repository at this point in the history
  • Loading branch information
wdog5734 committed Oct 17, 2024
1 parent 2a9c287 commit 4c9c751
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ allprojects {
name = 'mohist'
url = 'https://maven.mohistmc.com/'
}
maven {
name = 'mohist lib'
url = 'https://maven.mohistmc.com/libraries'
}
maven {
name = 'izzel'
url = 'https://maven.izzel.io/releases'
Expand Down Expand Up @@ -161,6 +165,7 @@ dependencies {
include(project("banner-server"))
include(project("banner-plugin"))
include(project("banner-bootstrap"))
include("net.minecraft:server:${project.minecraft_version}")
}

tasks.withType(JavaCompile).configureEach {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/mohistmc/banner/BannerMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,36 @@ public static void main(String[] args) throws Throwable {
}
}

private static Path extractMC() throws Exception {
var path = BannerMain.class.getModule().getResourceAsStream("/META-INF/jars/server-1.21.1.jar");
var dir = Paths.get("libraries", "net/minecraft/server/1.21.1");
if (!Files.exists(dir)) {
Files.createDirectories(dir);
}
var mc = dir.resolve("server-1.21.1.jar");
if (!Files.exists(mc)) {
try (var files = Files.list(dir)) {
for (Path old : files.toList()) {
Files.delete(old);
}
Files.copy(path, mc);
}
}
return mc;
}

@SuppressWarnings("unchecked")
private static Map.Entry<String, List<Path>> fabricInstall() throws Throwable {
var path = Paths.get(".banner", "gson.jar");
if (!Files.exists(path)) {
Files.createDirectories(path.getParent());
Files.copy(Objects.requireNonNull(BannerMain.class.getResourceAsStream("/gson.jar")), path);
}
try {
extractMC();
} catch (Exception e) {
System.out.println("Failed to extract MC Jar");
}
try (var loader = new URLClassLoader(new URL[]{path.toUri().toURL(), BannerMain.class.getProtectionDomain().getCodeSource().getLocation()}, ClassLoader.getPlatformClassLoader())) {
var cl = loader.loadClass("com.mohistmc.banner.install.FabricInstaller");
var handle = MethodHandles.lookup().findStatic(cl, "applicationInstall", MethodType.methodType(Map.Entry.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static Map<String, Map.Entry<String, String>> fabricDeps(Path fabricLoad

@SuppressWarnings("unchecked")
private static CompletableFuture<Path>[] installFabric(InstallInfo info, ExecutorService pool, Consumer<String> logger) {
var minecraftData = MinecraftProvider.downloadMinecraftData(info, pool, logger);
//var minecraftData = MinecraftProvider.downloadMinecraftData(info, pool, logger);
String coord = String.format("net.fabricmc:fabric-loader:%s", info.installer.fabricLoader);
String dist = "libraries/" + Util.mavenToPath(coord);
var installerFuture = MinecraftProvider.reportSupply(pool, logger).apply(new MavenDownloader(Mirrors.getMavenRepo(), coord, dist, info.installer.fabricLoaderHash))
Expand All @@ -120,10 +120,11 @@ private static CompletableFuture<Path>[] installFabric(InstallInfo info, Executo
throw new RuntimeException(e);
}
});
/*
var serverFuture = minecraftData.thenCompose(data -> MinecraftProvider.reportSupply(pool, logger).apply(
new FileDownloader(String.format(data.serverUrl(), info.installer.minecraft),
String.format("libraries/net/minecraft/server/%1$s/server-%1$s.jar", info.installer.minecraft), data.serverHash())
));
return new CompletableFuture[]{installerFuture, serverFuture};
));*/
return new CompletableFuture[]{installerFuture};
}
}

0 comments on commit 4c9c751

Please sign in to comment.