mirror of
https://github.com/aikar/commands.git
synced 2026-06-02 15:22:17 +00:00
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:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user