Class CalculatorCommand
java.lang.Object
io.github.projectunified.craftcommand.example.standalone.CalculatorCommand
Comprehensive example command demonstrating all CraftCommand features.
Features demonstrated:
Commandwith name, aliases, descriptionDefaultaction methodCommandon methods and nested classesDefaultparameters with default valuesGreedyparameters (String and non-String types)Nameparameter name overrideSuggestfor tab completion (field and method)Resolvefor custom parameter resolution (implicit and explicit)Min,Maxvalidation annotationsValidateWithcustom validation- Nested subcommand classes
Resolvefrom inner class referencing outer class method- Multiple sender types
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassNested subcommand class demonstrating class-level subcommands.static classstatic enumstatic classclassNested subcommand class demonstratingResolvereferencing a resolver method defined in the outer class. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoiddefaultAndGreedy(Object sender, String greeting, String text) voidvoidDemonstrates @Greedy on String (joins remaining args with spaces).voidenumOp(Object sender, CalculatorCommand.MathOp op, int num1, int num2) Demonstrates enum parameter resolution (via registerProvider in CLIApp).voidDefault action: addition of two numbers.Method-based suggestion provider with current input.voidgreedyResolve(Object sender, String text) voidgreedyResolveWithPrefix(Object sender, String prefix, String text) voidvoidnamedResolver(Object sender, CalculatorCommand.Point pt) voidDemonstrates @Greedy on non-String type (joins remaining args, then parses).voidDemonstrates @Default with default value on String.voidDemonstrates @Default with default value on int.voidresolveAndDefault(Object sender, CalculatorCommand.Point pt, String mode) voidresolveAndSuggest(Object sender, CalculatorCommand.Point pt, String mode) voidresolveAndValidate(Object sender, CalculatorCommand.Point pt, int level) intresolveClamped(int value) resolveGreedy(String text) resolvePoint(double x, double y) Local resolver for Point type (multi-arg, width=2).resolvePointNamed(double x, double y) resolvePointSuggest(String mode, double x) resolvePointWithSender(Object sender, double x, double y) resolveSender(Object sender) Local resolver for CustomSender type.voidDemonstrates method-based @Suggest with sender, args, current parameters.voidDemonstrates field-based @Suggest for operator selection.voidrunPoint(Object sender, CalculatorCommand.Point pt) Demonstrates parameter-level @Resolve with named method.voidsameSender(Object sender, CalculatorCommand.Point pt) voidsendMessage(Object sender, String target, String message) Demonstrates @Name to override parameter name in usage messages.voidsetCoordinate(Object sender, double x, double y, double z) Demonstrates @ValidateWith with custom validation method.voidDemonstrates @Min and @Max validation on numeric types.voidvoidsuggestAndDefault(Object sender, String mode, int count) voidsuggestResolver(Object sender, CalculatorCommand.Point pt) voidDemonstrates @Greedy on array type (creates array from remaining args).voidvalidateCoordinate(double value) Validates coordinate is within bounds.voidvalidateDivider(int num) Validates that divisor is not zero.voidwhoAmI(CalculatorCommand.CustomSender sender) Demonstrates sender-level @Resolve.
-
Field Details
-
operators
Field-based suggestion provider for operator names. -
modes
Field-based suggestion provider for mode names.
-
-
Constructor Details
-
CalculatorCommand
public CalculatorCommand()
-
-
Method Details
-
getModes
Method-based suggestion provider with current input.- Parameters:
current- the current input being typed- Returns:
- list of suggested modes
-
resolveSender
Local resolver for CustomSender type. -
resolvePoint
Local resolver for Point type (multi-arg, width=2). -
resolvePointWithSender
-
resolvePointNamed
-
resolvePointSuggest
-
resolveClamped
public int resolveClamped(int value) -
resolveGreedy
-
validateDivider
public void validateDivider(int num) Validates that divisor is not zero. -
validateCoordinate
public void validateCoordinate(double value) Validates coordinate is within bounds. -
execute
Default action: addition of two numbers. Usage: /calc <num1> <num2> -
add
-
subtract
-
multiply
-
divide
-
runOp
Demonstrates field-based @Suggest for operator selection. -
runMode
Demonstrates method-based @Suggest with sender, args, current parameters. -
print
Demonstrates @Default with default value on String. -
repeat
Demonstrates @Default with default value on int. -
echo
Demonstrates @Greedy on String (joins remaining args with spaces). -
parse
Demonstrates @Greedy on non-String type (joins remaining args, then parses). -
sum
Demonstrates @Greedy on array type (creates array from remaining args). -
sendMessage
Demonstrates @Name to override parameter name in usage messages. -
runPoint
Demonstrates parameter-level @Resolve with named method. -
whoAmI
Demonstrates sender-level @Resolve. -
setCoordinate
Demonstrates @ValidateWith with custom validation method. -
setLevel
Demonstrates @Min and @Max validation on numeric types. -
enumOp
Demonstrates enum parameter resolution (via registerProvider in CLIApp). -
resolveAndSuggest
-
resolveAndDefault
-
resolveAndValidate
-
suggestAndDefault
-
defaultAndGreedy
-
sameSender
-
namedResolver
-
suggestResolver
-
clamped
-
greedyResolve
-
greedyResolveWithPrefix
-