diff --git a/build.xml b/build.xml index 29c664c92..f3fe8bbbf 100644 --- a/build.xml +++ b/build.xml @@ -63,8 +63,8 @@ diff --git a/src/docs/java/jscript.java b/src/docs/java/jscript.java index 5b06fd541..d93af8a78 100644 --- a/src/docs/java/jscript.java +++ b/src/docs/java/jscript.java @@ -8,6 +8,12 @@ public static void main(String[] args) throws Exception { ScriptEngineManager factory = new ScriptEngineManager(); ScriptEngine engine = factory.getEngineByName("JavaScript"); + + // https://docs.oracle.com/en/graalvm/enterprise/21/docs/reference-manual/js/ScriptEngine/ + Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); + bindings.put("polyglot.js.allowAllAccess", true); + bindings.put("polyglot.js.nashorn-compat", true); + java.io.File file = new java.io.File(args[0]); engine.put("engine",engine); engine.put("args",args); diff --git a/src/main/java/bukkit/org/scriptcraftjs/bukkit/ScriptCraftPlugin.java b/src/main/java/bukkit/org/scriptcraftjs/bukkit/ScriptCraftPlugin.java index d65736910..1da63f281 100644 --- a/src/main/java/bukkit/org/scriptcraftjs/bukkit/ScriptCraftPlugin.java +++ b/src/main/java/bukkit/org/scriptcraftjs/bukkit/ScriptCraftPlugin.java @@ -4,7 +4,9 @@ import org.bukkit.command.CommandSender; import org.bukkit.plugin.java.JavaPlugin; +import javax.script.Bindings; import javax.script.Invocable; +import javax.script.ScriptContext; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import java.io.InputStreamReader; @@ -32,6 +34,11 @@ public class ScriptCraftPlugin extends JavaPlugin if (this.engine == null) { this.getLogger().severe(NO_JAVASCRIPT_MESSAGE); } else { + // https://docs.oracle.com/en/graalvm/enterprise/21/docs/reference-manual/js/ScriptEngine/ + Bindings bindings = this.engine.getBindings(ScriptContext.ENGINE_SCOPE); + bindings.put("polyglot.js.allowAllAccess", true); + bindings.put("polyglot.js.nashorn-compat", true); + Invocable inv = (Invocable) this.engine; this.engine.eval(new InputStreamReader(this.getResource("boot.js"))); inv.invokeFunction("__scboot", this, engine); diff --git a/src/main/js/lib/task-bukkit.js b/src/main/js/lib/task-bukkit.js index 444e1422a..a092f6ab0 100644 --- a/src/main/js/lib/task-bukkit.js +++ b/src/main/js/lib/task-bukkit.js @@ -2,9 +2,10 @@ /*global __plugin, module, server*/ function bukkitSetTimeout(callback, delayInMillis) { var delay = Math.ceil(delayInMillis / 50); - var task = server.scheduler[ - 'runTaskLater(org.bukkit.plugin.Plugin, java.lang.Runnable ,long)' - ](__plugin, callback, delay); + // https://github.com/walterhiggins/ScriptCraft/issues/396 + var Run = Java.type('java.lang.Runnable'); + var MyRun = Java.extend(Run, { run: callback }); + var task = server.scheduler.runTaskLater(__plugin, new MyRun(), delay); return task; } function bukkitClearTimeout(task) { @@ -12,9 +13,10 @@ function bukkitClearTimeout(task) { } function bukkitSetInterval(callback, intervalInMillis) { var delay = Math.ceil(intervalInMillis / 50); - var task = server.scheduler[ - 'runTaskTimer(org.bukkit.plugin.Plugin, java.lang.Runnable ,long, long)' - ](__plugin, callback, delay, delay); + // https://github.com/walterhiggins/ScriptCraft/issues/396 + var Run = Java.type('java.lang.Runnable'); + var MyRun = Java.extend(Run, { run: callback }); + var task = server.scheduler.runTaskTimer(__plugin, new MyRun(), delay, delay); return task; } function bukkitClearInterval(bukkitTask) { diff --git a/src/main/js/modules/drone/index.js b/src/main/js/modules/drone/index.js index 369f7a696..f43303220 100644 --- a/src/main/js/modules/drone/index.js +++ b/src/main/js/modules/drone/index.js @@ -346,7 +346,8 @@ function makeTypeIdAndDataSetter() { }; } else { try { - var CraftEvil = Java.type(server.class.package.name + '.util.CraftEvil'); + // https://github.com/walterhiggins/ScriptCraft/issues/447 + var CraftEvil = Java.type(server.class.package.name + '.legacy.CraftEvil'); console.log('Drone using CraftEvil.setTypeIdAndData method'); return function(block, typeId, data, applyPhysics) { CraftEvil.setTypeIdAndData(block, typeId, data, applyPhysics); @@ -386,7 +387,7 @@ function putBlock(x, y, z, blockId, metadata, world, update) { } } if (__plugin.bukkit) { - setTypeIdAndData(block, blockId, metadata, update); + setTypeIdAndData(block, blockId, metadata, !!update); } return block; }