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

Signed-off-by: MiaoWoo <admin@yumc.pw>
merge/16/MERGE
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 cmdDes = "§6命令描述: §3%s";
private static String argErr = "§c参数错误: §4%s";
private static String execErr = "§c命令执行失败: §4%s";
@Override
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) {
Log.sender(sender, argErr, e.getMessage());
} else {
throw e;
Log.sender(sender, execErr, e.getMessage());
}
}
}

View File

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