CommandAPI 9.7.0
An API for the command UI introduced in Minecraft 1.13
com.mojang.brigadier.exceptions.CommandSyntaxException Class Reference

An exception for a syntax error that occurred while parsing or executing a command. More...

+ Inheritance diagram for com.mojang.brigadier.exceptions.CommandSyntaxException:

Public Member Functions

 CommandSyntaxException (final CommandExceptionType type, final Message message)
 Creates a new CommandSyntaxException of a given type and with a given message. More...
 
 CommandSyntaxException (final CommandExceptionType type, final Message message, final String input, final int cursor)
 Creates a new CommandSyntaxException of a given type and message together with the input and cursor position. More...
 
String getMessage ()
 Returns the message together with the position it occurred on and some context. More...
 
Message getRawMessage ()
 Returns the raw message, not including positional information. More...
 
String getContext ()
 Returns some contextual information about where the error occurred. More...
 
CommandExceptionType getType ()
 Returns the type of the exception. More...
 
String getInput ()
 Returns the input that caused the CommandSyntaxException. More...
 
int getCursor ()
 Returns the cursor position. More...
 

Static Public Attributes

static final int CONTEXT_AMOUNT = 10
 The amount of characters from the input that should be displayed in the getContext().
 
static boolean ENABLE_COMMAND_STACK_TRACES = true
 Enables suppression as defined in Exception#Exception(String, Throwable, boolean, boolean), i.e. More...
 
static BuiltInExceptionProvider BUILT_IN_EXCEPTIONS = new BuiltInExceptions()
 

Detailed Description

An exception for a syntax error that occurred while parsing or executing a command.

TODO: Why is this named syntax exception, when it can also occur when executing a command?

Constructor & Destructor Documentation

◆ CommandSyntaxException() [1/2]

com.mojang.brigadier.exceptions.CommandSyntaxException.CommandSyntaxException ( final CommandExceptionType  type,
final Message  message 
)

Creates a new CommandSyntaxException of a given type and with a given message.

Parameters
typethe type of the exception
messagethe message

◆ CommandSyntaxException() [2/2]

com.mojang.brigadier.exceptions.CommandSyntaxException.CommandSyntaxException ( final CommandExceptionType  type,
final Message  message,
final String  input,
final int  cursor 
)

Creates a new CommandSyntaxException of a given type and message together with the input and cursor position.

Parameters
typethe type of the exception
messagethe message
inputthe input that caused the exception
cursorthe cursor position the exception occurred on

Member Function Documentation

◆ getContext()

String com.mojang.brigadier.exceptions.CommandSyntaxException.getContext ( )

Returns some contextual information about where the error occurred.

This is done by returning a few characters ({@value CONTEXT_AMOUNT}) of the faulty getInput() and a pointer to where the exception happened.

Returns
some contextual information about where the error occurred or null if getInput() or getCursor() are null/0.

◆ getCursor()

int com.mojang.brigadier.exceptions.CommandSyntaxException.getCursor ( )

Returns the cursor position.

Returns
the cursor position or -1 if not set

◆ getInput()

String com.mojang.brigadier.exceptions.CommandSyntaxException.getInput ( )

Returns the input that caused the CommandSyntaxException.

Returns
the input that caused the CommandSyntaxException or null if not set

◆ getMessage()

String com.mojang.brigadier.exceptions.CommandSyntaxException.getMessage ( )

Returns the message together with the position it occurred on and some context.

Returns
the message together with the position it occurred on and some context

◆ getRawMessage()

Message com.mojang.brigadier.exceptions.CommandSyntaxException.getRawMessage ( )

Returns the raw message, not including positional information.

Returns
the raw message without any formatting or positional information

◆ getType()

CommandExceptionType com.mojang.brigadier.exceptions.CommandSyntaxException.getType ( )

Returns the type of the exception.

Returns
the type of the exception

Member Data Documentation

◆ ENABLE_COMMAND_STACK_TRACES

boolean com.mojang.brigadier.exceptions.CommandSyntaxException.ENABLE_COMMAND_STACK_TRACES = true
static

Enables suppression as defined in Exception#Exception(String, Throwable, boolean, boolean), i.e.

whether to ignore calls to Exception#addSuppressed(Throwable). Additionally it is also used as the second boolean in the constructor mentioned above, i.e. specifies whether the stack trace is writable.

See also
Exception::fillInStackTrace()
Exception::addSuppressed(Throwable)