Skip to content

Commit

Permalink
include MC Jar
Browse files Browse the repository at this point in the history
  • Loading branch information
wdog5734 committed Oct 17, 2024
1 parent 61667d9 commit feb3bee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 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 @@ -206,6 +210,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.20.1.jar");
var dir = Paths.get("libraries", "net/minecraft/server/1.20.1");
if (!Files.exists(dir)) {
Files.createDirectories(dir);
}
var mc = dir.resolve("server-1.20.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

0 comments on commit feb3bee

Please sign in to comment.