1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-24 02:08:48 +00:00

fix: 修复命令执行时抛出CommandException未拦截的问题

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-10-26 10:15:06 +08:00
parent 300dc0d607
commit be1ad18954
2 changed files with 267 additions and 264 deletions

View File

@ -24,6 +24,7 @@ public class CommandError implements ErrorHanlder {
private static String cmdUse = "§6使用方法: §e/%s %s%s"; private static String cmdUse = "§6使用方法: §e/%s %s%s";
private static String cmdDes = "§6命令描述: §3%s"; private static String cmdDes = "§6命令描述: §3%s";
private static String argErr = "§c参数错误: §4%s"; private static String argErr = "§c参数错误: §4%s";
private static String execErr = "§c命令执行失败: §4%s";
@Override @Override
public void error(CommandException e, CommandSender sender, CommandInfo info, String label, String[] args) { public void error(CommandException e, CommandSender sender, CommandInfo info, String label, String[] args) {
@ -39,7 +40,7 @@ public class CommandError implements ErrorHanlder {
} else if (e instanceof ParseException) { } else if (e instanceof ParseException) {
Log.sender(sender, argErr, e.getMessage()); Log.sender(sender, argErr, e.getMessage());
} else { } else {
throw e; Log.sender(sender, execErr, e.getMessage());
} }
} }
} }

View File

@ -1,7 +1,6 @@
package pw.yumc.YumCore.commands.info; package pw.yumc.YumCore.commands.info;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -134,9 +133,12 @@ public class CommandInfo {
try { try {
check(sender, label, args); check(sender, label, args);
method.invoke(origin, parse.parse(sender, label, args)); method.invoke(origin, parse.parse(sender, label, args));
} catch (CommandException e) { } catch (Exception e) {
commandErrorHandler.error(e, sender, this, label, args); if (e.getCause() instanceof CommandException) { e = (Exception) e.getCause(); }
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { if (e instanceof CommandException) {
commandErrorHandler.error((CommandException) e, sender, this, label, args);
return;
}
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}; };