From 60785ec00a960515b92bbfe918b1d959691e045f Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 29 Apr 2017 00:45:24 -0400 Subject: [PATCH] some fixes with reporting of errors --- .../co/aikar/commands/CommandCompletions.java | 2 +- .../co/aikar/commands/RegisteredCommand.java | 28 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/co/aikar/commands/CommandCompletions.java b/src/main/java/co/aikar/commands/CommandCompletions.java index ab01ef08..4bcf7a7f 100644 --- a/src/main/java/co/aikar/commands/CommandCompletions.java +++ b/src/main/java/co/aikar/commands/CommandCompletions.java @@ -102,7 +102,7 @@ public class CommandCompletions { } catch (CommandCompletionTextLookupException ignored) { // This should only happen if some other feedback error occured. } catch (Exception e) { - ACFLog.exception(e); + command.handleException(sender, Lists.newArrayList(args), e); } // Something went wrong in lookup, fall back to input return ImmutableList.of(input); diff --git a/src/main/java/co/aikar/commands/RegisteredCommand.java b/src/main/java/co/aikar/commands/RegisteredCommand.java index 8b220e6e..f92475fb 100644 --- a/src/main/java/co/aikar/commands/RegisteredCommand.java +++ b/src/main/java/co/aikar/commands/RegisteredCommand.java @@ -132,20 +132,24 @@ public class RegisteredCommand { method.invoke(scope, passedArgs.values().toArray()); } catch (Exception e) { - if (e instanceof InvocationTargetException && e.getCause() instanceof InvalidCommandArgument) { - e = (Exception) e.getCause(); + handleException(sender, args, e); + } + } + + void handleException(CommandSender sender, List args, Exception e) { + if (e instanceof InvocationTargetException && e.getCause() instanceof InvalidCommandArgument) { + e = (Exception) e.getCause(); + } + if (e instanceof InvalidCommandArgument) { + if (e.getMessage() != null && !e.getMessage().isEmpty()) { + ACFUtil.sendMsg(sender, "&cError: " + e.getMessage()); } - if (e instanceof InvalidCommandArgument) { - if (e.getMessage() != null && !e.getMessage().isEmpty()) { - ACFUtil.sendMsg(sender, "&cError: " + e.getMessage()); - } - if (((InvalidCommandArgument) e).showSyntax) { - scope.showSyntax(sender, this); - } - } else { - ACFUtil.sendMsg(sender, "&cI'm sorry, but there was an error performing this command."); - ACFLog.exception("Exception in command: " + command + " " + ACFUtil.join(args), e); + if (((InvalidCommandArgument) e).showSyntax) { + scope.showSyntax(sender, this); } + } else { + ACFUtil.sendMsg(sender, "&cI'm sorry, but there was an error performing this command."); + ACFLog.exception("Exception in command: " + command + " " + ACFUtil.join(args), e); } }