mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-21 11:43:27 +00:00
move script engine libraries into the iris plugin folder
This commit is contained in:
parent
badf108d56
commit
50db1d11a7
@ -63,7 +63,8 @@ val serverMinHeap = "2G"
|
|||||||
val serverMaxHeap = "8G"
|
val serverMaxHeap = "8G"
|
||||||
//Valid values are: none, truecolor, indexed256, indexed16, indexed8
|
//Valid values are: none, truecolor, indexed256, indexed16, indexed8
|
||||||
val color = "truecolor"
|
val color = "truecolor"
|
||||||
val errorReporting = false
|
val errorReporting = findProperty("errorReporting") as Boolean? ?: false
|
||||||
|
val scriptVersion = findProperty("scriptVersion") as String? ?: "master-SNAPSHOT"
|
||||||
|
|
||||||
val nmsBindings = mapOf(
|
val nmsBindings = mapOf(
|
||||||
"v1_21_R5" to "1.21.7-R0.1-SNAPSHOT",
|
"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("net.kyori.ansi.colorLevel", color)
|
||||||
systemProperty("com.mojang.eula.agree", true)
|
systemProperty("com.mojang.eula.agree", true)
|
||||||
systemProperty("iris.suppressReporting", !errorReporting)
|
systemProperty("iris.suppressReporting", !errorReporting)
|
||||||
|
systemProperty("iris.scriptVersion", scriptVersion)
|
||||||
jvmArgs("-javaagent:${project(":core:agent").tasks.jar.flatMap { it.archiveFile }.get().asFile.absolutePath}")
|
jvmArgs("-javaagent:${project(":core:agent").tasks.jar.flatMap { it.archiveFile }.get().asFile.absolutePath}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,15 +15,20 @@ import java.io.File;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
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.*;
|
import java.util.*;
|
||||||
|
|
||||||
@UtilityClass
|
@UtilityClass
|
||||||
public class ExecutionEnvironment {
|
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())
|
private static final Provider PROVIDER = ServiceLoader.load(Provider.class, buildLoader())
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElseThrow();
|
.orElseThrow()
|
||||||
|
.init(Iris.instance.getDataFolder("cache", "libraries").toPath());
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static Engine createEngine(@NonNull com.volmit.iris.engine.framework.Engine engine) {
|
public static Engine createEngine(@NonNull com.volmit.iris.engine.framework.Engine engine) {
|
||||||
@ -42,21 +47,24 @@ public class ExecutionEnvironment {
|
|||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
private static URLClassLoader buildLoader() {
|
private static URLClassLoader buildLoader() {
|
||||||
String version = "e08b6f893e";
|
try (HttpClient client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS).build()) {
|
||||||
String url = BASE_URL.formatted(version, version);
|
var resolved = client.send(HttpRequest.newBuilder(URI.create(BASE_URL)).build(), HttpResponse.BodyHandlers.discarding())
|
||||||
String hash = IO.hash("Iris-Scripts.jar@" + version);
|
.request();
|
||||||
var file = Iris.instance.getDataFile("cache", hash.substring(0, 2), hash.substring(3, 5), hash + ".jar");
|
String hash = IO.hash(resolved.uri().getPath());
|
||||||
if (!file.exists()) {
|
File file = Iris.instance.getDataFile("cache", hash.substring(0, 2), hash.substring(3, 5), hash + ".jar");
|
||||||
Iris.info("Downloading Script Engine...");
|
if (!file.exists()) {
|
||||||
try (var stream = URI.create(url).toURL().openStream()) {
|
file.getParentFile().mkdirs();
|
||||||
Files.copy(stream, file.toPath());
|
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 {
|
public interface Provider {
|
||||||
|
Provider init(Path localRepository);
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
Engine createEngine(@NonNull com.volmit.iris.engine.framework.Engine engine);
|
Engine createEngine(@NonNull com.volmit.iris.engine.framework.Engine engine);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user