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:
P0nk
2021-04-17 15:08:45 +02:00
parent e42fb27459
commit a18a1cb8ce
13 changed files with 284 additions and 364 deletions

View File

@@ -24,7 +24,6 @@ package client;
import client.inventory.MapleInventoryType;
import config.YamlConfig;
import constants.game.GameConstants;
import jdk.nashorn.api.scripting.NashornScriptEngine;
import net.server.Server;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
@@ -50,6 +49,7 @@ import server.maps.MapleMap;
import server.maps.MapleMiniDungeonInfo;
import tools.*;
import javax.script.ScriptEngine;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
@@ -85,7 +85,7 @@ public class MapleClient {
private long lastPong;
private int gmlevel;
private Set<String> macs = new HashSet<>();
private Map<String, NashornScriptEngine> engines = new HashMap<>();
private Map<String, ScriptEngine> engines = new HashMap<>();
private byte characterSlots = 3;
private byte loginattempt = 0;
private String pin = "";
@@ -1041,11 +1041,11 @@ public class MapleClient {
gmlevel = level;
}
public void setScriptEngine(String name, NashornScriptEngine e) {
engines.put(name, e);
public void setScriptEngine(String name, ScriptEngine e) {
engines.put(name, e);
}
public NashornScriptEngine getScriptEngine(String name) {
public ScriptEngine getScriptEngine(String name) {
return engines.get(name);
}