From 5f3db15b41ffa72cec28968b2b6a19a8cb820587 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Fri, 22 Jul 2016 20:52:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../java/pw/yumc/Yum/commands/YumCommand.java | 8 ++++---- .../pw/yumc/Yum/inject/CommandInjector.java | 4 ++-- .../pw/yumc/Yum/inject/ListenerInjector.java | 4 ++-- .../java/pw/yumc/Yum/inject/TaskInjector.java | 4 ++-- .../pw/yumc/Yum/managers/MonitorManager.java | 18 ++++++++++++++---- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/java/pw/yumc/Yum/commands/YumCommand.java b/src/main/java/pw/yumc/Yum/commands/YumCommand.java index 8f9630c..8ea2898 100644 --- a/src/main/java/pw/yumc/Yum/commands/YumCommand.java +++ b/src/main/java/pw/yumc/Yum/commands/YumCommand.java @@ -44,16 +44,16 @@ import pw.yumc.Yum.models.RepoSerialization.Repositories; */ public class YumCommand implements HandlerCommands, Listener { private final String prefix = "§6[§bYum §a插件管理§6] "; - private final String not_found_from_bukkit = prefix + "§c未在BukkitDev搜索到 %s 的相关插件!"; - private final String not_found_id_from_bukkit = prefix + "§c未在BukkitDev搜索到ID为 %s 的相关插件!"; private final String searchlimit = prefix + "§c为保证搜索速度和准确性 关键词必须大于 3 个字符!"; - private final String searching = prefix + "§a正在从BukkitDev获取 §b%s §a的相关数据..."; + private final String searching = prefix + "§a正在从 §eBukkitDev 获取 §b%s §a的相关数据..."; + private final String not_found_from_bukkit = prefix + "§c未在 §eBukkitDev 搜索到 %s 的相关插件!"; private final String result = prefix + "§6关键词 §b%s §6的搜索结果如下:"; private final String bukkitlistprefix = " §6插件ID §3插件名称 §d发布类型 §a操作"; private final String bukkitlist = "§6- §e%-6s §b%-25s §d%-10s"; - private final String fsearching = prefix + "§a正在从BukkitDev获取ID §b%s §a的文件列表..."; + private final String fsearching = prefix + "§a正在从 §eBukkitDev 获取ID §b%s §a的文件列表..."; + private final String not_found_id_from_bukkit = prefix + "§c未在 §eBukkitDev 搜索到ID为 %s 的相关插件!"; private final String filelistprefix = " §6插件名称 §3游戏版本 §d发布类型 §a操作"; private final String filelist = "§6- §b%-20s §3%-15s §d%-10s"; diff --git a/src/main/java/pw/yumc/Yum/inject/CommandInjector.java b/src/main/java/pw/yumc/Yum/inject/CommandInjector.java index 22a9db6..f52b3af 100644 --- a/src/main/java/pw/yumc/Yum/inject/CommandInjector.java +++ b/src/main/java/pw/yumc/Yum/inject/CommandInjector.java @@ -109,7 +109,7 @@ public class CommandInjector implements TabExecutor { final long end = System.nanoTime(); final long lag = end - start; if (Bukkit.isPrimaryThread() && lag / 1000000 > MonitorManager.lagTime) { - PluginKit.sc("§6[§bYum §a能耗监控§6] §c注意! §6玩家 §a" + sender.getName() + " §6执行 §b" + plugin.getName() + " §6插件 §d" + label + " " + StrKit.join(args, " ") + " §6命令 §c耗时 §4" + lag / 1000000 + "ms!"); + MonitorManager.lagTip("§c注意! §6玩家 §a" + sender.getName() + " §6执行 §b" + plugin.getName() + " §6插件 §d" + label + " " + StrKit.join(args, " ") + " §6命令 §c耗时 §4" + lag / 1000000 + "ms!"); } totalTime += lag; count++; @@ -124,7 +124,7 @@ public class CommandInjector implements TabExecutor { sender.sendMessage("§6异常名称: §c" + e.getClass().getName()); sender.sendMessage("§6异常说明: §3" + e.getMessage()); MonitorCommand.lastError = e; - PluginKit.sc(prefix + "§6玩家 §a" + sender.getName() + " §6执行 §b" + plugin.getName() + " §6插件 §d" + label + " " + StrKit.join(args, " ") + " §6命令时发生异常!"); + MonitorManager.log(prefix + "§6玩家 §a" + sender.getName() + " §6执行 §b" + plugin.getName() + " §6插件 §d" + label + " " + StrKit.join(args, " ") + " §6命令时发生异常!"); MonitorManager.print(e); } return false; diff --git a/src/main/java/pw/yumc/Yum/inject/ListenerInjector.java b/src/main/java/pw/yumc/Yum/inject/ListenerInjector.java index 5fa2ab3..031995e 100644 --- a/src/main/java/pw/yumc/Yum/inject/ListenerInjector.java +++ b/src/main/java/pw/yumc/Yum/inject/ListenerInjector.java @@ -99,7 +99,7 @@ public class ListenerInjector implements EventExecutor { final String en = event.getEventName(); final long lag = end - start; if (lag / 1000000 > MonitorManager.lagTime && !ConfigManager.i().getMonitorIgnoreList().contains(plugin.getName())) { - PluginKit.sc("§6[§bYum §a能耗监控§6] §c注意! §6插件 §b" + plugin.getName() + " §6处理 §d" + event.getEventName() + " §6事件 §c耗时 §4" + lag / 1000000 + "ms!"); + MonitorManager.lagTip("§c注意! §6插件 §b" + plugin.getName() + " §6处理 §d" + event.getEventName() + " §6事件 §c耗时 §4" + lag / 1000000 + "ms!"); } if (eventTotalTime.containsKey(en)) { eventTotalTime.put(en, eventTotalTime.get(en) + lag); @@ -117,7 +117,7 @@ public class ListenerInjector implements EventExecutor { e = e.getCause(); } MonitorCommand.lastError = e; - PluginKit.sc(prefix + "§6插件 §b" + plugin.getName() + " §6处理 §d" + event.getEventName() + " §6事件时发生异常!"); + MonitorManager.log(prefix + "§6插件 §b" + plugin.getName() + " §6处理 §d" + event.getEventName() + " §6事件时发生异常!"); MonitorManager.print(e); } } diff --git a/src/main/java/pw/yumc/Yum/inject/TaskInjector.java b/src/main/java/pw/yumc/Yum/inject/TaskInjector.java index 78e8059..c45f077 100644 --- a/src/main/java/pw/yumc/Yum/inject/TaskInjector.java +++ b/src/main/java/pw/yumc/Yum/inject/TaskInjector.java @@ -87,7 +87,7 @@ public class TaskInjector implements Runnable { final long end = System.nanoTime(); final long lag = end - start; if (Bukkit.isPrimaryThread() && lag / 1000000 > MonitorManager.lagTime) { - PluginKit.sc("§6[§bYum §a能耗监控§6] §c注意! §6插件 §b" + plugin.getName() + " §6执行 §d" + taskName + " §6任务 §c耗时 §4" + lag / 1000000 + "ms!"); + MonitorManager.lagTip("§6[§bYum §a能耗监控§6] §c注意! §6插件 §b" + plugin.getName() + " §6执行 §d" + taskName + " §6任务 §c耗时 §4" + lag / 1000000 + "ms!"); } totalTime += lag; count++; @@ -97,7 +97,7 @@ public class TaskInjector implements Runnable { e = e.getCause(); } MonitorCommand.lastError = e; - PluginKit.sc(prefix + "§6插件 §b" + plugin.getName() + " §6执行 §d" + taskName + " §6任务时发生异常!"); + MonitorManager.log(prefix + "§6插件 §b" + plugin.getName() + " §6执行 §d" + taskName + " §6任务时发生异常!"); MonitorManager.print(e); } diff --git a/src/main/java/pw/yumc/Yum/managers/MonitorManager.java b/src/main/java/pw/yumc/Yum/managers/MonitorManager.java index 33dd056..d8acaf3 100644 --- a/src/main/java/pw/yumc/Yum/managers/MonitorManager.java +++ b/src/main/java/pw/yumc/Yum/managers/MonitorManager.java @@ -10,6 +10,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import cn.citycraft.PluginHelper.kit.LogKit; import cn.citycraft.PluginHelper.kit.PluginKit; /** @@ -18,6 +19,7 @@ import cn.citycraft.PluginHelper.kit.PluginKit; * @author 喵♂呜 */ public class MonitorManager { + public static String prefix = "§6[§bYum §a能耗监控§6] "; public static int lagTime = 20; public static boolean debug = ConfigManager.i().isMonitorDebug(); @@ -51,14 +53,22 @@ public class MonitorManager { return new MonitorInfo(monitor.get(pname) / um, cmd.get(pname) / um, event.get(pname) / um, task.get(pname) / um); } + public static void lagTip(final String message) { + LogKit.DEFAULT.logSender(prefix + message); + } + + public static void log(final String message) { + LogKit.DEFAULT.logSender(message); + } + public static void print(final Throwable e) { - PluginKit.sc("§6异常名称: §c" + e.getClass().getName()); - PluginKit.sc("§6异常说明: §3" + e.getMessage()); - PluginKit.sc("§6简易错误信息如下:"); + LogKit.DEFAULT.logSender("§6异常名称: §c" + e.getClass().getName()); + LogKit.DEFAULT.logSender("§6异常说明: §3" + e.getMessage()); + LogKit.DEFAULT.logSender("§6简易错误信息如下:"); final int l = e.getStackTrace().length > 5 ? 5 : e.getStackTrace().length; for (int i = 0; i < l; i++) { final StackTraceElement ste = e.getStackTrace()[i]; - PluginKit.sc(" §e位于 §c" + ste.getClassName() + "." + ste.getMethodName() + "(§4" + ste.getFileName() + ":" + ste.getLineNumber() + "§c)"); + LogKit.DEFAULT.logSender(" §e位于 §c" + ste.getClassName() + "." + ste.getMethodName() + "(§4" + ste.getFileName() + ":" + ste.getLineNumber() + "§c)"); } if (debug) { PluginKit.sc("§c开发人员调试信息如下:");