Package dev.oumaimaa.kawaiiapi.command
Class SubCommand
java.lang.Object
dev.oumaimaa.kawaiiapi.command.SubCommand
Abstract base class for subcommands within a core command structure.
Example: In /chunkcollector buy, "buy" would be the subcommand.
Subcommands should be lightweight, stateless, and thread-safe. Each subcommand is instantiated once per command registration.
- Version:
- 1.0
- Author:
- KawaiiDevelopment
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the aliases that can be used for this subcommand.@NotNull StringGets the message to display when asking for confirmation.longGets the cooldown time for this subcommand in milliseconds.abstract @NotNull StringGets a description of what this subcommand does.intGets the maximum number of arguments allowed (excluding the subcommand name).intGets the minimum number of arguments required (excluding the subcommand name).abstract @NotNull StringgetName()Gets the name of this subcommand.@Nullable StringGets the permission node required to use this subcommand.getSubcommandArguments(@NotNull org.bukkit.command.CommandSender sender, @NotNull String[] args) Provides tab completion suggestions for this subcommand's arguments.abstract @NotNull StringGets the syntax/usage example for this subcommand.protected booleanhasPermission(@NotNull org.bukkit.command.CommandSender sender, @NotNull String permission) Utility method to check if sender has a specific permission.booleanChecks if this subcommand can only be executed by players.abstract voidExecutes the subcommand logic.booleanChecks if this subcommand requires confirmation before execution.protected voidUtility method to send an error message with standard formatting.protected voidsendMessage(@NotNull org.bukkit.command.CommandSender sender, @NotNull String message) Utility method to send a colored message to the sender.protected voidsendSuccess(@NotNull org.bukkit.command.CommandSender sender, @NotNull String success) Utility method to send a success message with standard formatting.protected voidsendUsage(@NotNull org.bukkit.command.CommandSender sender) Utility method to send the usage/syntax message.protected voidsendWarning(@NotNull org.bukkit.command.CommandSender sender, @NotNull String warning) Utility method to send a warning message with standard formatting.protected booleanCalled before perform() to validate the command execution.
-
Constructor Details
-
SubCommand
public SubCommand()
-
-
Method Details
-
getName
Gets the name of this subcommand. Must be lowercase and contain no spaces.- Returns:
- The subcommand name (case-insensitive during matching)
-
getAliases
-
getDescription
Gets a description of what this subcommand does. Displayed in the default command list.- Returns:
- A user-friendly description
-
getSyntax
Gets the syntax/usage example for this subcommand. Should include the full command path and argument placeholders.- Returns:
- Usage example (e.g., "/command subcommand <arg> [optional]")
-
perform
public abstract void perform(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String[] args) Executes the subcommand logic. Called on the main server thread.- Parameters:
sender- The entity that executed the command (Player, Console, etc.)args- The command arguments (includes the subcommand name at index 0)
-
getSubcommandArguments
@Nullable public abstract @Nullable List<String> getSubcommandArguments(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String[] args) Provides tab completion suggestions for this subcommand's arguments. Called asynchronously for tab completion.- Parameters:
sender- The entity requesting tab completionargs- The current command arguments- Returns:
- List of suggestions for tab completion, or null for no suggestions
-
getPermission
Gets the permission node required to use this subcommand. If null or empty, no permission is required.- Returns:
- The permission node, or null for no permission requirement
-
isPlayerOnly
public boolean isPlayerOnly()Checks if this subcommand can only be executed by players. Override to return true if console/command blocks should be blocked.- Returns:
- true if player-only, false to allow all senders
-
getMinimumArguments
public int getMinimumArguments()Gets the minimum number of arguments required (excluding the subcommand name). Override to enable automatic argument count validation.- Returns:
- Minimum argument count, or 0 for no minimum
-
getMaximumArguments
public int getMaximumArguments()Gets the maximum number of arguments allowed (excluding the subcommand name). Override to enable automatic argument count validation.- Returns:
- Maximum argument count, or -1 for unlimited
-
validate
protected boolean validate(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String[] args) Called before perform() to validate the command execution. Override to add custom validation logic.- Parameters:
sender- The command senderargs- The command arguments- Returns:
- true if validation passed, false to cancel execution
-
getCooldown
public long getCooldown()Gets the cooldown time for this subcommand in milliseconds. Override to implement per-subcommand cooldowns.- Returns:
- Cooldown time in milliseconds, or 0 for no cooldown
-
requiresConfirmation
public boolean requiresConfirmation()Checks if this subcommand requires confirmation before execution. Useful for destructive operations.- Returns:
- true if confirmation is required
-
getConfirmationMessage
Gets the message to display when asking for confirmation. Only used if requiresConfirmation() returns true.- Returns:
- The confirmation message
-
hasPermission
protected boolean hasPermission(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String permission) Utility method to check if sender has a specific permission.- Parameters:
sender- The command senderpermission- The permission to check- Returns:
- true if sender has permission
-
sendMessage
protected void sendMessage(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String message) Utility method to send a colored message to the sender.- Parameters:
sender- The message recipientmessage- The message with color codes
-
sendError
protected void sendError(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String error) Utility method to send an error message with standard formatting.- Parameters:
sender- The message recipienterror- The error message
-
sendSuccess
protected void sendSuccess(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String success) Utility method to send a success message with standard formatting.- Parameters:
sender- The message recipientsuccess- The success message
-
sendWarning
protected void sendWarning(@NotNull @NotNull org.bukkit.command.CommandSender sender, @NotNull @NotNull String warning) Utility method to send a warning message with standard formatting.- Parameters:
sender- The message recipientwarning- The warning message
-
sendUsage
protected void sendUsage(@NotNull @NotNull org.bukkit.command.CommandSender sender) Utility method to send the usage/syntax message.- Parameters:
sender- The message recipient
-