Class MinecraftExceptionHandler<C>

java.lang.Object
cloud.commandframework.minecraft.extras.MinecraftExceptionHandler<C>
Type Parameters:
C - Command sender type

public final class MinecraftExceptionHandler<C> extends Object
Exception handler that sends Component to the sender. All component builders can be overridden and the handled exception types can be configured (see MinecraftExceptionHandler.ExceptionType for types)
  • Field Details

    • DEFAULT_INVALID_SYNTAX_FUNCTION

      public static final Function<Exception,​net.kyori.adventure.text.Component> DEFAULT_INVALID_SYNTAX_FUNCTION
      Default component builder for InvalidSyntaxException
    • DEFAULT_INVALID_SENDER_FUNCTION

      public static final Function<Exception,​net.kyori.adventure.text.Component> DEFAULT_INVALID_SENDER_FUNCTION
      Default component builder for InvalidCommandSenderException
    • DEFAULT_NO_PERMISSION_FUNCTION

      public static final Function<Exception,​net.kyori.adventure.text.Component> DEFAULT_NO_PERMISSION_FUNCTION
      Default component builder for NoPermissionException
    • DEFAULT_ARGUMENT_PARSING_FUNCTION

      public static final Function<Exception,​net.kyori.adventure.text.Component> DEFAULT_ARGUMENT_PARSING_FUNCTION
      Default component builder for ArgumentParseException
    • DEFAULT_COMMAND_EXECUTION_FUNCTION

      public static final Function<Exception,​net.kyori.adventure.text.Component> DEFAULT_COMMAND_EXECUTION_FUNCTION
      Default component builder for CommandExecutionException
      Since:
      1.2.0
  • Constructor Details

    • MinecraftExceptionHandler

      public MinecraftExceptionHandler()
  • Method Details

    • withInvalidSyntaxHandler

      public @NonNull MinecraftExceptionHandler<C> withInvalidSyntaxHandler()
      Use the default invalid syntax handler
      Returns:
      this
    • withInvalidSenderHandler

      public @NonNull MinecraftExceptionHandler<C> withInvalidSenderHandler()
      Use the default invalid sender handler
      Returns:
      this
    • withNoPermissionHandler

      public @NonNull MinecraftExceptionHandler<C> withNoPermissionHandler()
      Use the default no permission handler
      Returns:
      this
    • withArgumentParsingHandler

      public @NonNull MinecraftExceptionHandler<C> withArgumentParsingHandler()
      Use the default argument parsing handler
      Returns:
      this
    • withCommandExecutionHandler

      public @NonNull MinecraftExceptionHandler<C> withCommandExecutionHandler()
      Use the default CommandExecutionException handler
      Returns:
      this
      Since:
      1.2.0
    • withDefaultHandlers

      public @NonNull MinecraftExceptionHandler<C> withDefaultHandlers()
      Use all of the default exception handlers
      Returns:
      this
    • withHandler

      public @NonNull MinecraftExceptionHandler<C> withHandler(@NonNull MinecraftExceptionHandler.ExceptionType type, @NonNull Function<@NonNull Exception,​@NonNull net.kyori.adventure.text.Component> componentBuilder)
      Specify an exception handler
      Parameters:
      type - Exception type
      componentBuilder - Component builder
      Returns:
      this
    • withHandler

      public @NonNull MinecraftExceptionHandler<C> withHandler(@NonNull MinecraftExceptionHandler.ExceptionType type, @NonNull BiFunction<@NonNull C,​@NonNull Exception,​@NonNull net.kyori.adventure.text.Component> componentBuilder)
      Specify an exception handler
      Parameters:
      type - Exception type
      componentBuilder - Component builder
      Returns:
      this
      Since:
      1.2.0
    • withDecorator

      public @NonNull MinecraftExceptionHandler<C> withDecorator(@NonNull Function<@NonNull net.kyori.adventure.text.Component,​@NonNull net.kyori.adventure.text.Component> decorator)
      Specify a decorator that acts on a component before it's sent to the sender
      Parameters:
      decorator - Component decorator
      Returns:
      this
    • apply

      public void apply(@NonNull cloud.commandframework.CommandManager<C> manager, @NonNull Function<@NonNull C,​@NonNull net.kyori.adventure.audience.Audience> audienceMapper)
      Register the exception handlers in the manager
      Parameters:
      manager - Manager instance
      audienceMapper - Mapper that maps command sender to audience instances