Class Grenadier
Note: When getProvider()
is called for the first time, the
provider will attempt to determine the plugin that loaded it. If a plugin is
found, then it is set as Grenadier's plugin and will be returned in
plugin()
.
If no plugin could be determined then there will be issues. See
plugin()
for why Grenadier requires a plugin
-
Method Summary
Modifier and TypeMethodDescriptionstatic GrenadierCommand
createCommand
(@NotNull String name) Creates a grenadier command builderstatic CommandSource
createSource
(CommandSender sender) Creates a command source for the specifiedsender
static CommandSource
createSource
(CommandSender sender, GrenadierCommandNode node) Creates a command source for the specifiedsender
and then callsCommandSource.setCurrentNode(GrenadierCommandNode)
with the specifiednode
static CommandDispatcher<CommandSource>
Gets the command dispatcher.static void
ensureValidLabel
(String label) Ensures a specified commandlabel
is valid.static ExceptionProvider
Gets the exception factorystatic String
Gets the command fallback prefix, this is prepended onto command labels to prevent commands from overriding eachother.static Component
fromMessage
(Message message) Converts a Brigadier message to a component.static GrenadierProvider
Gets or creates the grenadier providerstatic Plugin
plugin()
Gets the plugin using grenadier.static void
Sets the plugin using grenadierstatic SuggestionProvider<CommandSource>
Gets a suggestion provider that suggests all commands currently registered on the server.static Message
Converts the adventure component to a message.
-
Method Details
-
getProvider
Gets or creates the grenadier provider- Returns:
- Grenadier API
-
dispatcher
Gets the command dispatcher.This dispatcher has a restriction on the nodes registered into it, only command nodes created by
GrenadierCommand
instances can be registered into this dispatcher. More specifically, onlyGrenadierCommandNode
s can be registered into this dispatcher- Returns:
- Grenadier dispatcher
-
plugin
Gets the plugin using grenadier.If the grenadier singleton was created by a plugin class loader, then this will return the plugin that loaded the Grenadier class.
A plugin is required to register an internal event listener that ensures clients that connect to the server receive correct command trees, otherwise the default bukkit command tree is sent to clients. The difference between the two is mostly in the color of the text typed in chat.
Secondly, the listener also ensures that Grenadier is able to register commands into the same dispatcher that the
/executes
command uses.Thirdly, if no plugin is found, then there is a chance suggestions will not function properly, this is mostly in the case of argument types like
OptionsArgument
that must offset suggestions in a way the base Bukkit system cannot handleIf you're encountering any of the above-mentioned issues, place the following in your plugin's
onEnable
method@Override public void onEnable() { Grenadier.plugin(this); }
- Returns:
- Grenadier plugin,
null
, if no plugin is set
-
plugin
Sets the plugin using grenadier- Parameters:
plugin
- Plugin- See Also:
-
exceptions
Gets the exception factoryMost, if not all, exceptions created by the returned factory are translatable
- Returns:
- Exception factory
-
createSource
Creates a command source for the specifiedsender
- Parameters:
sender
- Sender to wrap- Returns:
- Created source
-
createSource
Creates a command source for the specifiedsender
and then callsCommandSource.setCurrentNode(GrenadierCommandNode)
with the specifiednode
- Parameters:
sender
- Sender to wrapnode
- Current command node- Returns:
- Created source
-
fromMessage
Converts a Brigadier message to a component.This is preferable to using
Message.getString()
because the vanilla implementation of the chat component system also implementsMessage
. So the supplied message may be aLiteralMessage
or a vanilla component.- Parameters:
message
- Message to convert- Returns:
- Component
-
toMessage
Converts the adventure component to a message.Internally this turns the Adventure API chat component to a vanilla chat component
- Parameters:
component
- Component to convert- Returns:
- Message
-
fallbackPrefix
Gets the command fallback prefix, this is prepended onto command labels to prevent commands from overriding eachother.Example:
Without prefix: command_label With prefix: fallback:command_label
- Returns:
- Grenadier fallback prefix
-
suggestAllCommands
Gets a suggestion provider that suggests all commands currently registered on the server.The returned suggestion provider not only suggests command labels, but also gets suggestions specific to each command
- Returns:
- suggestion provider
-
createCommand
Creates a grenadier command builder- Parameters:
name
- Name of the command- Returns:
- Created command
-
ensureValidLabel
public static void ensureValidLabel(String label) throws IllegalArgumentException, NullPointerException Ensures a specified commandlabel
is valid. For a command label to be valid it must be non-null and not empty- Parameters:
label
- Label to test- Throws:
IllegalArgumentException
- If the label was empty, or blankNullPointerException
- If the label was null
-