Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
edewit committed Jul 1, 2023
2 parents 574a5e9 + 8c3c89f commit 6675c25
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(() -> {

});
Expand Down
2 changes: 2 additions & 0 deletions storeys/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>) s -> true);

return (Script) engine.eval(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class DynamicAction implements Action<Void> {
CompletableFuture<Void> future = new CompletableFuture<>();

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
ScriptEngine engine = manager.getEngineByName("graal.js");
engine.put("player", context.getCommandCause());

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* ch.vorburger.minecraft.storeys
*
* Copyright (C) 2016 - 2018 Michael Vorburger.ch <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<ScriptEngineFactory> 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"));
}
}
7 changes: 7 additions & 0 deletions web/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.<clinit>(DnsNameResolver.java:103)
relocate 'io.netty', 'ch.vorburger.relocated.io.netty'
mergeServiceFiles()

dependencies {
// https://imperceptiblethoughts.com/shadow/configuration/filtering/
Expand Down Expand Up @@ -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'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down

0 comments on commit 6675c25

Please sign in to comment.