From 50db1d11a7750b474d01117e0d638db4cdea7b6d Mon Sep 17 00:00:00 2001 From: Julian Krings Date: Tue, 8 Jul 2025 12:30:21 +0200 Subject: [PATCH] move script engine libraries into the iris plugin folder --- build.gradle.kts | 4 ++- .../core/scripting/ExecutionEnvironment.java | 34 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index d3cfd5fee..4ae285a40 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -63,7 +63,8 @@ val serverMinHeap = "2G" val serverMaxHeap = "8G" //Valid values are: none, truecolor, indexed256, indexed16, indexed8 val color = "truecolor" -val errorReporting = false +val errorReporting = findProperty("errorReporting") as Boolean? ?: false +val scriptVersion = findProperty("scriptVersion") as String? ?: "master-SNAPSHOT" val nmsBindings = mapOf( "v1_21_R5" to "1.21.7-R0.1-SNAPSHOT", @@ -110,6 +111,7 @@ nmsBindings.forEach { key, value -> systemProperty("net.kyori.ansi.colorLevel", color) systemProperty("com.mojang.eula.agree", true) systemProperty("iris.suppressReporting", !errorReporting) + systemProperty("iris.scriptVersion", scriptVersion) jvmArgs("-javaagent:${project(":core:agent").tasks.jar.flatMap { it.archiveFile }.get().asFile.absolutePath}") } } diff --git a/core/src/main/java/com/volmit/iris/core/scripting/ExecutionEnvironment.java b/core/src/main/java/com/volmit/iris/core/scripting/ExecutionEnvironment.java index 6620880db..2b6ab34b6 100644 --- a/core/src/main/java/com/volmit/iris/core/scripting/ExecutionEnvironment.java +++ b/core/src/main/java/com/volmit/iris/core/scripting/ExecutionEnvironment.java @@ -15,15 +15,20 @@ import java.io.File; import java.net.URI; import java.net.URL; import java.net.URLClassLoader; -import java.nio.file.Files; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.nio.file.Path; import java.util.*; @UtilityClass public class ExecutionEnvironment { - private static final String BASE_URL = "https://jitpack.io/com/github/VolmitSoftware/Iris-Scripts/%s/Iris-Scripts-%s-all.jar"; + private static final String VERSION = System.getProperty("iris.scriptVersion", "e08b6f893e"); + private static final String BASE_URL = "https://jitpack.io/com/github/VolmitSoftware/Iris-Scripts/" + VERSION + "/Iris-Scripts-" + VERSION + "-all.jar"; private static final Provider PROVIDER = ServiceLoader.load(Provider.class, buildLoader()) .findFirst() - .orElseThrow(); + .orElseThrow() + .init(Iris.instance.getDataFolder("cache", "libraries").toPath()); @NonNull public static Engine createEngine(@NonNull com.volmit.iris.engine.framework.Engine engine) { @@ -42,21 +47,24 @@ public class ExecutionEnvironment { @SneakyThrows private static URLClassLoader buildLoader() { - String version = "e08b6f893e"; - String url = BASE_URL.formatted(version, version); - String hash = IO.hash("Iris-Scripts.jar@" + version); - var file = Iris.instance.getDataFile("cache", hash.substring(0, 2), hash.substring(3, 5), hash + ".jar"); - if (!file.exists()) { - Iris.info("Downloading Script Engine..."); - try (var stream = URI.create(url).toURL().openStream()) { - Files.copy(stream, file.toPath()); + try (HttpClient client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS).build()) { + var resolved = client.send(HttpRequest.newBuilder(URI.create(BASE_URL)).build(), HttpResponse.BodyHandlers.discarding()) + .request(); + String hash = IO.hash(resolved.uri().getPath()); + File file = Iris.instance.getDataFile("cache", hash.substring(0, 2), hash.substring(3, 5), hash + ".jar"); + if (!file.exists()) { + file.getParentFile().mkdirs(); + Iris.info("Downloading Script Engine..."); + client.send(resolved, HttpResponse.BodyHandlers.ofFile(file.toPath())); + Iris.info("Downloaded Script Engine!"); } - Iris.info("Downloaded Script Engine!"); + return new URLClassLoader(new URL[]{file.toURI().toURL()}, Provider.class.getClassLoader()); } - return new URLClassLoader(new URL[]{file.toURI().toURL()}, Provider.class.getClassLoader()); } public interface Provider { + Provider init(Path localRepository); + @NonNull Engine createEngine(@NonNull com.volmit.iris.engine.framework.Engine engine);