diff --git a/api-jvm-impl/src/main/java/ch/vorburger/minecraft/storeys/japi/impl/EventsImpl.java b/api-jvm-impl/src/main/java/ch/vorburger/minecraft/storeys/japi/impl/EventsImpl.java index 4d4e0b77..4e56b210 100644 --- a/api-jvm-impl/src/main/java/ch/vorburger/minecraft/storeys/japi/impl/EventsImpl.java +++ b/api-jvm-impl/src/main/java/ch/vorburger/minecraft/storeys/japi/impl/EventsImpl.java @@ -75,7 +75,9 @@ class EventsImpl implements Events, Unregisterable { return; } registrar.get().register(plugin, spec, name); - //TODO Sponge.server().commandManager().updateCommandTreeForPlayer(); + Sponge.server().onlinePlayers().forEach(p -> Sponge.server().commandManager().updateCommandTreeForPlayer(p)); + + //TODO unregister commands so that we can update them unregistrables.add(() -> { }); diff --git a/storeys/build.gradle b/storeys/build.gradle index 407788e1..cee19827 100644 --- a/storeys/build.gradle +++ b/storeys/build.gradle @@ -7,6 +7,8 @@ repositories { dependencies { api project(':api-jvm-impl') implementation 'ch.vorburger:fswatch:1.3.0' + implementation 'org.graalvm.js:js-scriptengine:22.3.0' + runtimeOnly 'org.graalvm.js:js:22.3.0' implementation project(':example') testImplementation project(':test-utils') diff --git a/storeys/src/main/java/ch/vorburger/minecraft/storeys/ScriptsLoader.java b/storeys/src/main/java/ch/vorburger/minecraft/storeys/ScriptsLoader.java index a1987515..bc1a31b3 100644 --- a/storeys/src/main/java/ch/vorburger/minecraft/storeys/ScriptsLoader.java +++ b/storeys/src/main/java/ch/vorburger/minecraft/storeys/ScriptsLoader.java @@ -31,8 +31,11 @@ import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; +import java.util.function.Predicate; import javax.inject.Inject; import javax.inject.Singleton; +import javax.script.Bindings; +import javax.script.ScriptContext; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; @@ -91,7 +94,10 @@ private Script load(Path file) throws IOException, ScriptException { final String result = template.replace("//SCRIPT", scriptFile); ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = manager.getEngineByName("JavaScript"); + ScriptEngine engine = manager.getEngineByName("graal.js"); + Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); + bindings.put("polyglot.js.allowHostAccess", true); + bindings.put("polyglot.js.allowHostClassLookup", (Predicate) s -> true); return (Script) engine.eval(result); } diff --git a/storeys/src/main/java/ch/vorburger/minecraft/storeys/model/DynamicAction.java b/storeys/src/main/java/ch/vorburger/minecraft/storeys/model/DynamicAction.java index 5dbacbb3..d492e8ca 100644 --- a/storeys/src/main/java/ch/vorburger/minecraft/storeys/model/DynamicAction.java +++ b/storeys/src/main/java/ch/vorburger/minecraft/storeys/model/DynamicAction.java @@ -52,7 +52,7 @@ public class DynamicAction implements Action { CompletableFuture future = new CompletableFuture<>(); ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = manager.getEngineByName("JavaScript"); + ScriptEngine engine = manager.getEngineByName("graal.js"); engine.put("player", context.getCommandCause()); try { diff --git a/storeys/src/test/java/ch/vorburger/minecraft/storeys/tests/GraalTest.java b/storeys/src/test/java/ch/vorburger/minecraft/storeys/tests/GraalTest.java new file mode 100644 index 00000000..bfaf1f8d --- /dev/null +++ b/storeys/src/test/java/ch/vorburger/minecraft/storeys/tests/GraalTest.java @@ -0,0 +1,39 @@ +/* + * ch.vorburger.minecraft.storeys + * + * Copyright (C) 2016 - 2018 Michael Vorburger.ch + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package ch.vorburger.minecraft.storeys.tests; + +import java.util.List; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineFactory; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; +import org.junit.Test; + +public class GraalTest { + + @Test public void testJsEngine() throws ScriptException { + List engines = (new ScriptEngineManager()).getEngineFactories(); + for (ScriptEngineFactory f : engines) { + System.out.println(f.getLanguageName() + " " + f.getEngineName() + " " + f.getNames().toString()); + } + + final ScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName("graal.js"); + System.out.println(scriptEngine.eval("1+1")); + } +} diff --git a/web/build.gradle b/web/build.gradle index f683b707..4fc76831 100644 --- a/web/build.gradle +++ b/web/build.gradle @@ -42,6 +42,7 @@ shadowJar { // Relocate shaded Netty dependency, because Minecraft Server uses (a very OLD version of!) Netty itself // causing java.lang.NoSuchMethodError: io.netty.util.NetUtil.isIpV4StackPreferred()Z at io.netty.resolver.dns.DnsNameResolver.(DnsNameResolver.java:103) relocate 'io.netty', 'ch.vorburger.relocated.io.netty' + mergeServiceFiles() dependencies { // https://imperceptiblethoughts.com/shadow/configuration/filtering/ @@ -80,6 +81,12 @@ shadowJar { include(dependency("io.netty:netty-codec-http")) include(dependency("io.netty:netty-codec-http2")) include(dependency("com.fasterxml.jackson.core:jackson-core")) + include(dependency("org.graalvm.js:js-scriptengine")) + include(dependency("org.graalvm.js:js")) + include(dependency("org.graalvm.truffle:truffle-api")) + include(dependency("org.graalvm.sdk:graal-sdk")) + include(dependency("org.graalvm.regex:regex")) + include(dependency("com.ibm.icu:icu4j")) exclude 'module-info.class' } } diff --git a/web/src/main/java/ch/vorburger/minecraft/storeys/web/StoreysWebPlugin.java b/web/src/main/java/ch/vorburger/minecraft/storeys/web/StoreysWebPlugin.java index 276fb439..8081c163 100644 --- a/web/src/main/java/ch/vorburger/minecraft/storeys/web/StoreysWebPlugin.java +++ b/web/src/main/java/ch/vorburger/minecraft/storeys/web/StoreysWebPlugin.java @@ -59,7 +59,6 @@ } @Override public void start(PluginInstance plugin, Path configDir) { - LOG.info("See https://github.com/OASIS-learn-study/minecraft-storeys-maker for how to use /story and /narrate commands"); super.start(plugin, configDir); Injector injector = pluginInjector.createChildInjector(binder -> {