feat: 新增屏蔽指定插件报错功能

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2021-10-28 09:51:27 +00:00
parent 129f854382
commit 18dc99e78e
7 changed files with 708 additions and 714 deletions

18
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>Yum</artifactId>
<version>2.9.1</version>
<version>2.9.5</version>
<packaging>jar</packaging>
<description>Minecraft 服务器插件管理系统</description>
@ -16,16 +16,18 @@
</parent>
<properties>
<update.description>§a补丁包 2.9.1 版本</update.description>
<update.description>§a补丁包 2.9.5 版本</update.description>
<update.changes>
§620-03-25 §cfix: paper HikariPool error;
§619-09-30 §cfix: tabComplete error;
§619-08-28 §cfix: knownCommands not compatible;
       §cfix: async event on primary thread;
§619-08-26 §cfix: 修复不兼容 1.14.4 的问题;
§619-02-23 §cfix: 修复不兼容 1.13 的问题;
§621-10-28 §afeat: 新增屏蔽插件报错功能;
§620-03-25 §afeat: 优化 当前插件获取逻辑;
§620-03-25 §c修复: Paper HikariPool 不兼容问题;
§619-09-30 §c修复: 自动补全报错的问题;
§619-08-28 §c修复: knownCommands 不兼容;
      §c修复: async event on primary thread;
</update.changes>
<update.changelog>
§619-08-26 §c修复: 修复不兼容 1.14.4 的问题;
§619-02-23 §c修复: 修复不兼容 1.13 的问题;
§617-07-29 §cfix: 修复不兼容 1.12 的问题;
§6- §cfix: §7修复仓库数据读取错误的问题;
§6- §cfix: §7修复一个tab补全产生的错误

View File

@ -1,25 +1,18 @@
package pw.yumc.Yum.inject;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.command.TabCompleter;
import org.bukkit.command.TabExecutor;
import org.bukkit.command.*;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import pw.yumc.Yum.commands.MonitorCommand;
import pw.yumc.Yum.managers.MonitorManager;
import pw.yumc.YumCore.kit.StrKit;
import pw.yumc.YumCore.reflect.Reflect;
import java.util.Collections;
import java.util.List;
public class CommandInjector implements TabExecutor {
private static String prefix = "§6[§bYum §a命令监控§6] ";
private static String warn = "§c注意! §6玩家 §a%s §6执行 §b%s §6插件 §d%s %s §6命令 §c耗时 §4%sms §c平均耗时 §4%sms!";
@ -121,7 +114,7 @@ public class CommandInjector implements TabExecutor {
}
MonitorCommand.lastError = e;
MonitorManager.sendError(sender, plugin, e);
MonitorManager.printThrowable(String.format(err, sender.getName(), plugin.getName(), label, StrKit.join(args, " ")), e);
MonitorManager.printThrowable(plugin, String.format(err, sender.getName(), plugin.getName(), label, StrKit.join(args, " ")), e);
}
return false;
}

View File

@ -1,10 +1,5 @@
package pw.yumc.Yum.inject;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.lang.Validate;
import org.bukkit.event.Event;
import org.bukkit.event.EventException;
@ -14,12 +9,16 @@ import org.bukkit.plugin.EventExecutor;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredListener;
import org.bukkit.plugin.TimedRegisteredListener;
import pw.yumc.Yum.commands.MonitorCommand;
import pw.yumc.Yum.managers.ConfigManager;
import pw.yumc.Yum.managers.MonitorManager;
import pw.yumc.YumCore.reflect.Reflect;
import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class ListenerInjector implements EventExecutor {
private static String prefix = "§6[§bYum §a事件监控§6] ";
private static String warn = "§c注意! §6插件 §b%s §6处理 §d%s §6事件 §c耗时 §4%sms §c平均耗时 §4%sms!";
@ -110,7 +109,7 @@ public class ListenerInjector implements EventExecutor {
e = e.getCause();
}
MonitorCommand.lastError = e;
MonitorManager.printThrowable(String.format(err, plugin.getName(), event.getEventName()), e);
MonitorManager.printThrowable(plugin, String.format(err, plugin.getName(), event.getEventName()), e);
}
}

View File

