mirror of
https://e.coding.net/circlecloud/Yum.git
synced 2024-11-22 14:28:46 +00:00
fix: 修复线程检查任务
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
b3dea9a5e3
commit
d62a36815e
@ -30,6 +30,8 @@ import pw.yumc.Yum.runnables.MainThreadCheckTask;
|
||||
* @since 2015年8月21日下午5:14:39
|
||||
*/
|
||||
public class Yum extends JavaPlugin {
|
||||
public static Thread mainThread = null;
|
||||
|
||||
@Override
|
||||
public FileConfiguration getConfig() {
|
||||
return ConfigManager.i().config;
|
||||
@ -42,6 +44,9 @@ public class Yum extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
mainThread = Thread.currentThread();
|
||||
}
|
||||
new YumAPI();
|
||||
initCommands();
|
||||
initListeners();
|
||||
@ -92,7 +97,7 @@ public class Yum extends JavaPlugin {
|
||||
new PluginNetworkListener(this);
|
||||
PluginKit.scp("§a网络管理系统已启用...");
|
||||
}
|
||||
if (ConfigManager.i().isThreadSafe() && Bukkit.isPrimaryThread()) {
|
||||
if (ConfigManager.i().isThreadSafe()) {
|
||||
new ThreadSafetyListener(this);
|
||||
PluginKit.scp("§a线程管理系统已启用...");
|
||||
}
|
||||
@ -103,10 +108,10 @@ public class Yum extends JavaPlugin {
|
||||
*/
|
||||
private void initRunnable() {
|
||||
// 需要在主线程注册任务
|
||||
if (ConfigManager.i().isMainThreadCheck() && Bukkit.isPrimaryThread()) {
|
||||
if (ConfigManager.i().isMainThreadCheck() && mainThread != null) {
|
||||
final Timer task = new Timer();
|
||||
PluginKit.scp("§aIO管理系统已启用...");
|
||||
task.scheduleAtFixedRate(new MainThreadCheckTask(Thread.currentThread()), 0, 3000);
|
||||
task.scheduleAtFixedRate(new MainThreadCheckTask(mainThread), 0, 3000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,6 @@ import pw.yumc.Yum.Yum;
|
||||
*/
|
||||
public class ThreadSafetyListener implements Listener {
|
||||
|
||||
private final Thread mainThread = Thread.currentThread();
|
||||
|
||||
public ThreadSafetyListener(final Yum yum) {
|
||||
Bukkit.getPluginManager().registerEvents(this, yum);
|
||||
}
|
||||
@ -99,7 +97,7 @@ public class ThreadSafetyListener implements Listener {
|
||||
}
|
||||
|
||||
private void checkSafety(final Event eventType) {
|
||||
if (Thread.currentThread() != mainThread && !eventType.isAsynchronous()) {
|
||||
if (Yum.mainThread != null && Thread.currentThread() != Yum.mainThread && !eventType.isAsynchronous()) {
|
||||
final String eventName = eventType.getEventName();
|
||||
throw new IllegalAccessError("[Yum 线程安全]: 请勿异步调用一个同步事件 " + eventName);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user