Add custom Exception Handlers (#43)

* Add the ability to register exception handlers to handle exceptions that occur while executing a command

* you saw nothing

* add ability to cancel default error message

* per command exception handler

* add a getter for the default exception handler
This commit is contained in:
MiniDigger
2017-06-15 16:25:25 +02:00
committed by Daniel Ennis
parent 24066faabd
commit eb84340f46
5 changed files with 102 additions and 2 deletions
@@ -45,8 +45,17 @@ public final class ACFExample extends JavaPlugin {
commandManager.getCommandCompletions().registerCompletion("test", c -> (
Lists.newArrayList("foo", "bar", "baz")
));
commandManager.registerCommand(new SomeCommand());
commandManager.registerCommand(new SomeCommand().setExceptionHandler((command, registeredCommand, sender, args, t) -> {
sender.sendMessage("An error occured. This problem has been logged. Sorry for the inconvienence.");
return true; // mark as handeled, default message will not be send to sender
}));
commandManager.registerCommand(new SomeCommand_ExtraSubs());
commandManager.setDefaultExceptionHandler((command, registeredCommand, sender, args, t) -> {
getLogger().warning("Error occured while executing command " + command.getName());
return false; // mark as unhandeled, sender will see default message
});
}
public static ACFExample getPlugin() {