From c0d3edd4b0371275769479da9cb23c45750eb69e Mon Sep 17 00:00:00 2001 From: yoyosource Date: Mon, 3 Jan 2022 00:42:00 +0100 Subject: [PATCH] Improve CommandFramework Exception readability --- .../src/de/steamwar/command/CommandFrameworkException.java | 1 + SpigotCore_Main/src/de/steamwar/command/SWCommand.java | 4 +++- .../testsrc/de/steamwar/command/SimpleCommandTest.java | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/CommandFrameworkException.java b/SpigotCore_Main/src/de/steamwar/command/CommandFrameworkException.java index 916417d..5021a66 100644 --- a/SpigotCore_Main/src/de/steamwar/command/CommandFrameworkException.java +++ b/SpigotCore_Main/src/de/steamwar/command/CommandFrameworkException.java @@ -32,6 +32,7 @@ public class CommandFrameworkException extends RuntimeException { private String message; CommandFrameworkException(InvocationTargetException invocationTargetException, String alias, String[] args) { + super(invocationTargetException); this.invocationTargetException = invocationTargetException; this.alias = alias; this.args = args; diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 6e93262..35ce8f9 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -102,7 +102,9 @@ public abstract class SWCommand { } catch (CommandNoHelpException e) { // Ignored } catch (CommandFrameworkException e) { - Bukkit.getLogger().log(Level.SEVERE, e.getBuildStackTrace()); + if (Bukkit.getServer() != null) { + Bukkit.getLogger().log(Level.SEVERE, e.getBuildStackTrace()); + } throw e; } } diff --git a/SpigotCore_Main/testsrc/de/steamwar/command/SimpleCommandTest.java b/SpigotCore_Main/testsrc/de/steamwar/command/SimpleCommandTest.java index daa72fd..c18728e 100644 --- a/SpigotCore_Main/testsrc/de/steamwar/command/SimpleCommandTest.java +++ b/SpigotCore_Main/testsrc/de/steamwar/command/SimpleCommandTest.java @@ -39,9 +39,9 @@ public class SimpleCommandTest { public void testCommandParsing() { try { simpleCommand.execute(new TestCommandSender(), "", new String[]{}); - } catch (SecurityException securityException) { - if (securityException.getCause().getCause() instanceof ExecutionIdentifier) { - ExecutionIdentifier executionIdentifier = (ExecutionIdentifier) securityException.getCause().getCause(); + } catch (CommandFrameworkException commandFrameworkException) { + if (commandFrameworkException.getCause().getCause() instanceof ExecutionIdentifier) { + ExecutionIdentifier executionIdentifier = (ExecutionIdentifier) commandFrameworkException.getCause().getCause(); assertThat(executionIdentifier.getMessage(), is("Simple execute without any parameters")); return; }