protected Invocable getInvocable(String path, MapleClient c, boolean npc) throws ScriptException { InputStream in = null; try { path = "scripts/" + path; 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); } in = new FileInputStream(scriptFile); BufferedReader bf = new BufferedReader(new InputStreamReader(in, EncodingDetect.getJavaEncode(scriptFile))); String lines = "load('nashorn:mozilla_compat.js');" + bf.lines().collect(Collectors.joining(System.lineSeparator())); engine.eval(lines); } else if (c != null && npc) { //c.getPlayer().dropMessage(-1, "You already are talking to this NPC. Use @ea if this is not intended."); } } catch (FileNotFoundException | ScriptException e) { System.err.println("Error executing script. Path: " + path + "\r\nException " + e); FileoutputUtil.log(FileoutputUtil.ScriptEx_Log, "Error executing script. Path: " + path + "\r\nException " + e); return null; } catch (UnsupportedEncodingException ex) { System.err.println("Read Script Error - " + ex); return null; }finally { try { if (in != null) { in.close(); } } catch (IOException ignore) { } }
return (Invocable) engine;
}
|