Class CommandManager<S>
java.lang.Object
dev.ua.theroer.magicutils.commands.CommandManager<S>
- Type Parameters:
S- sender type
Manages registration, execution, and tab completion of commands.
-
Constructor Summary
ConstructorsConstructorDescriptionCommandManager(String permissionPrefix, String pluginName, CommandLogger logger, CommandPlatform<S> platform, TypeParserRegistry<S> typeParserRegistry) Constructs a new CommandManager. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanAccessCommand(String name, S sender, @Nullable String targetSubName) Checks if a sender can access the command (base permission or any sub/arg permission).booleancanAccessSubCommandPath(String name, S sender, List<String> pathSegments) Checks whether the sender can access a resolved subcommand path or any executable child under it.@Nullable ResolvedCommandSchemadescribe(MagicCommand command, CommandInfo info) Returns the resolved command schema for a registered command instance.@Nullable ResolvedCommandSchemaReturns the resolved command schema for the provided command label.Executes a command by name.Executes a command asynchronously on the provided executor.executeOrThrow(String name, S sender, List<String> args) Executes a command, optionally bubbling unexpected failures.formatArguments(List<CommandArgument> arguments) Formats argument list for usage display, skipping sender parameters.formatArguments(List<CommandArgument> arguments, boolean forceOptional) Formats argument list for usage display, skipping sender parameters.generateSubCommandUsages(MagicCommand command, CommandInfo info) Generates detailed usage strings for all subcommands.generateUsage(MagicCommand command, CommandInfo info) Generates a usage string for a command based on its structure.getAll()Gets all registered commands.getCommand(String name) Gets a command by name or alias.getCommandInfo(MagicCommand command) Gets stored command info for a registered command instance.getSuggestions(String name, S sender, List<String> args) Gets tab completion suggestions for a command.booleanisRegistered(String name) Checks if a command is registered.booleanisSenderArgument(CommandArgument argument) Returns true when the argument represents the sender parameter.voidregister(MagicCommand command, CommandInfo info) Registers a command and its info.resolveThreading(String name, List<String> args) Resolves the threading policy for the targeted command action.
-
Constructor Details
-
CommandManager
public CommandManager(String permissionPrefix, String pluginName, CommandLogger logger, CommandPlatform<S> platform, TypeParserRegistry<S> typeParserRegistry) Constructs a new CommandManager.- Parameters:
permissionPrefix- the prefix for permissionspluginName- the plugin name for namespaced commandslogger- command logger implementationplatform- platform adaptertypeParserRegistry- type parser registry
-
-
Method Details
-
register
Registers a command and its info.- Parameters:
command- the command instanceinfo- the command info annotation
-
describe
Returns the resolved command schema for the provided command label.- Parameters:
name- command name, alias, or namespaced label- Returns:
- resolved schema or null when the command is not registered
-
describe
Returns the resolved command schema for a registered command instance.- Parameters:
command- command instanceinfo- resolved command info- Returns:
- immutable resolved schema or null when the command is unknown
-
execute
Executes a command by name.- Parameters:
name- the command namesender- the command senderargs- the command arguments- Returns:
- the result of command execution
-
executeAsync
public CompletableFuture<CommandResult> executeAsync(String name, S sender, List<String> args, Executor executor) Executes a command asynchronously on the provided executor.- Parameters:
name- command namesender- sender handleargs- command argumentsexecutor- executor to run on (uses common pool when null)- Returns:
- future with command result
-
executeOrThrow
public CommandResult executeOrThrow(String name, S sender, List<String> args) throws CommandExecutionException Executes a command, optionally bubbling unexpected failures.- Parameters:
name- command namesender- sender handleargs- command arguments- Returns:
- command result
- Throws:
CommandExecutionException- when execution fails unexpectedly and bubbling is enabled
-
resolveThreading
Resolves the threading policy for the targeted command action.- Parameters:
name- command nameargs- command arguments- Returns:
- resolved threading policy
-
canAccessCommand
Checks if a sender can access the command (base permission or any sub/arg permission).- Parameters:
name- command label or aliassender- sender handletargetSubName- optional first subcommand token (for more accurate checks)- Returns:
- true if accessible
-
canAccessSubCommandPath
Checks whether the sender can access a resolved subcommand path or any executable child under it.- Parameters:
name- command label or aliassender- sender handlepathSegments- path tokens using either canonical names or aliases- Returns:
- true if the path resolves to an accessible node
-
isSenderArgument
Returns true when the argument represents the sender parameter.- Parameters:
argument- command argument- Returns:
- true if sender argument
-
getSuggestions
-
generateUsage
Generates a usage string for a command based on its structure.- Parameters:
command- the command instanceinfo- the command info- Returns:
- formatted usage string
-
generateSubCommandUsages
Generates detailed usage strings for all subcommands.- Parameters:
command- the command instanceinfo- the command info- Returns:
- list of usage strings for each subcommand
-
formatArguments
Formats argument list for usage display, skipping sender parameters.- Parameters:
arguments- arguments to format- Returns:
- formatted argument string without leading/trailing spaces
-
formatArguments
Formats argument list for usage display, skipping sender parameters.- Parameters:
arguments- arguments to formatforceOptional- whether to force all arguments to be optional- Returns:
- formatted argument string without leading/trailing spaces
-
isRegistered
Checks if a command is registered.- Parameters:
name- the command name- Returns:
- true if registered
-
getAll
Gets all registered commands.- Returns:
- a collection of MagicCommand
-
getCommandInfo
Gets stored command info for a registered command instance.- Parameters:
command- command instance- Returns:
- command info or null
-
getCommand
Gets a command by name or alias.- Parameters:
name- command name- Returns:
- command instance or null
-