Messages - adamtomi/grapefruit GitHub Wiki
Quick Note
If you're ok with the default messages and don't plan on adding custom parameter resolvers (which is unlikely to be honest), you can skip to the next page.
Builtin Messages
Grapefruit currently has the following messages:
Constant | Key | Variable(s) |
---|---|---|
CONDITION_FAILED |
condition.failed |
{id} |
AUTHORIZATION_ERROR |
dispatcher.authorization-error |
{permission} |
FAILED_TO_EXECUTE_COMMAND |
dispatcher.failed-to-execute-command |
{commandline} |
NO_SUCH_COMMAND |
dispatcher.no-such-command |
{name} |
TOO_FEW_ARGUMENTS |
dispatcher.too-few-arguments |
{syntax} |
TOO_MANY_ARGUMENTS |
dispatcher.too-many-arguments |
{syntax} |
ILLEGAL_COMMAND_SOURCE |
dispatcher.illegal-command-source |
{found} , {required} |
INVALID_BOOLEAN_VALUE |
parameter.invalid-boolean-value |
{input} , {options} |
INVALID_CHARACTER_VALUE |
parameter.invalid-character-value |
{input} |
INVALID_NUMBER_VALUE |
parameter.invalid-number-value |
{input} |
NUMBER_OUT_OF_RANGE |
parameter.number-out-of-range |
{min} , {max} |
QUOTED_STRING_INVALID_TRAILING_CHARATER |
parameter.quoted-string-invalid-trailing-character |
{input} |
STRING_REGEX_ERROR |
parameter.string-regex-error |
{input} , {regex} |
MISSING_FLAG_VALUE |
parameter.missing-flag-value |
{input} |
MISSING_FLAG |
parameter.missing-flag |
{syntax} |
DUPLICATE_FLAG |
parameter.duplicate-flag |
{flag} |
UNRECOGNIZED_COMMAND_FLAG |
parameter.unrecognized-command-flag |
{input} |
Customizing Messages
If you are looking to customize these messages, you will need to create a custom MessageProvider
.
public class MyMessageProvider implements MessageProvider {
@Override
public @NotNull String provide(final @NotNull MessageKey key) {
final String messageKey = key.key();
return runLogicToRetrieveMessage(messageKey);
}
}
This way you can store your messages in a file for instance. Now all you need is to register your message provider when building the command dispatcher:
final CommandDispatcher<CommandSource> dispatcher = CommandDispatcher.builder(TypeToken.of(CommandSource.class))
.withMessageProvider(new MyMessageProvider())
.build();
Creating Custom Messages
The only scenario where you would need to create custom messages is if you're adding custom parameter resolvers (more on that here). Creating a MessageKey
is as simple as it gets. It's recommended to make it constant to make sure that you can access it easily whe(n|r)ever you need it.
public final class MyMessageKeys {
public static final MessageKey CUSTOM_MESSAGE_KEY = MessageKey.of("my.custom.message-key");
private MyMessageKeys() {}
}
Please note that custom message keys aren't supported by the default message provider, so you'll need to write your own implementation.