Skip to content

Commit

Permalink
patches from @ediloren for GraalVM 21.2.0 + SpigotMC 1.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
justinludwig committed Dec 9, 2021
1 parent eaf4e68 commit 87b667c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@

<target name="compile-plugins" depends="init" description="compile canary plugin source">
<javac includeantruntime="false"
source="1.6"
target="1.6"
source="1.9"
target="1.9"
destdir="${build}"
debug="true">
<src path="${src.canary}"/>
Expand Down
6 changes: 6 additions & 0 deletions src/docs/java/jscript.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 8 additions & 6 deletions src/main/js/lib/task-bukkit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@
/*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) {
task.cancel();
}
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) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/js/modules/drone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 87b667c

Please sign in to comment.