- Back to Home »
- 楓之谷教學 »
- 【楓之谷教學】解決 JAVA8 腳本讀取問題
關於此問題,我希望在學習修復的朋友,先去理解以下網址的觀念。
觀念網址一 (點我)
了解nashorn (點我)
【說明】
在您使用JAVA8環境架設過程中,之所以你的EVENT無法讀取,還有NPC腳本不被使用,
都是因為在JAVA8的環境中,有關於importPackage的方法全都在JAVA8版本後被刪除,不再使用
因此,如要修正此問題,就必須調整JAVA內容,定義nashorn給JAVA知道。
【教學開始】
找到 AbstractScriptManager.JAVA
新增方法
protected AbstractScriptManager() {
sem = new ScriptEngineManager();
}
|
搜尋 protected Invocable getInvocable
改寫方法
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;
}
|
找到 EventScriptManager .JAVA
搜尋 EventScriptManager(final ChannelServer cserv, final String[] scripts)
改寫方法
public EventScriptManager(final ChannelServer cserv, final String[] scripts) throws ScriptException {
super();
for (final String script : scripts) {
if (!script.equals("")) {
final Invocable iv = getInvocable("event/" + script + ".js", null);
if (iv != null) {
events.put(script, new EventEntry(script, iv, new EventManager(cserv, iv, script)));
}
}
}
}
|
完成後,即可正常在JAVA8環境中,順利讀取所有腳本。
接下來,如有任何問題,請至論壇技術交流版發問。
每次在讀取後寫入在執行會導致性能低落
回覆刪除期待您提供更好的教學^_^
刪除