From db96c11a5e95a55134670dcda24c71ba87694ba7 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Wed, 11 Oct 2017 16:43:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=B0=83=E6=95=B4=E9=87=8D=E5=90=AF?= =?UTF-8?q?=E5=BC=95=E6=93=8E=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../java/pw/yumc/MiaoScript/MiaoScript.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/pw/yumc/MiaoScript/MiaoScript.java b/src/main/java/pw/yumc/MiaoScript/MiaoScript.java index ad0e98e..229ac91 100644 --- a/src/main/java/pw/yumc/MiaoScript/MiaoScript.java +++ b/src/main/java/pw/yumc/MiaoScript/MiaoScript.java @@ -32,7 +32,7 @@ public class MiaoScript extends JavaPlugin implements Executor { public void onEnable() { new CommandSub("ms", this); saveScript(); - loadEngine(); + enableEngine(); } @Cmd @@ -51,12 +51,12 @@ public class MiaoScript extends JavaPlugin implements Executor { @Cmd @Help("重启脚本引擎") - @SneakyThrows public void reload(CommandSender sender) { - engine.invokeFunction("disable"); - engine.invokeFunction("boot", this); + disableEngine(); + enableEngine(); + Log.sender(sender, "§bMiaoScript §eEngine §a重启完成!"); } - + private void result(CommandSender sender, Object result) { if (result == null) { Log.sender(sender, "§a运行成功! §c没有返回结果!"); @@ -69,7 +69,7 @@ public class MiaoScript extends JavaPlugin implements Executor { P.saveFile(true, "core", "modules", "kit"); } - private void loadEngine() { + private void enableEngine() { Thread currentThread = Thread.currentThread(); ClassLoader previousClassLoader = currentThread.getContextClassLoader(); currentThread.setContextClassLoader(getClassLoader()); @@ -86,8 +86,7 @@ public class MiaoScript extends JavaPlugin implements Executor { } } - @Override - public void onDisable() { + private void disableEngine() { try { engine.invokeFunction("disable"); } catch (ScriptException | NoSuchMethodException e) { @@ -95,4 +94,9 @@ public class MiaoScript extends JavaPlugin implements Executor { Log.d(e); } } + + @Override + public void onDisable() { + disableEngine(); + } }