This is some of the code I'm running for a MapleStory server. Whenever a script for an event like talking to an NPC is supposed to occur, this script will be run to create a scripting path for whatever script is being called up (NPC, portal, event etc.).
I am also using jdk1.7.0_80
lang-java
package scripting;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import client.MapleClient;
import tools.FileoutputUtil;
public abstract class AbstractScriptManager {
private static final ScriptEngineManager sem = new ScriptEngineManager(null);
protected Invocable getInvocable(String path, MapleClient c) {
return getInvocable(path, c, false);
}
protected Invocable getInvocable(String path, MapleClient c, boolean npc) {
FileReader fr = null;
try {
path = "scripts/" + path;
ScriptEngine engine = null;
if (c != null) {
engine = c.getScriptEngine(path);
}
if (engine == null) {
File scriptFile = new File(path);
if (!scriptFile.exists()) {
return null;
}
engine = sem.getEngineByName("JavaScript");
if (c != null) {
c.setScriptEngine(path, engine);
}
fr = new FileReader(scriptFile);
engine.eval(fr);
} else if (c != null && npc) {
c.getPlayer().dropMessage(-1, "You already are talking to this NPC. Use @ea if this is
not intended.");
}
return (Invocable) engine;
} catch (Exception e) {
System.err.println("Error executing script. Path: " + path + "\nException " + e);
FileoutputUtil.log(FileoutputUtil.ScriptEx_Log, "Error executing script. Path: " + path +
"\nException " + e);
return null;
} finally {
try {
if (fr != null) {
fr.close();
}
} catch (IOException ignore) {
}
}
}
}
This is the bat error I receive:
Error executing script. Path: scripts/event/someEvent.js Exception java.lang.NullPointerException: Cannot invoke "javax.script.ScriptEngine.eval(java.io.Reader)" because "engine" is null
These errors are thrown whenever I try to interact with something that utilizes this method (i.e. clicking NPC or on server start-up when some scripts are run).