diff --git a/src/main/java/pw/yumc/MiaoScript/MiaoScript.java b/src/main/java/pw/yumc/MiaoScript/MiaoScript.java index 3e304c9..8988e5b 100644 --- a/src/main/java/pw/yumc/MiaoScript/MiaoScript.java +++ b/src/main/java/pw/yumc/MiaoScript/MiaoScript.java @@ -10,7 +10,6 @@ import org.bukkit.plugin.java.JavaPlugin; import lombok.SneakyThrows; import lombok.val; import pw.yumc.YumCore.bukkit.Log; -import pw.yumc.YumCore.bukkit.P; import pw.yumc.YumCore.commands.CommandSub; import pw.yumc.YumCore.commands.annotation.Cmd; import pw.yumc.YumCore.commands.annotation.Help; @@ -30,6 +29,7 @@ public class MiaoScript extends JavaPlugin implements Executor { public void onEnable() { new CommandSub("ms", this); engine = new ScriptEngine(getDataFolder().getCanonicalPath(), getLogger()); + engine.enableEngine(getClassLoader()); } @Cmd @@ -60,7 +60,7 @@ public class MiaoScript extends JavaPlugin implements Executor { } catch (Exception ex) { Log.d("Error reload", ex); } - engine.enableEngine(); + engine.enableEngine(getClassLoader()); Log.sender(sender, "§bMiaoScript §eEngine §a重启完成!"); } diff --git a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java index f859f58..d83a1a4 100644 --- a/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java +++ b/src/main/java/pw/yumc/MiaoScript/ScriptEngine.java @@ -1,16 +1,11 @@ package pw.yumc.MiaoScript; -import java.lang.Thread; import java.io.InputStreamReader; -import java.util.logging.Level; -import java.util.logging.Logger; - -import java.nio.file.Paths; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import javax.script.ScriptEngineManager; -import javax.script.ScriptException; import lombok.SneakyThrows; import pw.yumc.YumCore.engine.MiaoScriptEngine; @@ -19,7 +14,7 @@ import pw.yumc.YumCore.engine.MiaoScriptEngine; * Created with IntelliJ IDEA * * @author 喵♂呜 - * Created on 2017/10/25 21:01. + * Created on 2017/10/25 21:01. */ public class ScriptEngine { private String root; @@ -29,11 +24,14 @@ public class ScriptEngine { public ScriptEngine(String root, Object logger) { this.root = root; this.logger = logger; - enableEngine(); + } + + public void enableEngine() { + enableEngine(Thread.currentThread().getContextClassLoader()); } @SneakyThrows - public void enableEngine() { + public void enableEngine(ClassLoader loader) { ScriptEngineManager manager = new ScriptEngineManager(null); this.engine = new MiaoScriptEngine(manager, "nashorn"); this.engine.put("base", new Base()); @@ -42,7 +40,7 @@ public class ScriptEngine { if (Files.exists(bios)) { this.engine.eval("load('" + bios.toFile().getCanonicalPath() + "')"); } else { - this.engine.eval(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("bios.js"))); + this.engine.eval(new InputStreamReader(loader.getResourceAsStream("bios.js"))); } engine.invokeFunction("boot", root, logger); }