Class MinecraftExceptionHandler<C>
java.lang.Object
org.incendo.cloud.minecraft.extras.MinecraftExceptionHandler<C>
- Type Parameters:
C- command sender type
Creates and registers
ExceptionHandlers that send a Component to the
command sender.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceConverts Throwables to ComponentMessageThrowables when possible.static final classDefault implementation and holder forMinecraftExceptionHandler.ComponentMessageThrowableConverter.static interfacestatic interface -
Method Summary
Modifier and TypeMethodDescriptioncaptionFormatter(@NonNull ComponentCaptionFormatter<C> captionFormatter) Sets the caption formatter that is responsible for turningcaptionsinto Adventurecomponents.static <C> MinecraftExceptionHandler<C> create(AudienceProvider<C> audienceProvider) Create a newMinecraftExceptionHandlerusingaudienceProvider.The defaultArgumentParseExceptionhandler.The defaultCommandExecutionExceptionhandler, usingcreateDefaultCommandExecutionLogger().createDefaultCommandExecutionHandler(Consumer<ExceptionContext<C, CommandExecutionException>> logger) The defaultCommandExecutionExceptionhandler, with a specific logger.static <C> Consumer<ExceptionContext<C, CommandExecutionException>> Default logger forcreateDefaultCommandExecutionHandler(Consumer), usingThrowable.printStackTrace()on theCommandExecutionException's cause.The defaultInvalidCommandSenderExceptionhandler.The defaultInvalidSyntaxExceptionhandler.The defaultNoPermissionExceptionhandler.static <C extends Audience>
MinecraftExceptionHandler<C> Create a newMinecraftExceptionHandlerusingAudienceProvider.nativeAudience().Sets the decorator that acts on a component before it's sent to the sender.decorator(@NonNull MinecraftExceptionHandler.Decorator<C> decorator) Sets the decorator that acts on a component before it's sent to the sender.Use the defaultArgumentParseExceptionhandler.Use the defaultCommandExecutionExceptionhandler withcreateDefaultCommandExecutionLogger().defaultCommandExecutionHandler(@NonNull Consumer<ExceptionContext<C, CommandExecutionException>> logger) Use the defaultCommandExecutionExceptionhandler with a custom logger.Use all the default exception handlers.Use the defaultInvalidCommandSenderExceptionhandler.Use the defaultInvalidSyntaxExceptionhandler.Use the defaultNoPermissionExceptionhandler.<T extends Throwable>
@NonNull MinecraftExceptionHandler<C> handler(@NonNull Class<T> type, @NonNull MinecraftExceptionHandler.MessageFactory<C, T> componentFactory) Sets the exception handler for the giventype.voidregisterTo(@NonNull CommandManager<C> manager) Registers configured handlers to theExceptionController.
-
Method Details
-
createDefaultInvalidSyntaxHandler
@API(status=STABLE, since="2.0.0") public static <C> MinecraftExceptionHandler.MessageFactory<C,InvalidSyntaxException> createDefaultInvalidSyntaxHandler()The defaultInvalidSyntaxExceptionhandler.- Type Parameters:
C- sender type- Returns:
InvalidSyntaxExceptionhandler function- Since:
- 2.0.0
- See Also:
-
createDefaultInvalidSenderHandler
@API(status=STABLE, since="2.0.0") public static <C> MinecraftExceptionHandler.MessageFactory<C,InvalidCommandSenderException> createDefaultInvalidSenderHandler()The defaultInvalidCommandSenderExceptionhandler.- Type Parameters:
C- sender type- Returns:
InvalidCommandSenderExceptionhandler function- Since:
- 2.0.0
- See Also:
-
createDefaultNoPermissionHandler
@API(status=STABLE, since="2.0.0") public static <C> MinecraftExceptionHandler.MessageFactory<C,NoPermissionException> createDefaultNoPermissionHandler()The defaultNoPermissionExceptionhandler.- Type Parameters:
C- sender type- Returns:
NoPermissionExceptionhandler function- Since:
- 2.0.0
- See Also:
-
createDefaultArgumentParsingHandler
@API(status=STABLE, since="2.0.0") public static <C> MinecraftExceptionHandler.MessageFactory<C,ArgumentParseException> createDefaultArgumentParsingHandler()The defaultArgumentParseExceptionhandler.- Type Parameters:
C- sender type- Returns:
ArgumentParseExceptionhandler function- Since:
- 2.0.0
- See Also:
-
createDefaultCommandExecutionLogger
@API(status=STABLE, since="2.0.0") public static <C> Consumer<ExceptionContext<C,CommandExecutionException>> createDefaultCommandExecutionLogger()Default logger forcreateDefaultCommandExecutionHandler(Consumer), usingThrowable.printStackTrace()on theCommandExecutionException's cause.- Type Parameters:
C- sender type- Returns:
- default logger
- Since:
- 2.0.0
-
createDefaultCommandExecutionHandler
@API(status=STABLE, since="2.0.0") public static <C> MinecraftExceptionHandler.MessageFactory<C,CommandExecutionException> createDefaultCommandExecutionHandler()The defaultCommandExecutionExceptionhandler, usingcreateDefaultCommandExecutionLogger().- Type Parameters:
C- sender type- Returns:
CommandExecutionExceptionhandler function- Since:
- 2.0.0
- See Also:
-
createDefaultCommandExecutionHandler
@API(status=STABLE, since="2.0.0") public static <C> MinecraftExceptionHandler.MessageFactory<C,CommandExecutionException> createDefaultCommandExecutionHandler(Consumer<ExceptionContext<C, CommandExecutionException>> logger) The defaultCommandExecutionExceptionhandler, with a specific logger.- Type Parameters:
C- sender type- Parameters:
logger- logger- Returns:
CommandExecutionExceptionhandler function- Since:
- 2.0.0
- See Also:
-
create
@API(status=STABLE, since="2.0.0") public static <C> MinecraftExceptionHandler<C> create(AudienceProvider<C> audienceProvider) Create a newMinecraftExceptionHandlerusingaudienceProvider.- Type Parameters:
C- sender type- Parameters:
audienceProvider- audience provider- Returns:
- new
MinecraftExceptionHandler - Since:
- 2.0.0
-
createNative
@API(status=STABLE, since="2.0.0") public static <C extends Audience> MinecraftExceptionHandler<C> createNative()Create a newMinecraftExceptionHandlerusingAudienceProvider.nativeAudience().- Type Parameters:
C- sender type- Returns:
- new
MinecraftExceptionHandler - Since:
- 2.0.0
-
defaultInvalidSyntaxHandler
@API(status=STABLE, since="2.0.0") public @NonNull MinecraftExceptionHandler<C> defaultInvalidSyntaxHandler()Use the defaultInvalidSyntaxExceptionhandler.- Returns:
this- Since:
- 2.0.0
-
defaultInvalidSenderHandler
@API(status=STABLE, since="2.0.0") public @NonNull MinecraftExceptionHandler<C> defaultInvalidSenderHandler()Use the defaultInvalidCommandSenderExceptionhandler.- Returns:
this- Since:
- 2.0.0
-
defaultNoPermissionHandler
@API(status=STABLE, since="2.0.0") public @NonNull MinecraftExceptionHandler<C> defaultNoPermissionHandler()Use the defaultNoPermissionExceptionhandler.- Returns:
this- Since:
- 2.0.0
-
defaultArgumentParsingHandler
@API(status=STABLE, since="2.0.0") public @NonNull MinecraftExceptionHandler<C> defaultArgumentParsingHandler()Use the defaultArgumentParseExceptionhandler.- Returns:
this- Since:
- 2.0.0
-
defaultCommandExecutionHandler
@API(status=STABLE, since="2.0.0") public @NonNull MinecraftExceptionHandler<C> defaultCommandExecutionHandler()Use the defaultCommandExecutionExceptionhandler withcreateDefaultCommandExecutionLogger().- Returns:
this- Since:
- 2.0.0
- See Also:
-
defaultCommandExecutionHandler
@API(status=STABLE, since="2.0.0") public @NonNull MinecraftExceptionHandler<C> defaultCommandExecutionHandler(@NonNull Consumer<ExceptionContext<C, CommandExecutionException>> logger) Use the defaultCommandExecutionExceptionhandler with a custom logger.- Parameters:
logger- logger- Returns:
this- Since:
- 2.0.0
-
defaultHandlers
Use all the default exception handlers.- Returns:
this- Since:
- 2.0.0
- See Also:
-
handler
@API(status=STABLE, since="2.0.0") public <T extends Throwable> @NonNull MinecraftExceptionHandler<C> handler(@NonNull Class<T> type, @NonNull MinecraftExceptionHandler.MessageFactory<C, T> componentFactory) Sets the exception handler for the giventype. A handler can returnnullto indicate no message should be sent.- Type Parameters:
T- exception type- Parameters:
type- the exception type to handlecomponentFactory- the factory that produces the components- Returns:
this- Since:
- 2.0.0
-
decorator
@API(status=STABLE, since="2.0.0") public @NonNull MinecraftExceptionHandler<C> decorator(@NonNull MinecraftExceptionHandler.Decorator<C> decorator) Sets the decorator that acts on a component before it's sent to the sender.- Parameters:
decorator- the component decorator- Returns:
this- Since:
- 2.0.0
-
captionFormatter
public @NonNull MinecraftExceptionHandler<C> captionFormatter(@NonNull ComponentCaptionFormatter<C> captionFormatter) Sets the caption formatter that is responsible for turningcaptionsinto Adventurecomponents.- Parameters:
captionFormatter- caption formatter- Returns:
this
-
decorator
@API(status=STABLE, since="2.0.0") public @NonNull MinecraftExceptionHandler<C> decorator(@NonNull Function<@NonNull Component, @NonNull ComponentLike> decorator) Sets the decorator that acts on a component before it's sent to the sender.- Parameters:
decorator- the component decorator- Returns:
this- Since:
- 2.0.0
-
registerTo
Registers configured handlers to theExceptionController.- Parameters:
manager- the manager instance- Since:
- 2.0.0
-