Class CommandBuilder
java.lang.Object
me.tayebyassine.homestead.commands.CommandBuilder
- All Implemented Interfaces:
org.bukkit.command.CommandExecutor, org.bukkit.command.TabCompleter
- Direct Known Subclasses:
ClaimCommand, ForceUnclaimCommand, HomesteadAdminCommand, RegionCommand, UnclaimCommand
public abstract class CommandBuilder
extends Object
implements org.bukkit.command.CommandExecutor, org.bukkit.command.TabCompleter
Base class for every top-level Bukkit command.
A command may hold any number of sub-commands. When no sub-command is
matched, execution falls back to onDefaultExecution(CommandSender, String[]).
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCommandBuilder(String name) Creates a command without aliases.CommandBuilder(String name, String... aliases) Creates a command with the given aliases. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.bukkit.entity.PlayerasPlayer(org.bukkit.command.CommandSender sender) Casts the sender to aPlayerwhen possible.String[]Gets a human-readable description of allowed executors.protected Collection<SubCommandBuilder> getName()protected SubCommandBuildergetSubCommand(String name) Resolves a sub-command by name or alias.getUsage()booleanhasPermission(org.bukkit.command.CommandSender sender) Checks whether the sender holds every required permission.booleanisAllowedCommandSender(org.bukkit.command.CommandSender sender) Checks if the given sender is allowed to execute this command.booleanbooleanfinal booleanonCommand(org.bukkit.command.CommandSender sender, org.bukkit.command.Command cmd, String label, String[] args) abstract booleanonDefaultExecution(org.bukkit.command.CommandSender sender, String[] args) Executes the command when no (matching) sub-command is provided.onDefaultTabComplete(org.bukkit.command.CommandSender sender, String[] args) Provides tab-completion suggestions for the default execution of this command.onTabComplete(org.bukkit.command.CommandSender sender, org.bukkit.command.Command cmd, String alias, String[] args) protected voidregisterSubCommand(SubCommandBuilder subCommand) Registers a sub-command, together with all of its aliases, on this command.setAllowedCommandSenders(CommandSenderType... types) Sets the allowed executor types for this command.Restricts this command to the console only.setPermission(String permission) Replaces the permission list with a single permission.setPermission(List<String> permissions) Replaces the permission list.Restricts this command to players only.Sets the usage string shown to the player.
-
Field Details
-
plugin
-
-
Constructor Details
-
CommandBuilder
Creates a command without aliases.- Parameters:
name- the command name, as declared inplugin.yml
-
CommandBuilder
-
-
Method Details
-
registerSubCommand
Registers a sub-command, together with all of its aliases, on this command.- Parameters:
subCommand- the sub-command to register
-
getSubCommand
Resolves a sub-command by name or alias.- Parameters:
name- the sub-command name or alias- Returns:
- the matching sub-command, or
nullif none match
-
getAllSubCommands
- Returns:
- a de-duplicated view of all registered sub-commands
-
getSubCommandNames
-
setPermission
Replaces the permission list with a single permission.- Parameters:
permission- the required permission- Returns:
- this command, for chaining
-
setPermission
Replaces the permission list. All permissions must be held by the sender.- Parameters:
permissions- the required permissions- Returns:
- this command, for chaining
-
setAllowedCommandSenders
Sets the allowed executor types for this command.- Parameters:
types- the allowed executor types- Returns:
- this command, for chaining
-
setPlayerOnly
Restricts this command to players only.- Returns:
- this command, for chaining
-
setConsoleOnly
Restricts this command to the console only.- Returns:
- this command, for chaining
-
hasPermission
public boolean hasPermission(org.bukkit.command.CommandSender sender) Checks whether the sender holds every required permission.- Parameters:
sender- the command sender- Returns:
trueif no permissions are required or the sender holds all of them
-
onDefaultExecution
Executes the command when no (matching) sub-command is provided.- Parameters:
sender- the command senderargs- the full command arguments- Returns:
trueto signal that the command was handled
-
onDefaultTabComplete
-
isAllowedCommandSender
public boolean isAllowedCommandSender(org.bukkit.command.CommandSender sender) Checks if the given sender is allowed to execute this command.- Parameters:
sender- the command sender- Returns:
trueif the sender type is allowed
-
getAllowedCommandSenderDescription
Gets a human-readable description of allowed executors.- Returns:
- description string
-
onCommand
-
onTabComplete
-
getName
- Returns:
- the command name
-
getAliases
- Returns:
- the command aliases
-
getUsage
- Returns:
- the command usage string
-
setUsage
Sets the usage string shown to the player.- Parameters:
usage- the usage string- Returns:
- this command, for chaining
-
getPermissions
-
isPlayerOnly
public boolean isPlayerOnly()- Returns:
trueif this command is restricted to players only
-
isConsoleOnly
public boolean isConsoleOnly()- Returns:
trueif this command is restricted to the console only
-
getallowedCommandSenders
- Returns:
- an unmodifiable view of the allowed executor types
-
asPlayer
protected org.bukkit.entity.Player asPlayer(org.bukkit.command.CommandSender sender) Casts the sender to aPlayerwhen possible.- Parameters:
sender- the command sender- Returns:
- the player, or
nullif the sender is not a player
-