diff --git a/build.gradle.kts b/build.gradle.kts index 6e70848..8eacc04 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,11 +15,9 @@ subprojects { val mainClass = "io.papermc.paperclip.Main" tasks.jar { - val java6Jar = project(":java6").tasks.named("jar") val java17Jar = project(":java17").tasks.named("shadowJar") - dependsOn(java6Jar, java17Jar) + dependsOn(java17Jar) - from(zipTree(java6Jar.map { it.outputs.files.singleFile })) from(zipTree(java17Jar.map { it.outputs.files.singleFile })) manifest { @@ -42,83 +40,14 @@ tasks.jar { } val sourcesJar by tasks.registering(Jar::class) { - val java6Sources = project(":java6").tasks.named("sourcesJar") val java17Sources = project(":java17").tasks.named("sourcesJar") - dependsOn(java6Sources, java17Sources) - - from(zipTree(java6Sources.map { it.outputs.files.singleFile })) + dependsOn(java17Sources) from(zipTree(java17Sources.map { it.outputs.files.singleFile })) - archiveClassifier.set("sources") } val isSnapshot = project.version.toString().endsWith("-SNAPSHOT") -publishing { - publications { - register("maven") { - groupId = project.group.toString() - artifactId = project.name - version = project.version.toString() - - from(components["java"]) - artifact(sourcesJar) - withoutBuildIdentifier() - - pom { - val repoPath = "PaperMC/Paperclip" - val repoUrl = "https://github.com/$repoPath" - - name.set("Paperclip") - description.set(project.description) - url.set(repoUrl) - packaging = "jar" - - licenses { - license { - name.set("MIT") - url.set("$repoUrl/blob/main/license.txt") - distribution.set("repo") - } - } - - issueManagement { - system.set("GitHub") - url.set("$repoUrl/issues") - } - - developers { - developer { - id.set("DemonWav") - name.set("Kyle Wood") - email.set("demonwav@gmail.com") - url.set("https://github.com/DemonWav") - } - } - - scm { - url.set(repoUrl) - connection.set("scm:git:$repoUrl.git") - developerConnection.set("scm:git:git@github.com:$repoPath.git") - } - } - } - - repositories { - val url = if (isSnapshot) { - "https://repo.papermc.io/repository/maven-snapshots/" - } else { - "https://repo.papermc.io/repository/maven-releases/" - } - - maven(url) { - credentials(PasswordCredentials::class) - name = "paper" - } - } - } -} - tasks.register("printVersion") { doFirst { println(version) diff --git a/java17/build.gradle.kts b/java17/build.gradle.kts index d306503..f8a42d8 100644 --- a/java17/build.gradle.kts +++ b/java17/build.gradle.kts @@ -21,6 +21,7 @@ repositories { dependencies { implementation("io.sigpipe:jbsdiff:1.0") + compileOnly(files("D:\\idea\\project\\Allay\\Allay-API\\build\\libs\\Allay-API-0.0.1-all.jar")) } tasks.shadowJar { diff --git a/java17/src/main/java/io/papermc/paperclip/Paperclip.java b/java17/src/main/java/io/papermc/paperclip/Paperclip.java index a10744d..f6d0bde 100644 --- a/java17/src/main/java/io/papermc/paperclip/Paperclip.java +++ b/java17/src/main/java/io/papermc/paperclip/Paperclip.java @@ -1,55 +1,54 @@ package io.papermc.paperclip; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; +import cn.allay.api.datastruct.DynamicURLClassLoader; + +import java.io.*; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.net.URL; -import java.net.URLClassLoader; import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Path; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.Map; public final class Paperclip { + private static String workPath; + + public static void setup(DynamicURLClassLoader loader, final String[] args) { + workPath = args[0]; + File file = Path.of(workPath).toFile(); + if (!file.exists() || !file.isDirectory()) { + System.err.println("The working directory of je generator must be first param!"); + System.exit(1); + } - public static void main(final String[] args) { - if (Path.of("").toAbsolutePath().toString().contains("!")) { + if (Path.of(workPath).toAbsolutePath().toString().contains("!")) { System.err.println("Paperclip may not run in a directory containing '!'. Please rename the affected folder."); System.exit(1); } final URL[] classpathUrls = setupClasspath(); - - final ClassLoader parentClassLoader = Paperclip.class.getClassLoader().getParent(); - final URLClassLoader classLoader = new URLClassLoader(classpathUrls, parentClassLoader); - + for (var url : classpathUrls) { + loader.addURL(url); + } final String mainClassName = findMainClass(); System.out.println("Starting " + mainClassName); - - final Thread runThread = new Thread(() -> { - try { - final Class mainClass = Class.forName(mainClassName, true, classLoader); - final MethodHandle mainHandle = MethodHandles.lookup() + try { + final Class mainClass = Class.forName(mainClassName, true, loader); + final MethodHandle mainHandle = MethodHandles.lookup() .findStatic(mainClass, "main", MethodType.methodType(void.class, String[].class)) .asFixedArity(); - mainHandle.invoke((Object) args); - } catch (final Throwable t) { - throw Util.sneakyThrow(t); - } - }, "ServerMain"); - runThread.setContextClassLoader(classLoader); - runThread.start(); + mainHandle.invoke((Object) args); + } catch (final Throwable t) { + throw Util.sneakyThrow(t); + } } private static URL[] setupClasspath() { - final var repoDir = Path.of(System.getProperty("bundlerRepoDir", "")); + final var repoDir = Path.of(System.getProperty("bundlerRepoDir", workPath)); final PatchEntry[] patches = findPatches(); final DownloadContext downloadContext = findDownloadContext(); @@ -115,9 +114,11 @@ private static DownloadContext findDownloadContext() { private static FileEntry[] findVersionEntries() { return findFileEntries("versions.list"); } + private static FileEntry[] findLibraryEntries() { return findFileEntries("libraries.list"); } + private static FileEntry[] findFileEntries(final String fileName) { final InputStream libListStream = Paperclip.class.getResourceAsStream("/META-INF/" + fileName); if (libListStream == null) { @@ -199,12 +200,12 @@ private static Map> extractFiles(final PatchEntry[] pat } private static void extractEntries( - final Map urls, - final PatchEntry[] patches, - final Path originalRootDir, - final Path repoDir, - final FileEntry[] entries, - final String targetName + final Map urls, + final PatchEntry[] patches, + final Path originalRootDir, + final Path repoDir, + final FileEntry[] entries, + final String targetName ) throws IOException { if (entries == null) { return; @@ -219,10 +220,10 @@ private static void extractEntries( } private static void applyPatches( - final Map> urls, - final PatchEntry[] patches, - final Path originalJar, - final Path repoDir + final Map> urls, + final PatchEntry[] patches, + final Path originalJar, + final Path repoDir ) { if (patches.length == 0) { return; diff --git a/java6/build.gradle.kts b/java6/build.gradle.kts deleted file mode 100644 index df69ef6..0000000 --- a/java6/build.gradle.kts +++ /dev/null @@ -1,16 +0,0 @@ -plugins { - java -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - } - - withSourcesJar() -} - -tasks.withType().configureEach { - options.release.set(6) - options.compilerArgs = listOf("-Xlint:-options") -} diff --git a/java6/src/main/java/io/papermc/paperclip/Main.java b/java6/src/main/java/io/papermc/paperclip/Main.java deleted file mode 100644 index 5c30d9a..0000000 --- a/java6/src/main/java/io/papermc/paperclip/Main.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Paperclip - Paper Minecraft launcher - * - * Copyright (c) 2019 Kyle Wood (DemonWav) - * https://github.com/PaperMC/Paperclip - * - * MIT License - */ - -package io.papermc.paperclip; - -import java.lang.reflect.Method; - -public final class Main { - - public static void main(final String[] args) { - if (getJavaVersion() < 17) { - System.err.println("Minecraft 1.19 requires running the server with Java 17 or above. " + - "For information on how to update Java, see https://docs.papermc.io/misc/java-install"); - System.exit(1); - } - - try { - final Class paperclipClass = Class.forName("io.papermc.paperclip.Paperclip"); - final Method mainMethod = paperclipClass.getMethod("main", String[].class); - mainMethod.invoke(null, (Object) args); - } catch (final Exception e) { - e.printStackTrace(); - } - } - - private static int getJavaVersion() { - final String version = System.getProperty("java.specification.version"); - final String[] parts = version.split("\\."); - - final String errorMsg = "Could not determine version of the current JVM"; - if (parts.length == 0) { - throw new IllegalStateException(errorMsg); - } - - if (parts[0].equals("1")) { - if (parts.length < 2) { - throw new IllegalStateException(errorMsg); - } - return Integer.parseInt(parts[1]); - } else { - return Integer.parseInt(parts[0]); - } - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index cec4074..321011a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,4 +3,4 @@ plugins { } rootProject.name = "paperclip" -include("java6", "java17") +include("java17")