Interface CommandProcessor
public interface CommandProcessor
process(CommandSender, String, String[])
is called no matter what if a CommandSender
sends a command which
start by getCommandName()
or any of the aliases in getAliases()
Tab-completion can be activated by overriding enableWritingTracking()
and return true, you should then listen to
onWrite(String)
and return the possible completions to suggest.
Please be sure to check Command
as it is likely to be better for your use case.
-
Method Summary
Modifier and Type Method Description default boolean
enableWritingTracking()
Needed to enableonWrite(String)
callback.java.lang.String[]
getAliases()
Gets the command's aliases.java.lang.String
getCommandName()
Gets the main command's name.boolean
hasAccess(Player player)
Called to know if a player has access to the command.default java.lang.String[]
onWrite(java.lang.String text)
Allows for tab auto completion, this is called everytime the player press a key in the chat.boolean
process(CommandSender sender, java.lang.String command, java.lang.String[] args)
Called when the command is executed by aCommandSender
-
Method Details
-
getCommandName
@NotNull java.lang.String getCommandName()Gets the main command's name.- Returns:
- the main command's name
-
getAliases
@Nullable java.lang.String[] getAliases()Gets the command's aliases.Can be null or empty.
- Returns:
- the command aliases
-
process
boolean process(@NotNull CommandSender sender, @NotNull java.lang.String command, @NotNull java.lang.String[] args)Called when the command is executed by aCommandSender
- Parameters:
sender
- the sender which executed the commandcommand
- the command name usedargs
- an array containing all the args (split by space char)- Returns:
- true when the command is successful, false otherwise
-
hasAccess
Called to know if a player has access to the command.Right now it is only used to know if the player should see the command in auto-completion Conditions still need to be checked in
process(CommandSender, String, String[])
.- Parameters:
player
- the player to check the access- Returns:
- true if the player has access to the command, false otherwise
-
enableWritingTracking
default boolean enableWritingTracking()Needed to enableonWrite(String)
callback.Be aware that enabling it can cost some performance because of how often it will be called.
- Returns:
- true to enable writing tracking (and server auto completion)
- See Also:
onWrite(String)
-
onWrite
@Nullable default java.lang.String[] onWrite(@NotNull java.lang.String text)Allows for tab auto completion, this is called everytime the player press a key in the chat.WARNING:
enableWritingTracking()
needs to return true, you need to override it by default.- Parameters:
text
- the whole player text- Returns:
- the array containing all the suggestion for the current arg (split " "), can be null
- See Also:
enableWritingTracking()
-