From ae621a855e2c8c1f72577d44efc34dcac4a5c680 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 5 Jul 2016 11:01:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=B8=BB=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=93=8D=E4=BD=9C=E6=8F=92=E4=BB=B6=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../Yum/runnables/MainThreadCheckTask.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/pw/yumc/Yum/runnables/MainThreadCheckTask.java b/src/main/java/pw/yumc/Yum/runnables/MainThreadCheckTask.java index db63025..e5d95cf 100644 --- a/src/main/java/pw/yumc/Yum/runnables/MainThreadCheckTask.java +++ b/src/main/java/pw/yumc/Yum/runnables/MainThreadCheckTask.java @@ -2,18 +2,23 @@ package pw.yumc.Yum.runnables; import java.lang.Thread.State; import java.util.TimerTask; -import java.util.logging.Level; -import cn.citycraft.PluginHelper.kit.PKit; +import org.bukkit.plugin.Plugin; + +import cn.citycraft.PluginHelper.kit.PluginKit; /** * 线程安全检查任务 - * + * * @since 2016年6月22日 下午4:57:32 * @author 喵♂呜 */ public class MainThreadCheckTask extends TimerTask { - + public String prefix = "§6[§bYum §a线程管理§6] "; + public String warnPNet = "§6插件 §b%s §c在主线程进行网络操作 §4服务器处于停止状态..."; + public String warnPIO = "§6插件 §b%s §c在主线程进行IO操作 §4服务器处于停止状态..."; + public String warnNet = "§c主线程存在网络操作 §4服务器处于停止状态..."; + public String warnIO = "§c主线程存在IO操作 §4服务器处于停止状态..."; private final Thread mainThread; public MainThreadCheckTask(final Thread mainThread) { @@ -37,12 +42,22 @@ public class MainThreadCheckTask extends TimerTask { if (isElementEqual(topElement, "java.net.DualStackPlainSocketImpl", "connect0") || isElementEqual(topElement, "java.net.SocketInputStream", "socketRead0") || isElementEqual(topElement, "java.net.SocketOutputStream", "socketWrite0")) { - PKit.i().getLogger().log(Level.WARNING, "主线程存在网络操作 服务器处于停止状态...", stackTrace); + final Plugin plugin = PluginKit.getOperatePlugin(stackTrace); + if (plugin != null) { + PluginKit.sc(String.format(prefix + warnPNet, plugin.getName())); + } else { + PluginKit.sc(prefix + warnNet); + } } // File (in) - java.io.FileInputStream.readBytes // File (out) - java.io.FileOutputStream.writeBytes else if (isElementEqual(topElement, "java.io.FileInputStream", "readBytes") || isElementEqual(topElement, "java.io.FileOutputStream", "writeBytes")) { - PKit.i().getLogger().log(Level.WARNING, "主线程存在IO操作 服务器处于停止状态...", stackTrace); + final Plugin plugin = PluginKit.getOperatePlugin(stackTrace); + if (plugin != null) { + PluginKit.sc(String.format(prefix + warnPIO, plugin.getName())); + } else { + PluginKit.sc(prefix + warnIO); + } } } }