diff --git a/.gitignore b/.gitignore index aafef55..532b6a7 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,10 @@ local.properties .factorypath .apt_generated/ +# VSCode stuff +.vscode/ +.classpath + # macOS .DS_Store @@ -42,4 +46,4 @@ ehthumbs_vista.db .gradletasknamecache # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.ja +!gradle-wrapper.jar diff --git a/build.gradle.kts b/build.gradle.kts index 6e70848..40ae42b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -15,7 +15,7 @@ subprojects { val mainClass = "io.papermc.paperclip.Main" tasks.jar { - val java6Jar = project(":java6").tasks.named("jar") + val java6Jar = project(":java6").tasks.named("shadowJar") val java17Jar = project(":java17").tasks.named("shadowJar") dependsOn(java6Jar, java17Jar) diff --git a/java6/build.gradle.kts b/java6/build.gradle.kts index df69ef6..dfad228 100644 --- a/java6/build.gradle.kts +++ b/java6/build.gradle.kts @@ -1,5 +1,14 @@ plugins { java + id("com.github.johnrengelman.shadow") version "8.1.1" +} + +repositories { + mavenCentral() +} + +dependencies { + implementation("com.eclipsesource.minimal-json:minimal-json:0.9.5") } java { @@ -14,3 +23,13 @@ tasks.withType().configureEach { options.release.set(6) options.compilerArgs = listOf("-Xlint:-options") } + +tasks.shadowJar { + val prefix = "paperclip.libs" + listOf("com.eclipsesource").forEach { pack -> + relocate(pack, "$prefix.$pack") + } + + exclude("META-INF/LICENSE.txt") + exclude("META-INF/NOTICE.txt") +} \ No newline at end of file diff --git a/java6/src/main/java/io/papermc/paperclip/Main.java b/java6/src/main/java/io/papermc/paperclip/Main.java index 0a06a68..f4d3adf 100644 --- a/java6/src/main/java/io/papermc/paperclip/Main.java +++ b/java6/src/main/java/io/papermc/paperclip/Main.java @@ -9,14 +9,46 @@ package io.papermc.paperclip; +import com.eclipsesource.json.Json; +import com.eclipsesource.json.JsonObject; + +import java.io.IOException; +import java.io.InputStreamReader; import java.lang.reflect.Method; public final class Main { + private static final JsonObject VERSION = readJsonFile(); + + private static JsonObject readJsonFile() { + final JsonObject object; + + InputStreamReader reader = null; + + try { + reader = new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("version.json"), "UTF_8"); + object = Json.parse(reader).asObject(); + } catch (final IOException exc) { + throw new RuntimeException("Failed to read version.json", exc); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + + return object; + } + 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. " + - "Download Java 17 (or above) from https://adoptium.net/"); + final int javaVersion = VERSION.getInt("java_version", 17); + final String minecraftVersion = VERSION.getString("name", "Unknown"); + if (getJavaVersion() < javaVersion) { + System.err.printf("Minecraft %s requires running the server with Java %s or above. " + + "Download Java %s (or above) from https://adoptium.net/", minecraftVersion, javaVersion, javaVersion); System.exit(1); } diff --git a/settings.gradle.kts b/settings.gradle.kts index cec4074..f4b2915 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,4 +3,4 @@ plugins { } rootProject.name = "paperclip" -include("java6", "java17") +include("java6", "java17") \ No newline at end of file