From 8e30399465bd632adc8c201ad4ceb13f72a82f76 Mon Sep 17 00:00:00 2001 From: coding Date: Wed, 11 Oct 2017 16:37:24 +0000 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E5=8A=A8=E5=8F=8D?= =?UTF-8?q?=E5=B0=84=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/pw/yumc/MiaoScript/MiaoScript.java | 6 +++--- src/main/resources/{kit => core}/reflect.js | 0 src/main/resources/modules/bukkit.js | 1 + src/main/resources/modules/event.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) rename src/main/resources/{kit => core}/reflect.js (100%) diff --git a/src/main/java/pw/yumc/MiaoScript/MiaoScript.java b/src/main/java/pw/yumc/MiaoScript/MiaoScript.java index 229ac91..0b00809 100644 --- a/src/main/java/pw/yumc/MiaoScript/MiaoScript.java +++ b/src/main/java/pw/yumc/MiaoScript/MiaoScript.java @@ -46,7 +46,7 @@ public class MiaoScript extends JavaPlugin implements Executor { @Help("执行 JS 代码文件") @SneakyThrows public void file(CommandSender sender, String file) { - result(sender, engine.eval(new FileReader(new File(getDataFolder(), file)))); + result(sender, engine.eval("load('" + new File(getDataFolder(), file).getCanonicalPath() + "')")); } @Cmd @@ -66,7 +66,7 @@ public class MiaoScript extends JavaPlugin implements Executor { } private void saveScript() { - P.saveFile(true, "core", "modules", "kit"); + P.saveFile(true, "core", "modules"); } private void enableEngine() { @@ -75,7 +75,7 @@ public class MiaoScript extends JavaPlugin implements Executor { currentThread.setContextClassLoader(getClassLoader()); try { ScriptEngineManager manager = new ScriptEngineManager(); - this.engine = new MiaoScriptEngine(manager); + this.engine = new MiaoScriptEngine(manager, "nashorn"); this.engine.put("base", new Base()); this.engine.eval(new InputStreamReader(this.getResource("bios.js"))); engine.invokeFunction("boot", this); diff --git a/src/main/resources/kit/reflect.js b/src/main/resources/core/reflect.js similarity index 100% rename from src/main/resources/kit/reflect.js rename to src/main/resources/core/reflect.js diff --git a/src/main/resources/modules/bukkit.js b/src/main/resources/modules/bukkit.js index 3e45a40..16e06c7 100644 --- a/src/main/resources/modules/bukkit.js +++ b/src/main/resources/modules/bukkit.js @@ -8,6 +8,7 @@ var Bukkit = Java.type("org.bukkit.Bukkit"); // noinspection JSUnresolvedVariable var PluginManager = Bukkit.pluginManager; +exports.$ = Bukkit; /** * 插件管理 * @type {{manager: *, get: exports.plugin.get, load: exports.plugin.load}} diff --git a/src/main/resources/modules/event.js b/src/main/resources/modules/event.js index 538e185..ee78d67 100644 --- a/src/main/resources/modules/event.js +++ b/src/main/resources/modules/event.js @@ -15,7 +15,7 @@ var IllegalStateException = Java.type("java.lang.IllegalStateException"); var plugin = base.plugin; -var ref = require('kit/reflect'); +var ref = require('reflect'); var jspListener = [];