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:
@@ -24,7 +24,6 @@ package client;
|
|||||||
import client.inventory.MapleInventoryType;
|
import client.inventory.MapleInventoryType;
|
||||||
import config.YamlConfig;
|
import config.YamlConfig;
|
||||||
import constants.game.GameConstants;
|
import constants.game.GameConstants;
|
||||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
|
||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
import net.server.audit.locks.MonitoredLockType;
|
import net.server.audit.locks.MonitoredLockType;
|
||||||
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
||||||
@@ -50,6 +49,7 @@ import server.maps.MapleMap;
|
|||||||
import server.maps.MapleMiniDungeonInfo;
|
import server.maps.MapleMiniDungeonInfo;
|
||||||
import tools.*;
|
import tools.*;
|
||||||
|
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
@@ -85,7 +85,7 @@ public class MapleClient {
|
|||||||
private long lastPong;
|
private long lastPong;
|
||||||
private int gmlevel;
|
private int gmlevel;
|
||||||
private Set<String> macs = new HashSet<>();
|
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 characterSlots = 3;
|
||||||
private byte loginattempt = 0;
|
private byte loginattempt = 0;
|
||||||
private String pin = "";
|
private String pin = "";
|
||||||
@@ -1041,11 +1041,11 @@ public class MapleClient {
|
|||||||
gmlevel = level;
|
gmlevel = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScriptEngine(String name, NashornScriptEngine e) {
|
public void setScriptEngine(String name, ScriptEngine e) {
|
||||||
engines.put(name, e);
|
engines.put(name, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NashornScriptEngine getScriptEngine(String name) {
|
public ScriptEngine getScriptEngine(String name) {
|
||||||
return engines.get(name);
|
return engines.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,32 +5,6 @@ public class ServerConstants {
|
|||||||
//Server Version
|
//Server Version
|
||||||
public static short VERSION = 83;
|
public static short VERSION = 83;
|
||||||
|
|
||||||
//Java Configuration
|
|
||||||
public static final boolean JAVA_8 = getJavaVersion() >= 8; //Max amount of times a party leader is allowed to persist on the Party Search before entry expiration (thus needing to manually restart the Party Search to be able to search for members).
|
|
||||||
|
|
||||||
//Debug Variables
|
//Debug Variables
|
||||||
public static int[] DEBUG_VALUES = new int[10]; // Field designed for packet testing purposes
|
public static int[] DEBUG_VALUES = new int[10]; // Field designed for packet testing purposes
|
||||||
|
|
||||||
// https://github.com/openstreetmap/josm/blob/a3a6e8a6b657cf4c5b4c64ea14d6e87be6280d65/src/org/openstreetmap/josm/tools/Utils.java#L1566-L1585
|
|
||||||
// Added by kolakcc (Familiar)
|
|
||||||
/**
|
|
||||||
* Returns the Java version as an int value.
|
|
||||||
* @return the Java version as an int value (8, 9, etc.)
|
|
||||||
* @since 12130
|
|
||||||
*/
|
|
||||||
public static int getJavaVersion() {
|
|
||||||
String version = System.getProperty("java.version");
|
|
||||||
if (version.startsWith("1.")) {
|
|
||||||
version = version.substring(2);
|
|
||||||
}
|
|
||||||
// Allow these formats:
|
|
||||||
// 1.8.0_72-ea
|
|
||||||
// 9-ea
|
|
||||||
// 9
|
|
||||||
// 9.0.1
|
|
||||||
int dotPos = version.indexOf('.');
|
|
||||||
int dashPos = version.indexOf('-');
|
|
||||||
return Integer.parseInt(version.substring(0,
|
|
||||||
dotPos > -1 ? dotPos : dashPos > -1 ? dashPos : 1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import client.inventory.manipulator.MapleInventoryManipulator;
|
|||||||
import config.YamlConfig;
|
import config.YamlConfig;
|
||||||
import constants.game.GameConstants;
|
import constants.game.GameConstants;
|
||||||
import constants.inventory.ItemConstants;
|
import constants.inventory.ItemConstants;
|
||||||
import constants.net.ServerConstants;
|
|
||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
import net.server.guild.MapleGuild;
|
import net.server.guild.MapleGuild;
|
||||||
import net.server.world.MapleParty;
|
import net.server.world.MapleParty;
|
||||||
@@ -218,17 +217,11 @@ public class AbstractPlayerInteraction {
|
|||||||
return canHoldAllAfterRemoving(Collections.singletonList(itemid), Collections.singletonList(quantity), Collections.singletonList(removeItemid), Collections.singletonList(removeQuantity));
|
return canHoldAllAfterRemoving(Collections.singletonList(itemid), Collections.singletonList(quantity), Collections.singletonList(removeItemid), Collections.singletonList(removeQuantity));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> convertToIntegerArray(List<Object> list) {
|
private List<Integer> convertToIntegerList(List<Object> objects) {
|
||||||
List<Integer> intList = new ArrayList<>(); // JAVA 7 Rhino script engine. Thanks Bruno, felipepm10 for noticing a typecast issue here.
|
List<Integer> intList = new ArrayList<>();
|
||||||
|
|
||||||
if (ServerConstants.JAVA_8) {
|
for (Object object : objects) {
|
||||||
for (Object d: list) {
|
intList.add((Integer) object);
|
||||||
intList.add((Integer) d);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (Object d: list) {
|
|
||||||
intList.add(((Double) d).intValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return intList;
|
return intList;
|
||||||
@@ -237,25 +230,16 @@ public class AbstractPlayerInteraction {
|
|||||||
public boolean canHoldAll(List<Object> itemids) {
|
public boolean canHoldAll(List<Object> itemids) {
|
||||||
List<Object> quantity = new LinkedList<>();
|
List<Object> quantity = new LinkedList<>();
|
||||||
|
|
||||||
if (ServerConstants.JAVA_8) {
|
final int intOne = 1;
|
||||||
Integer intOne = 1;
|
|
||||||
|
|
||||||
for (int i = 0; i < itemids.size(); i++) {
|
for (int i = 0; i < itemids.size(); i++) {
|
||||||
quantity.add(intOne);
|
quantity.add(intOne);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Double doubleOne = 1.0;
|
|
||||||
|
|
||||||
for (int i = 0; i < itemids.size(); i++) {
|
|
||||||
quantity.add(doubleOne);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return canHoldAll(itemids, quantity);
|
return canHoldAll(itemids, quantity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canHoldAll(List<Object> itemids, List<Object> quantity) {
|
public boolean canHoldAll(List<Object> itemids, List<Object> quantity) {
|
||||||
return canHoldAll(convertToIntegerArray(itemids), convertToIntegerArray(quantity), true);
|
return canHoldAll(convertToIntegerList(itemids), convertToIntegerList(quantity), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canHoldAll(List<Integer> itemids, List<Integer> quantity, boolean isInteger) {
|
private boolean canHoldAll(List<Integer> itemids, List<Integer> quantity, boolean isInteger) {
|
||||||
|
|||||||
@@ -22,39 +22,35 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package scripting;
|
package scripting;
|
||||||
|
|
||||||
import client.MapleClient;
|
import client.MapleClient;
|
||||||
|
import tools.FilePrinter;
|
||||||
|
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.ScriptEngineFactory;
|
||||||
|
import javax.script.ScriptEngineManager;
|
||||||
|
import javax.script.ScriptException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.script.*;
|
|
||||||
|
|
||||||
import constants.net.ServerConstants;
|
|
||||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
|
||||||
import tools.FilePrinter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Matze
|
* @author Matze
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractScriptManager {
|
public abstract class AbstractScriptManager {
|
||||||
private ScriptEngineFactory sef;
|
private final ScriptEngineFactory sef;
|
||||||
|
|
||||||
protected AbstractScriptManager() {
|
protected AbstractScriptManager() {
|
||||||
sef = new ScriptEngineManager().getEngineByName("javascript").getFactory();
|
sef = new ScriptEngineManager().getEngineByName("graal.js").getFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NashornScriptEngine getScriptEngine(String path) {
|
protected ScriptEngine getScriptEngine(String path) {
|
||||||
path = "scripts/" + path;
|
path = "scripts/" + path;
|
||||||
File scriptFile = new File(path);
|
File scriptFile = new File(path);
|
||||||
if (!scriptFile.exists()) {
|
if (!scriptFile.exists()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
NashornScriptEngine engine = (NashornScriptEngine) sef.getScriptEngine();
|
ScriptEngine engine = sef.getScriptEngine();
|
||||||
try (FileReader fr = new FileReader(scriptFile)) {
|
try (FileReader fr = new FileReader(scriptFile)) {
|
||||||
if (ServerConstants.JAVA_8){
|
|
||||||
engine.eval("load('nashorn:mozilla_compat.js');" + System.lineSeparator());
|
|
||||||
}
|
|
||||||
engine.eval(fr);
|
engine.eval(fr);
|
||||||
} catch (final ScriptException | IOException t) {
|
} catch (final ScriptException | IOException t) {
|
||||||
FilePrinter.printError(FilePrinter.INVOCABLE + path.substring(12), t, path);
|
FilePrinter.printError(FilePrinter.INVOCABLE + path.substring(12), t, path);
|
||||||
@@ -64,8 +60,8 @@ public abstract class AbstractScriptManager {
|
|||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NashornScriptEngine getScriptEngine(String path, MapleClient c) {
|
protected ScriptEngine getScriptEngine(String path, MapleClient c) {
|
||||||
NashornScriptEngine engine = c.getScriptEngine("scripts/" + path);
|
ScriptEngine engine = c.getScriptEngine("scripts/" + path);
|
||||||
if (engine == null) {
|
if (engine == null) {
|
||||||
engine = getScriptEngine(path);
|
engine = getScriptEngine(path);
|
||||||
c.setScriptEngine(path, engine);
|
c.setScriptEngine(path, engine);
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import client.Skill;
|
|||||||
import client.SkillFactory;
|
import client.SkillFactory;
|
||||||
import config.YamlConfig;
|
import config.YamlConfig;
|
||||||
import constants.inventory.ItemConstants;
|
import constants.inventory.ItemConstants;
|
||||||
import constants.net.ServerConstants;
|
|
||||||
import net.server.audit.LockCollector;
|
import net.server.audit.LockCollector;
|
||||||
import net.server.audit.locks.*;
|
import net.server.audit.locks.*;
|
||||||
import net.server.audit.locks.factory.MonitoredReadLockFactory;
|
import net.server.audit.locks.factory.MonitoredReadLockFactory;
|
||||||
@@ -52,6 +51,7 @@ import server.maps.MapleReactor;
|
|||||||
import tools.MaplePacketCreator;
|
import tools.MaplePacketCreator;
|
||||||
import tools.Pair;
|
import tools.Pair;
|
||||||
|
|
||||||
|
import javax.script.Invocable;
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -217,7 +217,7 @@ public class EventInstanceManager {
|
|||||||
|
|
||||||
public Object invokeScriptFunction(String name, Object... args) throws ScriptException, NoSuchMethodException {
|
public Object invokeScriptFunction(String name, Object... args) throws ScriptException, NoSuchMethodException {
|
||||||
if (!disposed) {
|
if (!disposed) {
|
||||||
return em.getIv().invokeFunction(name, args);
|
return ((Invocable) em.getIv()).invokeFunction(name, args);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -558,13 +558,7 @@ public class EventInstanceManager {
|
|||||||
|
|
||||||
public void monsterKilled(MapleCharacter chr, final MapleMonster mob) {
|
public void monsterKilled(MapleCharacter chr, final MapleMonster mob) {
|
||||||
try {
|
try {
|
||||||
int inc;
|
final int inc = (int) invokeScriptFunction("monsterValue", EventInstanceManager.this, mob.getId());
|
||||||
|
|
||||||
if (ServerConstants.JAVA_8) {
|
|
||||||
inc = (int)invokeScriptFunction("monsterValue", EventInstanceManager.this, mob.getId());
|
|
||||||
} else {
|
|
||||||
inc = ((Double) invokeScriptFunction("monsterValue", EventInstanceManager.this, mob.getId())).intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inc != 0) {
|
if (inc != 0) {
|
||||||
Integer kc = killCount.get(chr);
|
Integer kc = killCount.get(chr);
|
||||||
@@ -574,7 +568,7 @@ public class EventInstanceManager {
|
|||||||
kc += inc;
|
kc += inc;
|
||||||
}
|
}
|
||||||
killCount.put(chr, kc);
|
killCount.put(chr, kc);
|
||||||
if (expedition != null){
|
if (expedition != null) {
|
||||||
expedition.monsterKilled(chr, mob);
|
expedition.monsterKilled(chr, mob);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -887,17 +881,11 @@ public class EventInstanceManager {
|
|||||||
return(MapleLifeFactory.getMonster(mid));
|
return(MapleLifeFactory.getMonster(mid));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> convertToIntegerArray(List<Object> list) {
|
private List<Integer> convertToIntegerList(List<Object> objects) {
|
||||||
List<Integer> intList = new ArrayList<>();
|
List<Integer> intList = new ArrayList<>();
|
||||||
|
|
||||||
if (ServerConstants.JAVA_8) {
|
for (Object object : objects) {
|
||||||
for (Object d: list) {
|
intList.add((Integer) object);
|
||||||
intList.add((Integer) d);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (Object d: list) {
|
|
||||||
intList.add(((Double) d).intValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return intList;
|
return intList;
|
||||||
@@ -905,12 +893,12 @@ public class EventInstanceManager {
|
|||||||
|
|
||||||
public void setEventClearStageExp(List<Object> gain) {
|
public void setEventClearStageExp(List<Object> gain) {
|
||||||
onMapClearExp.clear();
|
onMapClearExp.clear();
|
||||||
onMapClearExp.addAll(convertToIntegerArray(gain));
|
onMapClearExp.addAll(convertToIntegerList(gain));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEventClearStageMeso(List<Object> gain) {
|
public void setEventClearStageMeso(List<Object> gain) {
|
||||||
onMapClearMeso.clear();
|
onMapClearMeso.clear();
|
||||||
onMapClearMeso.addAll(convertToIntegerArray(gain));
|
onMapClearMeso.addAll(convertToIntegerList(gain));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getClearStageExp(int stage) { //stage counts from ONE.
|
public Integer getClearStageExp(int stage) { //stage counts from ONE.
|
||||||
@@ -940,7 +928,7 @@ public class EventInstanceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final void setExclusiveItems(List<Object> items) {
|
public final void setExclusiveItems(List<Object> items) {
|
||||||
List<Integer> exclusive = convertToIntegerArray(items);
|
List<Integer> exclusive = convertToIntegerList(items);
|
||||||
|
|
||||||
wL.lock();
|
wL.lock();
|
||||||
try {
|
try {
|
||||||
@@ -968,8 +956,8 @@ public class EventInstanceManager {
|
|||||||
if(eventLevel <= 0 || eventLevel > YamlConfig.config.server.MAX_EVENT_LEVELS) return;
|
if(eventLevel <= 0 || eventLevel > YamlConfig.config.server.MAX_EVENT_LEVELS) return;
|
||||||
eventLevel--; //event level starts from 1
|
eventLevel--; //event level starts from 1
|
||||||
|
|
||||||
List<Integer> rewardIds = convertToIntegerArray(rwds);
|
List<Integer> rewardIds = convertToIntegerList(rwds);
|
||||||
List<Integer> rewardQtys = convertToIntegerArray(qtys);
|
List<Integer> rewardQtys = convertToIntegerList(qtys);
|
||||||
|
|
||||||
//rewardsSet and rewardsQty hold temporary values
|
//rewardsSet and rewardsQty hold temporary values
|
||||||
wL.lock();
|
wL.lock();
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ package scripting.event;
|
|||||||
import client.MapleCharacter;
|
import client.MapleCharacter;
|
||||||
import config.YamlConfig;
|
import config.YamlConfig;
|
||||||
import constants.game.GameConstants;
|
import constants.game.GameConstants;
|
||||||
import constants.net.ServerConstants;
|
|
||||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
|
||||||
import jdk.nashorn.api.scripting.ScriptObjectMirror;
|
|
||||||
import jdk.nashorn.api.scripting.ScriptUtils;
|
|
||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
import net.server.audit.LockCollector;
|
import net.server.audit.LockCollector;
|
||||||
import net.server.audit.locks.MonitoredLockType;
|
import net.server.audit.locks.MonitoredLockType;
|
||||||
@@ -48,6 +44,8 @@ import server.maps.MapleMap;
|
|||||||
import server.quest.MapleQuest;
|
import server.quest.MapleQuest;
|
||||||
import tools.exceptions.EventInstanceInProgressException;
|
import tools.exceptions.EventInstanceInProgressException;
|
||||||
|
|
||||||
|
import javax.script.Invocable;
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
@@ -62,7 +60,7 @@ import java.util.logging.Logger;
|
|||||||
* @author Ronan
|
* @author Ronan
|
||||||
*/
|
*/
|
||||||
public class EventManager {
|
public class EventManager {
|
||||||
private NashornScriptEngine iv;
|
private ScriptEngine iv;
|
||||||
private Channel cserv;
|
private Channel cserv;
|
||||||
private World wserv;
|
private World wserv;
|
||||||
private Server server;
|
private Server server;
|
||||||
@@ -85,7 +83,7 @@ public class EventManager {
|
|||||||
|
|
||||||
private static final int maxLobbys = 8; // an event manager holds up to this amount of concurrent lobbys
|
private static final int maxLobbys = 8; // an event manager holds up to this amount of concurrent lobbys
|
||||||
|
|
||||||
public EventManager(Channel cserv, NashornScriptEngine iv, String name) {
|
public EventManager(Channel cserv, ScriptEngine iv, String name) {
|
||||||
this.server = Server.getInstance();
|
this.server = Server.getInstance();
|
||||||
this.iv = iv;
|
this.iv = iv;
|
||||||
this.cserv = cserv;
|
this.cserv = cserv;
|
||||||
@@ -104,7 +102,7 @@ public class EventManager {
|
|||||||
ess.dispose();
|
ess.dispose();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction("cancelSchedule", (Object) null);
|
((Invocable) iv).invokeFunction("cancelSchedule", (Object) null);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -152,17 +150,11 @@ public class EventManager {
|
|||||||
startLock = startLock.dispose();
|
startLock = startLock.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> convertToIntegerArray(List<Object> list) {
|
private List<Integer> convertToIntegerList(List<Object> objects) {
|
||||||
List<Integer> intList = new ArrayList<>();
|
List<Integer> intList = new ArrayList<>();
|
||||||
|
|
||||||
if (ServerConstants.JAVA_8) {
|
for (Object object : objects) {
|
||||||
for (Object d: list) {
|
intList.add((Integer) object);
|
||||||
intList.add((Integer) d);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (Object d: list) {
|
|
||||||
intList.add(((Double) d).intValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return intList;
|
return intList;
|
||||||
@@ -174,18 +166,8 @@ public class EventManager {
|
|||||||
|
|
||||||
private List<Integer> getLobbyRange() {
|
private List<Integer> getLobbyRange() {
|
||||||
try {
|
try {
|
||||||
if (!ServerConstants.JAVA_8) {
|
List<Object> objects = (List<Object>) ((Invocable) iv).invokeFunction("setLobbyRange", (Object) null);
|
||||||
return convertToIntegerArray((List<Object>)iv.invokeFunction("setLobbyRange", (Object) null));
|
return convertToIntegerList(objects);
|
||||||
} else { // java 8 support here thanks to MedicOP
|
|
||||||
ScriptObjectMirror object = (ScriptObjectMirror) iv.invokeFunction("setLobbyRange", (Object) null);
|
|
||||||
int[] to = object.to(int[].class);
|
|
||||||
List<Integer> list = new ArrayList<>();
|
|
||||||
for (int i : to) {
|
|
||||||
list.add(i);
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
|
|
||||||
}
|
|
||||||
} catch (ScriptException | NoSuchMethodException ex) { // they didn't define a lobby range
|
} catch (ScriptException | NoSuchMethodException ex) { // they didn't define a lobby range
|
||||||
List<Integer> defaultRange = new ArrayList<>();
|
List<Integer> defaultRange = new ArrayList<>();
|
||||||
defaultRange.add(0);
|
defaultRange.add(0);
|
||||||
@@ -202,7 +184,7 @@ public class EventManager {
|
|||||||
public EventScheduledFuture schedule(final String methodName, final EventInstanceManager eim, long delay) {
|
public EventScheduledFuture schedule(final String methodName, final EventInstanceManager eim, long delay) {
|
||||||
Runnable r = () -> {
|
Runnable r = () -> {
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction(methodName, eim);
|
((Invocable) iv).invokeFunction(methodName, eim);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
@@ -217,7 +199,7 @@ public class EventManager {
|
|||||||
public EventScheduledFuture scheduleAtTimestamp(final String methodName, long timestamp) {
|
public EventScheduledFuture scheduleAtTimestamp(final String methodName, long timestamp) {
|
||||||
Runnable r = () -> {
|
Runnable r = () -> {
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction(methodName, (Object) null);
|
((Invocable) iv).invokeFunction(methodName, (Object) null);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
@@ -235,7 +217,7 @@ public class EventManager {
|
|||||||
return cserv;
|
return cserv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NashornScriptEngine getIv() {
|
public ScriptEngine getIv() {
|
||||||
return iv;
|
return iv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,7 +368,7 @@ public class EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private EventInstanceManager createInstance(String name, Object... args) throws ScriptException, NoSuchMethodException {
|
private EventInstanceManager createInstance(String name, Object... args) throws ScriptException, NoSuchMethodException {
|
||||||
return (EventInstanceManager) iv.invokeFunction(name, args);
|
return (EventInstanceManager) ((Invocable) iv).invokeFunction(name, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerEventInstance(String eventName, int lobbyId) {
|
private void registerEventInstance(String eventName, int lobbyId) {
|
||||||
@@ -708,7 +690,7 @@ public class EventManager {
|
|||||||
registerEventInstance(eim.getName(), lobbyId);
|
registerEventInstance(eim.getName(), lobbyId);
|
||||||
eim.setLeader(leader);
|
eim.setLeader(leader);
|
||||||
|
|
||||||
iv.invokeFunction("setup", eim);
|
((Invocable) iv).invokeFunction("setup", eim);
|
||||||
eim.setProperty("leader", ldr);
|
eim.setProperty("leader", ldr);
|
||||||
|
|
||||||
eim.startEvent();
|
eim.startEvent();
|
||||||
@@ -735,17 +717,10 @@ public class EventManager {
|
|||||||
return(new ArrayList<>());
|
return(new ArrayList<>());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Object p = iv.invokeFunction("getEligibleParty", party.getPartyMembersOnline());
|
Object p = ((Invocable) iv).invokeFunction("getEligibleParty", party.getPartyMembersOnline());
|
||||||
|
|
||||||
if(p != null) {
|
if(p != null) {
|
||||||
List<MaplePartyCharacter> lmpc;
|
final List<MaplePartyCharacter> lmpc = new ArrayList<>((List<MaplePartyCharacter>) p);
|
||||||
|
|
||||||
if(ServerConstants.JAVA_8) {
|
|
||||||
lmpc = new ArrayList<>(((Map<String, MaplePartyCharacter>)(ScriptUtils.convert(p, Map.class))).values());
|
|
||||||
} else {
|
|
||||||
lmpc = new ArrayList<>((List<MaplePartyCharacter>) p);
|
|
||||||
}
|
|
||||||
|
|
||||||
party.setEligibleMembers(lmpc);
|
party.setEligibleMembers(lmpc);
|
||||||
return lmpc;
|
return lmpc;
|
||||||
}
|
}
|
||||||
@@ -758,7 +733,7 @@ public class EventManager {
|
|||||||
|
|
||||||
public void clearPQ(EventInstanceManager eim) {
|
public void clearPQ(EventInstanceManager eim) {
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction("clearPQ", eim);
|
((Invocable) iv).invokeFunction("clearPQ", eim);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
@@ -766,7 +741,7 @@ public class EventManager {
|
|||||||
|
|
||||||
public void clearPQ(EventInstanceManager eim, MapleMap toMap) {
|
public void clearPQ(EventInstanceManager eim, MapleMap toMap) {
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction("clearPQ", eim, toMap);
|
((Invocable) iv).invokeFunction("clearPQ", eim, toMap);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,19 +21,19 @@
|
|||||||
*/
|
*/
|
||||||
package scripting.event;
|
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.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
|
||||||
|
|
||||||
import net.server.channel.Channel;
|
|
||||||
import scripting.AbstractScriptManager;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Matze
|
* @author Matze
|
||||||
@@ -42,11 +42,11 @@ public class EventScriptManager extends AbstractScriptManager {
|
|||||||
|
|
||||||
private class EventEntry {
|
private class EventEntry {
|
||||||
|
|
||||||
public EventEntry(NashornScriptEngine iv, EventManager em) {
|
public EventEntry(ScriptEngine iv, EventManager em) {
|
||||||
this.iv = iv;
|
this.iv = iv;
|
||||||
this.em = em;
|
this.em = em;
|
||||||
}
|
}
|
||||||
public NashornScriptEngine iv;
|
public ScriptEngine iv;
|
||||||
public EventManager em;
|
public EventManager em;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ public class EventScriptManager extends AbstractScriptManager {
|
|||||||
super();
|
super();
|
||||||
for (String script : scripts) {
|
for (String script : scripts) {
|
||||||
if (!script.equals("")) {
|
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)));
|
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()) {
|
for (EventEntry entry : events.values()) {
|
||||||
try {
|
try {
|
||||||
entry.iv.put("em", entry.em);
|
entry.iv.put("em", entry.em);
|
||||||
entry.iv.invokeFunction("init", (Object) null);
|
((Invocable) entry.iv).invokeFunction("init", (Object) null);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.getLogger(EventScriptManager.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(EventScriptManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
System.out.println("Error on script: " + entry.em.getName());
|
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();
|
Channel cserv = eventEntries.iterator().next().getValue().em.getChannelServer();
|
||||||
for (Entry<String, EventEntry> entry : eventEntries) {
|
for (Entry<String, EventEntry> entry : eventEntries) {
|
||||||
String script = entry.getKey();
|
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)));
|
events.put(script, new EventEntry(iv, new EventManager(cserv, iv, script)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,15 +23,16 @@ package scripting.map;
|
|||||||
|
|
||||||
import client.MapleCharacter;
|
import client.MapleCharacter;
|
||||||
import client.MapleClient;
|
import client.MapleClient;
|
||||||
import java.lang.reflect.UndeclaredThrowableException;
|
import scripting.AbstractScriptManager;
|
||||||
import java.util.HashMap;
|
import tools.FilePrinter;
|
||||||
import java.util.Map;
|
|
||||||
|
import javax.script.Invocable;
|
||||||
import javax.script.ScriptEngineFactory;
|
import javax.script.ScriptEngineFactory;
|
||||||
import javax.script.ScriptEngineManager;
|
import javax.script.ScriptEngineManager;
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
import java.lang.reflect.UndeclaredThrowableException;
|
||||||
import scripting.AbstractScriptManager;
|
import java.util.HashMap;
|
||||||
import tools.FilePrinter;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MapScriptManager extends AbstractScriptManager {
|
public class MapScriptManager extends AbstractScriptManager {
|
||||||
|
|
||||||
@@ -41,12 +42,12 @@ public class MapScriptManager extends AbstractScriptManager {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, NashornScriptEngine> scripts = new HashMap<>();
|
private Map<String, Invocable> scripts = new HashMap<>();
|
||||||
private ScriptEngineFactory sef;
|
private final ScriptEngineFactory sef;
|
||||||
|
|
||||||
private MapScriptManager() {
|
private MapScriptManager() {
|
||||||
ScriptEngineManager sem = new ScriptEngineManager();
|
ScriptEngineManager sem = new ScriptEngineManager();
|
||||||
sef = sem.getEngineByName("javascript").getFactory();
|
sef = sem.getEngineByName("graal.js").getFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadScripts() {
|
public void reloadScripts() {
|
||||||
@@ -64,7 +65,7 @@ public class MapScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NashornScriptEngine iv = scripts.get(mapScriptPath);
|
Invocable iv = scripts.get(mapScriptPath);
|
||||||
if (iv != null) {
|
if (iv != null) {
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction("start", new MapScriptMethods(c));
|
iv.invokeFunction("start", new MapScriptMethods(c));
|
||||||
@@ -75,13 +76,13 @@ public class MapScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
iv = getScriptEngine("map/" + mapScriptPath + ".js");
|
iv = (Invocable) getScriptEngine("map/" + mapScriptPath + ".js");
|
||||||
if (iv == null) {
|
if (iv == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
scripts.put(mapScriptPath, iv);
|
scripts.put(mapScriptPath, iv);
|
||||||
iv.invokeFunction("start", new MapScriptMethods(c));
|
((Invocable) iv).invokeFunction("start", new MapScriptMethods(c));
|
||||||
return true;
|
return true;
|
||||||
} catch (final UndeclaredThrowableException | ScriptException ute) {
|
} catch (final UndeclaredThrowableException | ScriptException ute) {
|
||||||
FilePrinter.printError(FilePrinter.MAP_SCRIPT + mapScriptPath + ".txt", ute);
|
FilePrinter.printError(FilePrinter.MAP_SCRIPT + mapScriptPath + ".txt", ute);
|
||||||
|
|||||||
@@ -23,22 +23,20 @@ package scripting.npc;
|
|||||||
|
|
||||||
import client.MapleCharacter;
|
import client.MapleCharacter;
|
||||||
import client.MapleClient;
|
import client.MapleClient;
|
||||||
|
|
||||||
import java.lang.reflect.UndeclaredThrowableException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.script.ScriptException;
|
|
||||||
|
|
||||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
|
||||||
import net.server.world.MaplePartyCharacter;
|
import net.server.world.MaplePartyCharacter;
|
||||||
|
|
||||||
import scripting.AbstractScriptManager;
|
import scripting.AbstractScriptManager;
|
||||||
import server.MapleItemInformationProvider.ScriptedItem;
|
import server.MapleItemInformationProvider.ScriptedItem;
|
||||||
import tools.FilePrinter;
|
import tools.FilePrinter;
|
||||||
import tools.MaplePacketCreator;
|
import tools.MaplePacketCreator;
|
||||||
|
|
||||||
|
import javax.script.Invocable;
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.ScriptException;
|
||||||
|
import java.lang.reflect.UndeclaredThrowableException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Matze
|
* @author Matze
|
||||||
@@ -52,10 +50,10 @@ public class NPCScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<MapleClient, NPCConversationManager> cms = new HashMap<>();
|
private Map<MapleClient, NPCConversationManager> cms = new HashMap<>();
|
||||||
private Map<MapleClient, NashornScriptEngine> scripts = new HashMap<>();
|
private Map<MapleClient, ScriptEngine> scripts = new HashMap<>();
|
||||||
|
|
||||||
public boolean isNpcScriptAvailable(MapleClient c, String fileName) {
|
public boolean isNpcScriptAvailable(MapleClient c, String fileName) {
|
||||||
NashornScriptEngine iv = null;
|
ScriptEngine iv = null;
|
||||||
if (fileName != null) {
|
if (fileName != null) {
|
||||||
iv = getScriptEngine("npc/" + fileName + ".js", c);
|
iv = getScriptEngine("npc/" + fileName + ".js", c);
|
||||||
}
|
}
|
||||||
@@ -91,7 +89,7 @@ public class NPCScriptManager extends AbstractScriptManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cms.put(c, cm);
|
cms.put(c, cm);
|
||||||
NashornScriptEngine iv = getScriptEngine("npc/" + filename + ".js", c);
|
ScriptEngine iv = getScriptEngine("npc/" + filename + ".js", c);
|
||||||
|
|
||||||
if (iv == null) {
|
if (iv == null) {
|
||||||
c.getPlayer().dropMessage(1, "NPC " + npc + " is uncoded.");
|
c.getPlayer().dropMessage(1, "NPC " + npc + " is uncoded.");
|
||||||
@@ -101,7 +99,7 @@ public class NPCScriptManager extends AbstractScriptManager {
|
|||||||
iv.put("cm", cm);
|
iv.put("cm", cm);
|
||||||
scripts.put(c, iv);
|
scripts.put(c, iv);
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction("start", chrs);
|
((Invocable) iv).invokeFunction("start", chrs);
|
||||||
} catch (final NoSuchMethodException nsme) {
|
} catch (final NoSuchMethodException nsme) {
|
||||||
nsme.printStackTrace();
|
nsme.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -123,7 +121,7 @@ public class NPCScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
if (c.canClickNPC()) {
|
if (c.canClickNPC()) {
|
||||||
cms.put(c, cm);
|
cms.put(c, cm);
|
||||||
NashornScriptEngine iv = null;
|
ScriptEngine iv = null;
|
||||||
if (!itemScript) {
|
if (!itemScript) {
|
||||||
if (fileName != null) {
|
if (fileName != null) {
|
||||||
iv = getScriptEngine("npc/" + fileName + ".js", c);
|
iv = getScriptEngine("npc/" + fileName + ".js", c);
|
||||||
@@ -145,10 +143,10 @@ public class NPCScriptManager extends AbstractScriptManager {
|
|||||||
scripts.put(c, iv);
|
scripts.put(c, iv);
|
||||||
c.setClickedNPC();
|
c.setClickedNPC();
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction("start");
|
((Invocable) iv).invokeFunction("start");
|
||||||
} catch (final NoSuchMethodException nsme) {
|
} catch (final NoSuchMethodException nsme) {
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction("start", chr);
|
((Invocable) iv).invokeFunction("start", chr);
|
||||||
} catch (final NoSuchMethodException nsma) {
|
} catch (final NoSuchMethodException nsma) {
|
||||||
nsma.printStackTrace();
|
nsma.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -171,11 +169,11 @@ public class NPCScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void action(MapleClient c, byte mode, byte type, int selection) {
|
public void action(MapleClient c, byte mode, byte type, int selection) {
|
||||||
NashornScriptEngine iv = scripts.get(c);
|
ScriptEngine iv = scripts.get(c);
|
||||||
if (iv != null) {
|
if (iv != null) {
|
||||||
try {
|
try {
|
||||||
c.setClickedNPC();
|
c.setClickedNPC();
|
||||||
iv.invokeFunction("action", mode, type, selection);
|
((Invocable) iv).invokeFunction("action", mode, type, selection);
|
||||||
} catch (ScriptException | NoSuchMethodException t) {
|
} catch (ScriptException | NoSuchMethodException t) {
|
||||||
if (getCM(c) != null) {
|
if (getCM(c) != null) {
|
||||||
FilePrinter.printError(FilePrinter.NPC + getCM(c).getNpc() + ".txt", t);
|
FilePrinter.printError(FilePrinter.NPC + getCM(c).getNpc() + ".txt", t);
|
||||||
|
|||||||
@@ -22,35 +22,37 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package scripting.portal;
|
package scripting.portal;
|
||||||
|
|
||||||
import client.MapleClient;
|
import client.MapleClient;
|
||||||
import java.lang.reflect.UndeclaredThrowableException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import javax.script.ScriptEngineFactory;
|
|
||||||
import javax.script.ScriptEngineManager;
|
|
||||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
|
||||||
import scripting.AbstractScriptManager;
|
import scripting.AbstractScriptManager;
|
||||||
import server.maps.MaplePortal;
|
import server.maps.MaplePortal;
|
||||||
import tools.FilePrinter;
|
import tools.FilePrinter;
|
||||||
|
|
||||||
|
import javax.script.Invocable;
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
|
import javax.script.ScriptEngineFactory;
|
||||||
|
import javax.script.ScriptEngineManager;
|
||||||
|
import java.lang.reflect.UndeclaredThrowableException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class PortalScriptManager extends AbstractScriptManager {
|
public class PortalScriptManager extends AbstractScriptManager {
|
||||||
|
|
||||||
private static PortalScriptManager instance = new PortalScriptManager();
|
private static final PortalScriptManager instance = new PortalScriptManager();
|
||||||
|
|
||||||
public static PortalScriptManager getInstance() {
|
public static PortalScriptManager getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, NashornScriptEngine> scripts = new HashMap<>();
|
private Map<String, ScriptEngine> scripts = new HashMap<>();
|
||||||
private ScriptEngineFactory sef;
|
private final ScriptEngineFactory sef;
|
||||||
|
|
||||||
private PortalScriptManager() {
|
private PortalScriptManager() {
|
||||||
ScriptEngineManager sem = new ScriptEngineManager();
|
ScriptEngineManager sem = new ScriptEngineManager();
|
||||||
sef = sem.getEngineByName("javascript").getFactory();
|
sef = sem.getEngineByName("graal.js").getFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
private NashornScriptEngine getPortalScript(String scriptName) {
|
private ScriptEngine getPortalScript(String scriptName) {
|
||||||
String scriptPath = "portal/" + scriptName + ".js";
|
String scriptPath = "portal/" + scriptName + ".js";
|
||||||
NashornScriptEngine iv = scripts.get(scriptPath);
|
ScriptEngine iv = scripts.get(scriptPath);
|
||||||
if (iv != null) {
|
if (iv != null) {
|
||||||
return iv;
|
return iv;
|
||||||
}
|
}
|
||||||
@@ -66,9 +68,9 @@ public class PortalScriptManager extends AbstractScriptManager {
|
|||||||
|
|
||||||
public boolean executePortalScript(MaplePortal portal, MapleClient c) {
|
public boolean executePortalScript(MaplePortal portal, MapleClient c) {
|
||||||
try {
|
try {
|
||||||
NashornScriptEngine iv = getPortalScript(portal.getScriptName());
|
ScriptEngine iv = getPortalScript(portal.getScriptName());
|
||||||
if (iv != null) {
|
if (iv != null) {
|
||||||
boolean couldWarp = (boolean) iv.invokeFunction("enter", new PortalPlayerInteraction(c, portal));
|
boolean couldWarp = (boolean) ((Invocable) iv).invokeFunction("enter", new PortalPlayerInteraction(c, portal));
|
||||||
return couldWarp;
|
return couldWarp;
|
||||||
}
|
}
|
||||||
} catch (UndeclaredThrowableException ute) {
|
} catch (UndeclaredThrowableException ute) {
|
||||||
|
|||||||
@@ -21,24 +21,24 @@
|
|||||||
*/
|
*/
|
||||||
package scripting.quest;
|
package scripting.quest;
|
||||||
|
|
||||||
import java.lang.reflect.UndeclaredThrowableException;
|
import client.MapleClient;
|
||||||
import java.util.HashMap;
|
import client.MapleQuestStatus;
|
||||||
import java.util.Map;
|
import constants.game.GameConstants;
|
||||||
|
|
||||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
|
||||||
import scripting.AbstractScriptManager;
|
import scripting.AbstractScriptManager;
|
||||||
import server.quest.MapleQuest;
|
import server.quest.MapleQuest;
|
||||||
import tools.FilePrinter;
|
import tools.FilePrinter;
|
||||||
import constants.game.GameConstants;
|
|
||||||
import client.MapleClient;
|
import javax.script.Invocable;
|
||||||
import client.MapleQuestStatus;
|
import javax.script.ScriptEngine;
|
||||||
|
import java.lang.reflect.UndeclaredThrowableException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author RMZero213
|
* @author RMZero213
|
||||||
*/
|
*/
|
||||||
public class QuestScriptManager extends AbstractScriptManager {
|
public class QuestScriptManager extends AbstractScriptManager {
|
||||||
|
|
||||||
private static QuestScriptManager instance = new QuestScriptManager();
|
private static QuestScriptManager instance = new QuestScriptManager();
|
||||||
|
|
||||||
public static QuestScriptManager getInstance() {
|
public static QuestScriptManager getInstance() {
|
||||||
@@ -46,10 +46,10 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<MapleClient, QuestActionManager> qms = new HashMap<>();
|
private Map<MapleClient, QuestActionManager> qms = new HashMap<>();
|
||||||
private Map<MapleClient, NashornScriptEngine> scripts = new HashMap<>();
|
private Map<MapleClient, ScriptEngine> scripts = new HashMap<>();
|
||||||
|
|
||||||
private NashornScriptEngine getQuestScriptEngine(MapleClient c, short questid) {
|
private ScriptEngine getQuestScriptEngine(MapleClient c, short questid) {
|
||||||
NashornScriptEngine iv = getScriptEngine("quest/" + questid + ".js", c);
|
ScriptEngine iv = getScriptEngine("quest/" + questid + ".js", c);
|
||||||
if (iv == null && GameConstants.isMedalQuest(questid)) {
|
if (iv == null && GameConstants.isMedalQuest(questid)) {
|
||||||
iv = getScriptEngine("quest/medalQuest.js", c); // start generic medal quest
|
iv = getScriptEngine("quest/medalQuest.js", c); // start generic medal quest
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
if (qms.containsKey(c)) {
|
if (qms.containsKey(c)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(c.canClickNPC()) {
|
if (c.canClickNPC()) {
|
||||||
qms.put(c, qm);
|
qms.put(c, qm);
|
||||||
|
|
||||||
if (!quest.hasScriptRequirement(false)) { // lack of scripted quest checks found thanks to Mali, Resinate
|
if (!quest.hasScriptRequirement(false)) { // lack of scripted quest checks found thanks to Mali, Resinate
|
||||||
@@ -72,7 +72,7 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NashornScriptEngine iv = getQuestScriptEngine(c, questid);
|
ScriptEngine iv = getQuestScriptEngine(c, questid);
|
||||||
if (iv == null) {
|
if (iv == null) {
|
||||||
FilePrinter.printError(FilePrinter.QUEST_UNCODED, "START Quest " + questid + " is uncoded.");
|
FilePrinter.printError(FilePrinter.QUEST_UNCODED, "START Quest " + questid + " is uncoded.");
|
||||||
qm.dispose();
|
qm.dispose();
|
||||||
@@ -82,7 +82,7 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
iv.put("qm", qm);
|
iv.put("qm", qm);
|
||||||
scripts.put(c, iv);
|
scripts.put(c, iv);
|
||||||
c.setClickedNPC();
|
c.setClickedNPC();
|
||||||
iv.invokeFunction("start", (byte) 1, (byte) 0, 0);
|
((Invocable) iv).invokeFunction("start", (byte) 1, (byte) 0, 0);
|
||||||
}
|
}
|
||||||
} catch (final UndeclaredThrowableException ute) {
|
} catch (final UndeclaredThrowableException ute) {
|
||||||
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
|
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
|
||||||
@@ -94,11 +94,11 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start(MapleClient c, byte mode, byte type, int selection) {
|
public void start(MapleClient c, byte mode, byte type, int selection) {
|
||||||
NashornScriptEngine iv = scripts.get(c);
|
ScriptEngine iv = scripts.get(c);
|
||||||
if (iv != null) {
|
if (iv != null) {
|
||||||
try {
|
try {
|
||||||
c.setClickedNPC();
|
c.setClickedNPC();
|
||||||
iv.invokeFunction("start", mode, type, selection);
|
((Invocable) iv).invokeFunction("start", mode, type, selection);
|
||||||
} catch (final UndeclaredThrowableException ute) {
|
} catch (final UndeclaredThrowableException ute) {
|
||||||
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", ute);
|
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", ute);
|
||||||
dispose(c);
|
dispose(c);
|
||||||
@@ -120,7 +120,7 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
if (qms.containsKey(c)) {
|
if (qms.containsKey(c)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(c.canClickNPC()){
|
if (c.canClickNPC()) {
|
||||||
qms.put(c, qm);
|
qms.put(c, qm);
|
||||||
|
|
||||||
if (!quest.hasScriptRequirement(true)) {
|
if (!quest.hasScriptRequirement(true)) {
|
||||||
@@ -128,7 +128,7 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NashornScriptEngine iv = getQuestScriptEngine(c, questid);
|
ScriptEngine iv = getQuestScriptEngine(c, questid);
|
||||||
if (iv == null) {
|
if (iv == null) {
|
||||||
FilePrinter.printError(FilePrinter.QUEST_UNCODED, "END Quest " + questid + " is uncoded.");
|
FilePrinter.printError(FilePrinter.QUEST_UNCODED, "END Quest " + questid + " is uncoded.");
|
||||||
qm.dispose();
|
qm.dispose();
|
||||||
@@ -138,7 +138,7 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
iv.put("qm", qm);
|
iv.put("qm", qm);
|
||||||
scripts.put(c, iv);
|
scripts.put(c, iv);
|
||||||
c.setClickedNPC();
|
c.setClickedNPC();
|
||||||
iv.invokeFunction("end", (byte) 1, (byte) 0, 0);
|
((Invocable) iv).invokeFunction("end", (byte) 1, (byte) 0, 0);
|
||||||
}
|
}
|
||||||
} catch (final UndeclaredThrowableException ute) {
|
} catch (final UndeclaredThrowableException ute) {
|
||||||
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
|
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
|
||||||
@@ -150,11 +150,11 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void end(MapleClient c, byte mode, byte type, int selection) {
|
public void end(MapleClient c, byte mode, byte type, int selection) {
|
||||||
NashornScriptEngine iv = scripts.get(c);
|
ScriptEngine iv = scripts.get(c);
|
||||||
if (iv != null) {
|
if (iv != null) {
|
||||||
try {
|
try {
|
||||||
c.setClickedNPC();
|
c.setClickedNPC();
|
||||||
iv.invokeFunction("end", mode, type, selection);
|
((Invocable) iv).invokeFunction("end", mode, type, selection);
|
||||||
} catch (final UndeclaredThrowableException ute) {
|
} catch (final UndeclaredThrowableException ute) {
|
||||||
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", ute);
|
FilePrinter.printError(FilePrinter.QUEST + getQM(c).getQuest() + ".txt", ute);
|
||||||
dispose(c);
|
dispose(c);
|
||||||
@@ -171,10 +171,10 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
if (qms.containsKey(c)) {
|
if (qms.containsKey(c)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(c.canClickNPC()) {
|
if (c.canClickNPC()) {
|
||||||
qms.put(c, qm);
|
qms.put(c, qm);
|
||||||
|
|
||||||
NashornScriptEngine iv = getQuestScriptEngine(c, questid);
|
ScriptEngine iv = getQuestScriptEngine(c, questid);
|
||||||
if (iv == null) {
|
if (iv == null) {
|
||||||
//FilePrinter.printError(FilePrinter.QUEST_UNCODED, "RAISE Quest " + questid + " is uncoded.");
|
//FilePrinter.printError(FilePrinter.QUEST_UNCODED, "RAISE Quest " + questid + " is uncoded.");
|
||||||
qm.dispose();
|
qm.dispose();
|
||||||
@@ -184,7 +184,7 @@ public class QuestScriptManager extends AbstractScriptManager {
|
|||||||
iv.put("qm", qm);
|
iv.put("qm", qm);
|
||||||
scripts.put(c, iv);
|
scripts.put(c, iv);
|
||||||
c.setClickedNPC();
|
c.setClickedNPC();
|
||||||
iv.invokeFunction("raiseOpen");
|
((Invocable) iv).invokeFunction("raiseOpen");
|
||||||
}
|
}
|
||||||
} catch (final UndeclaredThrowableException ute) {
|
} catch (final UndeclaredThrowableException ute) {
|
||||||
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
|
FilePrinter.printError(FilePrinter.QUEST + questid + ".txt", ute);
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import client.inventory.Item;
|
|||||||
import client.inventory.MapleInventoryType;
|
import client.inventory.MapleInventoryType;
|
||||||
import config.YamlConfig;
|
import config.YamlConfig;
|
||||||
import constants.inventory.ItemConstants;
|
import constants.inventory.ItemConstants;
|
||||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
|
||||||
import scripting.AbstractPlayerInteraction;
|
import scripting.AbstractPlayerInteraction;
|
||||||
import scripting.event.EventInstanceManager;
|
import scripting.event.EventInstanceManager;
|
||||||
import scripting.event.EventManager;
|
import scripting.event.EventManager;
|
||||||
@@ -44,6 +43,8 @@ import server.partyquest.MapleCarnivalFactory;
|
|||||||
import server.partyquest.MapleCarnivalFactory.MCSkill;
|
import server.partyquest.MapleCarnivalFactory.MCSkill;
|
||||||
import tools.MaplePacketCreator;
|
import tools.MaplePacketCreator;
|
||||||
|
|
||||||
|
import javax.script.Invocable;
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -59,10 +60,10 @@ import java.util.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
public class ReactorActionManager extends AbstractPlayerInteraction {
|
public class ReactorActionManager extends AbstractPlayerInteraction {
|
||||||
private MapleReactor reactor;
|
private MapleReactor reactor;
|
||||||
private NashornScriptEngine iv;
|
private ScriptEngine iv;
|
||||||
private ScheduledFuture<?> sprayTask = null;
|
private ScheduledFuture<?> sprayTask = null;
|
||||||
|
|
||||||
public ReactorActionManager(MapleClient c, MapleReactor reactor, NashornScriptEngine iv) {
|
public ReactorActionManager(MapleClient c, MapleReactor reactor, ScriptEngine iv) {
|
||||||
super(c);
|
super(c);
|
||||||
this.reactor = reactor;
|
this.reactor = reactor;
|
||||||
this.iv = iv;
|
this.iv = iv;
|
||||||
@@ -319,7 +320,7 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
public ScheduledFuture<?> schedule(final String methodName, final EventInstanceManager eim, long delay) {
|
public ScheduledFuture<?> schedule(final String methodName, final EventInstanceManager eim, long delay) {
|
||||||
return TimerManager.getInstance().schedule(() -> {
|
return TimerManager.getInstance().schedule(() -> {
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction(methodName, eim);
|
((Invocable) iv).invokeFunction(methodName, eim);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
@@ -329,7 +330,7 @@ public class ReactorActionManager extends AbstractPlayerInteraction {
|
|||||||
public ScheduledFuture<?> scheduleAtTimestamp(final String methodName, long timestamp) {
|
public ScheduledFuture<?> scheduleAtTimestamp(final String methodName, long timestamp) {
|
||||||
return TimerManager.getInstance().scheduleAtTimestamp(() -> {
|
return TimerManager.getInstance().scheduleAtTimestamp(() -> {
|
||||||
try {
|
try {
|
||||||
iv.invokeFunction(methodName, (Object) null);
|
((Invocable) iv).invokeFunction(methodName, (Object) null);
|
||||||
} catch (ScriptException | NoSuchMethodException ex) {
|
} catch (ScriptException | NoSuchMethodException ex) {
|
||||||
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(EventManager.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,13 +22,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package scripting.reactor;
|
package scripting.reactor;
|
||||||
|
|
||||||
import client.MapleClient;
|
import client.MapleClient;
|
||||||
import jdk.nashorn.api.scripting.NashornScriptEngine;
|
|
||||||
import scripting.AbstractScriptManager;
|
import scripting.AbstractScriptManager;
|
||||||
import server.maps.MapleReactor;
|
import server.maps.MapleReactor;
|
||||||
import server.maps.ReactorDropEntry;
|
import server.maps.ReactorDropEntry;
|
||||||
import tools.DatabaseConnection;
|
import tools.DatabaseConnection;
|
||||||
import tools.FilePrinter;
|
import tools.FilePrinter;
|
||||||
|
|
||||||
|
import javax.script.Invocable;
|
||||||
|
import javax.script.ScriptEngine;
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
@@ -53,12 +54,12 @@ public class ReactorScriptManager extends AbstractScriptManager {
|
|||||||
|
|
||||||
public void onHit(MapleClient c, MapleReactor reactor) {
|
public void onHit(MapleClient c, MapleReactor reactor) {
|
||||||
try {
|
try {
|
||||||
NashornScriptEngine iv = getScriptEngine("reactor/" + reactor.getId() + ".js", c);
|
ScriptEngine iv = getScriptEngine("reactor/" + reactor.getId() + ".js", c);
|
||||||
if (iv == null) return;
|
if (iv == null) return;
|
||||||
|
|
||||||
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
|
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
|
||||||
iv.put("rm", rm);
|
iv.put("rm", rm);
|
||||||
iv.invokeFunction("hit");
|
((Invocable) iv).invokeFunction("hit");
|
||||||
} catch (final NoSuchMethodException e) {} //do nothing, hit is OPTIONAL
|
} catch (final NoSuchMethodException e) {} //do nothing, hit is OPTIONAL
|
||||||
|
|
||||||
catch (final ScriptException | NullPointerException e) {
|
catch (final ScriptException | NullPointerException e) {
|
||||||
@@ -68,12 +69,12 @@ public class ReactorScriptManager extends AbstractScriptManager {
|
|||||||
|
|
||||||
public void act(MapleClient c, MapleReactor reactor) {
|
public void act(MapleClient c, MapleReactor reactor) {
|
||||||
try {
|
try {
|
||||||
NashornScriptEngine iv = getScriptEngine("reactor/" + reactor.getId() + ".js", c);
|
ScriptEngine iv = getScriptEngine("reactor/" + reactor.getId() + ".js", c);
|
||||||
if (iv == null) return;
|
if (iv == null) return;
|
||||||
|
|
||||||
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
|
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
|
||||||
iv.put("rm", rm);
|
iv.put("rm", rm);
|
||||||
iv.invokeFunction("act");
|
((Invocable) iv).invokeFunction("act");
|
||||||
} catch (final ScriptException | NoSuchMethodException | NullPointerException e) {
|
} catch (final ScriptException | NoSuchMethodException | NullPointerException e) {
|
||||||
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", e);
|
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", e);
|
||||||
}
|
}
|
||||||
@@ -114,15 +115,15 @@ public class ReactorScriptManager extends AbstractScriptManager {
|
|||||||
|
|
||||||
private void touching(MapleClient c, MapleReactor reactor, boolean touching) {
|
private void touching(MapleClient c, MapleReactor reactor, boolean touching) {
|
||||||
try {
|
try {
|
||||||
NashornScriptEngine iv = getScriptEngine("reactor/" + reactor.getId() + ".js", c);
|
ScriptEngine iv = getScriptEngine("reactor/" + reactor.getId() + ".js", c);
|
||||||
if (iv == null) return;
|
if (iv == null) return;
|
||||||
|
|
||||||
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
|
ReactorActionManager rm = new ReactorActionManager(c, reactor, iv);
|
||||||
iv.put("rm", rm);
|
iv.put("rm", rm);
|
||||||
if (touching) {
|
if (touching) {
|
||||||
iv.invokeFunction("touch");
|
((Invocable) iv).invokeFunction("touch");
|
||||||
} else {
|
} else {
|
||||||
iv.invokeFunction("untouch");
|
((Invocable) iv).invokeFunction("untouch");
|
||||||
}
|
}
|
||||||
} catch (final ScriptException | NoSuchMethodException | NullPointerException ute) {
|
} catch (final ScriptException | NoSuchMethodException | NullPointerException ute) {
|
||||||
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", ute);
|
FilePrinter.printError(FilePrinter.REACTOR + reactor.getId() + ".txt", ute);
|
||||||
|
|||||||
Reference in New Issue
Block a user