feat: 调整重启引擎逻辑
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
3c888c7da7
commit
db96c11a5e
@ -32,7 +32,7 @@ public class MiaoScript extends JavaPlugin implements Executor {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
new CommandSub("ms", this);
|
new CommandSub("ms", this);
|
||||||
saveScript();
|
saveScript();
|
||||||
loadEngine();
|
enableEngine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Cmd
|
@Cmd
|
||||||
@ -51,12 +51,12 @@ public class MiaoScript extends JavaPlugin implements Executor {
|
|||||||
|
|
||||||
@Cmd
|
@Cmd
|
||||||
@Help("重启脚本引擎")
|
@Help("重启脚本引擎")
|
||||||
@SneakyThrows
|
|
||||||
public void reload(CommandSender sender) {
|
public void reload(CommandSender sender) {
|
||||||
engine.invokeFunction("disable");
|
disableEngine();
|
||||||
engine.invokeFunction("boot", this);
|
enableEngine();
|
||||||
|
Log.sender(sender, "§bMiaoScript §eEngine §a重启完成!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void result(CommandSender sender, Object result) {
|
private void result(CommandSender sender, Object result) {
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
Log.sender(sender, "§a运行成功! §c没有返回结果!");
|
Log.sender(sender, "§a运行成功! §c没有返回结果!");
|
||||||
@ -69,7 +69,7 @@ public class MiaoScript extends JavaPlugin implements Executor {
|
|||||||
P.saveFile(true, "core", "modules", "kit");
|
P.saveFile(true, "core", "modules", "kit");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadEngine() {
|
private void enableEngine() {
|
||||||
Thread currentThread = Thread.currentThread();
|
Thread currentThread = Thread.currentThread();
|
||||||
ClassLoader previousClassLoader = currentThread.getContextClassLoader();
|
ClassLoader previousClassLoader = currentThread.getContextClassLoader();
|
||||||
currentThread.setContextClassLoader(getClassLoader());
|
currentThread.setContextClassLoader(getClassLoader());
|
||||||
@ -86,8 +86,7 @@ public class MiaoScript extends JavaPlugin implements Executor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void disableEngine() {
|
||||||
public void onDisable() {
|
|
||||||
try {
|
try {
|
||||||
engine.invokeFunction("disable");
|
engine.invokeFunction("disable");
|
||||||
} catch (ScriptException | NoSuchMethodException e) {
|
} catch (ScriptException | NoSuchMethodException e) {
|
||||||
@ -95,4 +94,9 @@ public class MiaoScript extends JavaPlugin implements Executor {
|
|||||||
Log.d(e);
|
Log.d(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
disableEngine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user