mirror of
				https://e.coding.net/circlecloud/YumCore.git
				synced 2025-11-03 23:06:02 +00:00 
			
		
		
		
	fix: 修复命令执行时抛出CommandException未拦截的问题
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
		@@ -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());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user