Replace NashornScriptEngine with implicit GraalJSScriptEngine
GraalJSScriptEngine implements Invocable, which is why casting to it works. However, this is just a quick and ugly fix to make it compile. A better solution would be to cast it once, immediately after `eval`, and from then on only handle it as Invocable. Scripts still need to be fixed. They are still using Rhino and Nashorn-specific ways of importing packages. Usages of "importPackage" and "Packages" need to be replaced with the Graal specific "Java.type".
This commit is contained in:
@@ -21,19 +21,19 @@
|
||||
*/
|
||||
package scripting.event;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import net.server.channel.Channel;
|
||||
import scripting.AbstractScriptManager;
|
||||
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
||||
|
||||
import net.server.channel.Channel;
|
||||
import scripting.AbstractScriptManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Matze
|
||||
@@ -42,11 +42,11 @@ public class EventScriptManager extends AbstractScriptManager {
|
||||
|
||||
private class EventEntry {
|
||||
|
||||
public EventEntry(NashornScriptEngine iv, EventManager em) {
|
||||
public EventEntry(ScriptEngine iv, EventManager em) {
|
||||
this.iv = iv;
|
||||
this.em = em;
|
||||
}
|
||||
public NashornScriptEngine iv;
|
||||
public ScriptEngine iv;
|
||||
public EventManager em;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class EventScriptManager extends AbstractScriptManager {
|
||||
super();
|
||||
for (String script : scripts) {
|
||||
if (!script.equals("")) {
|
||||
NashornScriptEngine iv = getScriptEngine("event/" + script + ".js");
|
||||
ScriptEngine iv = getScriptEngine("event/" + script + ".js");
|
||||
events.put(script, new EventEntry(iv, new EventManager(cserv, iv, script)));
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class EventScriptManager extends AbstractScriptManager {
|
||||
for (EventEntry entry : events.values()) {
|
||||
try {
|
||||
entry.iv.put("em", entry.em);
|
||||
entry.iv.invokeFunction("init", (Object) null);
|
||||
((Invocable) entry.iv).invokeFunction("init", (Object) null);
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(EventScriptManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||
System.out.println("Error on script: " + entry.em.getName());
|
||||
@@ -102,7 +102,7 @@ public class EventScriptManager extends AbstractScriptManager {
|
||||
Channel cserv = eventEntries.iterator().next().getValue().em.getChannelServer();
|
||||
for (Entry<String, EventEntry> entry : eventEntries) {
|
||||
String script = entry.getKey();
|
||||
NashornScriptEngine iv = getScriptEngine("event/" + script + ".js");
|
||||
ScriptEngine iv = getScriptEngine("event/" + script + ".js");
|
||||
events.put(script, new EventEntry(iv, new EventManager(cserv, iv, script)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user