@ -1,19 +1,18 @@
package pw.yumc.Yum.inject;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import pw.yumc.Yum.commands.MonitorCommand;
import pw.yumc.Yum.managers.MonitorManager;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.kit.StrKit;
import pw.yumc.YumCore.reflect.Reflect;
import java.util.List;
public class TaskInjector implements Runnable {
private static String prefix = "§6[§bYum §a任务监控§6] ";
private static String warn = "§c注意! §6插件 §b%s §6处理 §d%s §6任务 §c耗时 §4%sms §c平均耗时 §4%sms!";
@ -23,14 +22,14 @@ public class TaskInjector implements Runnable {
private static String taskFieldName = "task";
static {
BukkitTask task = Bukkit.getServer().getScheduler().runTask(P.instance, new Runnable(){
BukkitTask task = Bukkit.getServer().getScheduler().runTask(P.instance, new Runnable() {
@Override
public void run() {}
});
try {
Reflect.on(task).get("rTask");
taskFieldName = "rTask";
}catch (Throwable ex) {
} catch (Throwable ex) {
}
}
@ -114,7 +113,7 @@ public class TaskInjector implements Runnable {
e = e.getCause();
}
MonitorCommand.lastError = e;
MonitorManager.printThrowable(String.format(err, plugin.getName(), taskName), e);
MonitorManager.printThrowable(plugin, String.format(err, plugin.getName(), taskName), e);
}
}
}

View File

@ -1,13 +1,12 @@
package pw.yumc.Yum.managers;
import java.util.List;
import org.bukkit.plugin.java.JavaPlugin;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.config.FileConfig;
import pw.yumc.YumCore.sql.DataBase;
import java.util.List;
public class ConfigManager {
public static String ENABLE = "Enable";
public static String BLACK = "Black";
@ -49,6 +48,10 @@ public class ConfigManager {
return monitor.getStringList(IGNORE);
}
public List<String> getMonitorIgnoreErrorList() {
return monitor.getStringList("IgnoreError");
}
public List<String> getNetworkBlackList() {
return network.getStringList(BLACK);
}

View File

@ -1,28 +1,20 @@
package pw.yumc.Yum.managers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.kit.LogKit;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
/**
* 能耗监控管理
*
* @since 2016年7月19日 下午3:55:54
* @author
* @since 2016年7月19日 下午3:55:54
*/
public class MonitorManager {
public static String prefix = "§6[§bYum §a能耗监控§6] ";
@ -96,12 +88,15 @@ public class MonitorManager {
}
}
public static void printThrowable(String title, Throwable e) {
public static void printThrowable(Plugin plugin, String title, Throwable e) {
if (ConfigManager.i().getMonitorIgnoreErrorList().contains(plugin.getName())) {
return;
}
elog(title);
elog(String.format(errN, e.getClass().getName()));
elog(String.format(errM, e.getMessage()));
elog(errInfo);
int l = e.getStackTrace().length > 5 ? 5 : e.getStackTrace().length;
int l = Math.min(e.getStackTrace().length, 5);
for (int i = 0; i < l; i++) {
StackTraceElement ste = e.getStackTrace()[i];
elog(String.format(errStackTrace, ste.getClassName(), ste.getMethodName(), ste.getFileName() == null ? "未知" : ste.getFileName(), ste.getLineNumber()));
@ -136,7 +131,7 @@ public class MonitorManager {
if (oriMap == null || oriMap.isEmpty()) { return oriMap; }
Map<String, Long> sortedMap = new LinkedHashMap<>();
List<Map.Entry<String, Long>> entryList = new ArrayList<>(oriMap.entrySet());
Collections.sort(entryList, new MonitorComparator());
entryList.sort(new MonitorComparator());
Iterator<Map.Entry<String, Long>> iter = entryList.iterator();
Entry<String, Long> tmpEntry;
while (iter.hasNext()) {

View File

@ -3,7 +3,7 @@
############################
#配置版本号 请勿修改!!!
Version: 1.3
Version: 1.4
#是否开启
Enable: true
@ -13,4 +13,7 @@ Debug: false
LogToFile: true
#忽略检测列表
Ignore:
- PluginHelper
- PluginHelper
#忽略报错的插件列表
IgnoreError:
- PluginHelper