微信扫一扫 分享朋友圈

已有 966 人浏览分享

[服務器教學] 解決 JAVA8 腳本讀取問題

[複製鏈接]

站長

Rank: 12Rank: 12Rank: 12

1780

威望

3023

金錢

111

A幣
主題
1320
帖子
2448
精華
3
綜合社群主題發文量
264
電玩社群主題發文量
1
娛樂社群主題發文量
4
技術社群主題發文量
28
閱讀權限
200
註冊時間
2013-1-28

我是傳奇贊助感謝勳章精華作者勳章

  • TA的每日心情
    開心
    昨天 00:01
  • 簽到天數: 384 天

    連續簽到: 3 天

    [LV.9]以壇為家II

    TWAICL 發表於  2017-6-5 18:39:46 | 顯示全部樓層 | 閱讀模式



    【前言】

    關於此問題,我希望在學習修復的朋友,先去理解以下網址的觀念。
    觀念網址一 (點我)
    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環境中,順利讀取所有腳本。
    接下來,如有任何問題,請至論壇技術交流版發問。
    共收到 0 A幣
    打賞榜
    暫無
    暫無
    暫無
    暫無
    ----
    暫無
    ----
    暫無
    ----
    暫無
    ----
    您需要登錄後才可以回帖 登錄 | 註冊會員

    本版積分規則

    2448

    發文

    3023

    金錢

    111

    A幣

    ----------榮譽勳章----------

    我是傳奇 贊助感謝勳章 精華作者勳章

    熱門推薦
    圖文推薦
    • 聯繫我們

    小黑屋|AICL社群娛樂集團

    GMT+8, 2024-5-12 22:36 , 網路刷新 0.109663 秒 .

    歡迎來到 AICL網路社群

    版權AICL社群所有 2011-2021.

    Total:123 Today:213 Online:322