Add adventure-based exception handlers to cloud-minecraft-extras

This commit is contained in:
Alexander Söderberg 2020-10-09 15:07:41 +02:00
parent 423b29ee3c
commit 4368305bc9
No known key found for this signature in database
GPG key ID: FACEA5B0F4C1BF80
2 changed files with 255 additions and 0 deletions

View file

@ -26,6 +26,7 @@ package cloud.commandframework.examples.bukkit;
import cloud.commandframework.Command;
import cloud.commandframework.CommandTree;
import cloud.commandframework.Description;
import cloud.commandframework.MinecraftExceptionHandler;
import cloud.commandframework.MinecraftHelp;
import cloud.commandframework.annotations.AnnotationParser;
import cloud.commandframework.annotations.Argument;
@ -179,6 +180,23 @@ public final class ExamplePlugin extends JavaPlugin {
/* Mapper for command meta instances */ commandMetaFunction
);
//
// Override the default exception handlers
//
new MinecraftExceptionHandler<CommandSender>()
.withInvalidSyntaxHandler()
.withInvalidSenderHandler()
.withNoPermissionHandler()
.withArgumentParsingHandler()
.withDecorator(
component -> Component.text().append(
Component.text("[", NamedTextColor.DARK_GRAY)
).append(
Component.text("Example", NamedTextColor.GOLD)
).append(
Component.text("] ", NamedTextColor.DARK_GRAY)
).append(component).build()
).apply(manager, bukkitAudiences::sender);
//
// Create the commands
//
this.constructCommands();