From b30fe1d49541a4dbebacfb5b174b6eac0b0712c4 Mon Sep 17 00:00:00 2001 From: OcZi Date: Tue, 19 Apr 2022 00:27:04 -0500 Subject: [PATCH 1/2] refactor(BukkitCommandManager): replace error handle of InvalidSubCommandException with common handle --- .../commandflow/bukkit/BukkitCommandManager.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Bukkit/src/main/java/me/fixeddev/commandflow/bukkit/BukkitCommandManager.java b/Bukkit/src/main/java/me/fixeddev/commandflow/bukkit/BukkitCommandManager.java index 75528848..c280061c 100644 --- a/Bukkit/src/main/java/me/fixeddev/commandflow/bukkit/BukkitCommandManager.java +++ b/Bukkit/src/main/java/me/fixeddev/commandflow/bukkit/BukkitCommandManager.java @@ -67,20 +67,13 @@ public BukkitCommandManager(CommandManager delegate, String fallbackPrefix) { return true; }); - this.getErrorHandler().addExceptionHandler(InvalidSubCommandException.class, (namespace, ex) -> { - BukkitCommandWrapper.sendMessageToSender(ex, namespace); - - String label = namespace.getObject(String.class, "label"); - - throw new org.bukkit.command.CommandException("An internal parse exception occurred while executing the command " + label, ex); - }); - ErrorHandler.ErrorConsumer commonArgumentExceptionConsumer = (namespace, ex) -> { BukkitCommandWrapper.sendMessageToSender(ex, namespace); return false; }; + this.getErrorHandler().addExceptionHandler(InvalidSubCommandException.class, commonArgumentExceptionConsumer); this.getErrorHandler().addExceptionHandler(ArgumentParseException.class, commonArgumentExceptionConsumer); this.getErrorHandler().addExceptionHandler(NoMoreArgumentsException.class, commonArgumentExceptionConsumer); this.getErrorHandler().addExceptionHandler(NoPermissionsException.class, (namespace, throwable) -> { From 3d44b6d736a8d33410b61b1e469bd5a270fc7fdc Mon Sep 17 00:00:00 2001 From: OcZi Date: Tue, 19 Apr 2022 00:55:12 -0500 Subject: [PATCH 2/2] refactor: apply common handler of InvalidSubCommandException in all the modules --- .../fixeddev/commandflow/bungee/BungeeCommandManager.java | 7 +------ .../commandflow/discord/DiscordCommandManager.java | 6 +----- .../commandflow/velocity/VelocityCommandManager.java | 6 +----- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/Bungee/src/main/java/me/fixeddev/commandflow/bungee/BungeeCommandManager.java b/Bungee/src/main/java/me/fixeddev/commandflow/bungee/BungeeCommandManager.java index 7b52b485..463ed6f5 100644 --- a/Bungee/src/main/java/me/fixeddev/commandflow/bungee/BungeeCommandManager.java +++ b/Bungee/src/main/java/me/fixeddev/commandflow/bungee/BungeeCommandManager.java @@ -62,12 +62,6 @@ public BungeeCommandManager(CommandManager commandManager, Plugin plugin) { return false; }); - getErrorHandler().addExceptionHandler(InvalidSubCommandException.class, (namespace, e) -> { - String label = namespace.getObject(String.class, "label"); - BungeeCommandWrapper.sendMessageToSender(e, namespace); - - throw new CommandException("An internal parse exception occurred while executing the command " + label, e); - }); ErrorHandler.ErrorConsumer commonHandler = (namespace, e) -> { BungeeCommandWrapper.sendMessageToSender(e, namespace); @@ -75,6 +69,7 @@ public BungeeCommandManager(CommandManager commandManager, Plugin plugin) { return true; }; + getErrorHandler().addExceptionHandler(InvalidSubCommandException.class, commonHandler); getErrorHandler().addExceptionHandler(ArgumentParseException.class, commonHandler); getErrorHandler().addExceptionHandler(NoMoreArgumentsException.class, commonHandler); getErrorHandler().addExceptionHandler(NoPermissionsException.class, commonHandler); diff --git a/Discord/src/main/java/me/fixeddev/commandflow/discord/DiscordCommandManager.java b/Discord/src/main/java/me/fixeddev/commandflow/discord/DiscordCommandManager.java index b48b2da0..b0067033 100644 --- a/Discord/src/main/java/me/fixeddev/commandflow/discord/DiscordCommandManager.java +++ b/Discord/src/main/java/me/fixeddev/commandflow/discord/DiscordCommandManager.java @@ -57,11 +57,6 @@ public DiscordCommandManager(CommandManager commandManager, JDA client, String c return true; }); - getErrorHandler().addExceptionHandler(InvalidSubCommandException.class, (namespace, e) -> { - MessageListener.sendMessage(namespace, e); - - throw new CommandException("An internal parse exception occurred while executing the command", e); - }); ErrorHandler.ErrorConsumer commonHandler = (namespace, e) -> { MessageListener.sendMessage(namespace, e); @@ -69,6 +64,7 @@ public DiscordCommandManager(CommandManager commandManager, JDA client, String c return true; }; + getErrorHandler().addExceptionHandler(InvalidSubCommandException.class, commonHandler); getErrorHandler().addExceptionHandler(ArgumentParseException.class, commonHandler); getErrorHandler().addExceptionHandler(NoMoreArgumentsException.class, commonHandler); getErrorHandler().addExceptionHandler(NoPermissionsException.class, commonHandler); diff --git a/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandManager.java b/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandManager.java index a588cd88..c2dd1b3d 100644 --- a/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandManager.java +++ b/Velocity/src/main/java/me/fixeddev/commandflow/velocity/VelocityCommandManager.java @@ -64,11 +64,6 @@ public VelocityCommandManager(ProxyServer proxyServer, CommandManager commandMan return true; }); - getErrorHandler().addExceptionHandler(InvalidSubCommandException.class, (namespace, e) -> { - VelocityCommandWrapper.sendMessageToSender(e, namespace); - - throw new CommandException("An internal parse exception occurred while executing the command", e); - }); ErrorHandler.ErrorConsumer commonHandler = (namespace, e) -> { VelocityCommandWrapper.sendMessageToSender(e, namespace); @@ -76,6 +71,7 @@ public VelocityCommandManager(ProxyServer proxyServer, CommandManager commandMan return true; }; + getErrorHandler().addExceptionHandler(InvalidSubCommandException.class, commonHandler); getErrorHandler().addExceptionHandler(ArgumentParseException.class, commonHandler); getErrorHandler().addExceptionHandler(NoMoreArgumentsException.class, commonHandler); getErrorHandler().addExceptionHandler(NoPermissionsException.class, commonHandler);