Skip to content

Commit dc991b2

Browse files
committed
refactor for a simpler annotation set
1 parent f8c100e commit dc991b2

48 files changed

Lines changed: 1048 additions & 1283 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
# CraftCommand
22

3-
An opinionated annotation-driven command framework for Java applications.
4-
5-
## Difference from other frameworks
6-
7-
The only difference is that while others rely on runtime reflection to fetch and handle annotations,
8-
this framework constructs the native code with annotation processor and JavaPoet,
9-
allows near native speed with minimal reflection usage.
3+
Compile-time command framework for Java. Generates platform-specific wrappers via annotation processing — no runtime
4+
reflection for execution.
105

116
## Installation
127

13-
It is recommended to import `craftcommand-bom` in your `<dependencyManagement>` section to manage version configurations of CraftCommand modules:
8+
Use the BOM for version management:
149

1510
```xml
1611
<dependencyManagement>
@@ -26,7 +21,7 @@ It is recommended to import `craftcommand-bom` in your `<dependencyManagement>`
2621
</dependencyManagement>
2722
```
2823

29-
Then, add the annotation and runtime dependency to your `pom.xml` without specifying a version:
24+
Add annotations + runtime + processor:
3025

3126
```xml
3227
<dependency>
@@ -39,8 +34,6 @@ Then, add the annotation and runtime dependency to your `pom.xml` without specif
3934
</dependency>
4035
```
4136

42-
And configure the annotation processor in your compiler plugin:
43-
4437
```xml
4538
<plugin>
4639
<groupId>org.apache.maven.plugins</groupId>
@@ -57,51 +50,44 @@ And configure the annotation processor in your compiler plugin:
5750
</plugin>
5851
```
5952

60-
## Quick Start (Standalone Console App)
61-
62-
### 1. Define your Command Class
53+
## Quick Start
6354

6455
```java
65-
package myapp;
66-
67-
import io.github.projectunified.craftcommand.annotation.*;
68-
69-
@Command(value = "calc", description = "Simple Calculator Command")
56+
@Command("calc")
7057
public class CalculatorCommand {
7158

7259
@Default
73-
public void defaultAction(Object sender) {
74-
System.out.println("Use /calc add <num1> <num2>");
60+
public void execute(Object sender) {
61+
System.out.println("Use /calc add <a> <b>");
7562
}
7663

77-
@Subcommand(value = "add", aliases = {"sum"})
78-
public void add(Object sender,
79-
@Min(value = 0, message = "Inputs must be positive") double a,
80-
double b) {
64+
@Command(value = "add", aliases = {"sum"})
65+
public void add(Object sender, double a, double b) {
8166
System.out.println("Result: " + (a + b));
8267
}
8368
}
8469
```
8570

86-
### 2. Register & Execute in your App
87-
8871
```java
89-
import io.github.projectunified.craftcommand.standalone.StandaloneCommandManager;
90-
import io.github.projectunified.craftcommand.standalone.StandaloneCommand;
91-
92-
public class Main {
93-
public static void main(String[] args) {
94-
StandaloneCommandManager manager = new StandaloneCommandManager();
95-
96-
// Register the annotated command instance
97-
manager.register(new CalculatorCommand());
98-
99-
// Customizing translation keys/messages in the dictionary
100-
manager.setMessage("validation.min", "Error: %s cannot be less than %s!");
101-
102-
// Execute the command
103-
StandaloneCommand cmd = manager.getCommand("calc");
104-
cmd.execute("sender", new String[]{"add", "5.2", "10.0"}); // Prints: Result: 15.2
105-
}
106-
}
72+
StandaloneCommandManager manager = new StandaloneCommandManager();
73+
manager.register(new CalculatorCommand());
74+
75+
StandaloneCommand cmd = manager.getCommand("calc");
76+
cmd.execute("sender", new String[]{"add", "5", "10"}); // Result: 15.0
10777
```
78+
79+
## Supported Platforms
80+
81+
| Platform | Runtime | Processor |
82+
|-------------------|-----------------------------------|--------------------------------------|
83+
| Bukkit/Spigot | `craftcommand-bukkit-runtime` | `craftcommand-bukkit-processor` |
84+
| Paper (Brigadier) | `craftcommand-paper-runtime` | `craftcommand-paper-processor` |
85+
| Paper (Basic) | `craftcommand-paper-runtime` | `craftcommand-paper-processor-basic` |
86+
| Standalone | `craftcommand-standalone-runtime` | `craftcommand-standalone-processor` |
87+
88+
## Documentation
89+
90+
- [Annotations Reference](docs/annotations.md)
91+
- [Architecture](docs/architecture.md)
92+
- [Processor Flow](docs/processor-flow.md)
93+
- [Platform Tutorials](docs/platform-tutorials.md)

‎annotations/src/main/java/io/github/projectunified/craftcommand/annotation/Command.java‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,27 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Annotation used to define a main command.
10-
* Apply this to a class to mark it as a command entry point.
9+
* Defines a command or subcommand.
10+
*
11+
* <p>On a class: marks it as the main command entry point.
12+
* On a method or nested class: marks it as a subcommand.
1113
*/
12-
@Target(ElementType.TYPE)
14+
@Target({ElementType.TYPE, ElementType.METHOD})
1315
@Retention(RetentionPolicy.CLASS)
1416
public @interface Command {
1517
/**
16-
* The primary name of the command.
17-
*
18-
* @return the command name
18+
* Command or subcommand name.
1919
*/
2020
String value();
2121

2222
/**
23-
* The aliases of the command.
24-
*
25-
* @return the command aliases
23+
* Alternative names for this command.
2624
*/
2725
String[] aliases() default {};
2826

2927
/**
30-
* The description of the command.
31-
*
32-
* @return the command description
28+
* Command description. Prefix with {@code i18n:} for runtime i18n lookup.
29+
* e.g. {@code "Static text"} or {@code "i18n:commands.cmd.desc"}.
3330
*/
3431
String description() default "";
3532
}

‎annotations/src/main/java/io/github/projectunified/craftcommand/annotation/Default.java‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,18 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Annotation used to define the default command action when no subcommands are matched.
10-
* Apply this to a method within a command class.
9+
* Dual-purpose annotation.
10+
*
11+
* <p><b>On methods:</b> Marks the default action when no subcommand matches.
12+
* {@link #value()} must be empty.
13+
*
14+
* <p><b>On parameters:</b> Marks as optional. {@link #value()} is the default value string.
1115
*/
12-
@Target(ElementType.METHOD)
16+
@Target({ElementType.METHOD, ElementType.PARAMETER})
1317
@Retention(RetentionPolicy.CLASS)
1418
public @interface Default {
19+
/**
20+
* Default value string for optional parameters. Empty on methods.
21+
*/
22+
String value() default "";
1523
}

‎annotations/src/main/java/io/github/projectunified/craftcommand/annotation/Greedy.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Annotation indicating that a parameter consumes all remaining command arguments.
10-
* Apply this to the last parameter of a command method.
9+
* Makes a parameter consume all remaining arguments. Must be the last parameter.
1110
*/
1211
@Target(ElementType.PARAMETER)
1312
@Retention(RetentionPolicy.CLASS)

‎annotations/src/main/java/io/github/projectunified/craftcommand/annotation/Name.java‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Annotation used to define a custom name for a command parameter.
10-
* This name will be displayed in command usages and exception messages.
9+
* Overrides the parameter name in usage strings and error messages.
1110
*/
1211
@Target(ElementType.PARAMETER)
1312
@Retention(RetentionPolicy.CLASS)
1413
public @interface Name {
1514
/**
16-
* The custom name of the parameter.
17-
*
18-
* @return the parameter name
15+
* The display name.
1916
*/
2017
String value();
2118
}

‎annotations/src/main/java/io/github/projectunified/craftcommand/annotation/Optional.java‎

Lines changed: 0 additions & 21 deletions
This file was deleted.

‎annotations/src/main/java/io/github/projectunified/craftcommand/annotation/Resolve.java‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Declares a local resolver method inside a command class, or binds a parameter to one.
10-
* When placed on a method, it marks it as a resolver.
11-
* When placed on a parameter, it binds the parameter to a specific resolver by name.
9+
* Binds a parameter to a local resolver method, or marks a method as a resolver.
10+
*
11+
* <p>On a method: declares it as a resolver for its return type.
12+
* On a parameter: binds to a resolver by name (value).
1213
*/
1314
@Target({ElementType.METHOD, ElementType.PARAMETER})
1415
@Retention(RetentionPolicy.CLASS)
1516
public @interface Resolve {
1617
/**
17-
* The name of the resolver.
18-
* If placed on a method, this specifies an optional name to reference this resolver.
19-
* If placed on a parameter, this specifies the name of the resolver method to bind to.
20-
*
21-
* @return the resolver name
18+
* Resolver method name. Optional on methods, required on parameters.
2219
*/
2320
String value() default "";
2421
}

‎annotations/src/main/java/io/github/projectunified/craftcommand/annotation/Subcommand.java‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎annotations/src/main/java/io/github/projectunified/craftcommand/annotation/Suggest.java‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
import java.lang.annotation.Target;
77

88
/**
9-
* Binds a command parameter to a suggestion provider method inside the command class.
10-
* This method is invoked when tab completing arguments for the parameter.
9+
* Binds a parameter to a suggestion provider method in the command class.
1110
*/
1211
@Target(ElementType.PARAMETER)
1312
@Retention(RetentionPolicy.CLASS)
1413
public @interface Suggest {
1514
/**
16-
* The name of the suggestion provider method inside the command class.
17-
*
18-
* @return the suggestion provider method name
15+
* Name of the suggestion provider method.
1916
*/
2017
String value();
2118
}
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
/**
2-
* Annotations used to define commands with CraftCommand.
2+
* Core annotations for defining commands with CraftCommand.
33
*
4-
* <p>Primary annotations:
5-
* <ul>
6-
* <li>{@link io.github.projectunified.craftcommand.annotation.Command} — marks a class as a command</li>
7-
* <li>{@link io.github.projectunified.craftcommand.annotation.Subcommand} — marks a method as a subcommand</li>
8-
* <li>{@link io.github.projectunified.craftcommand.annotation.Default} — marks a method as the default executor</li>
9-
* <li>{@link io.github.projectunified.craftcommand.annotation.Resolve} — marks a method as a parameter resolver</li>
10-
* </ul>
4+
* @see io.github.projectunified.craftcommand.annotation.Command
5+
* @see io.github.projectunified.craftcommand.annotation.Default
6+
* @see io.github.projectunified.craftcommand.annotation.Resolve
117
*/
128
package io.github.projectunified.craftcommand.annotation;

0 commit comments

Comments
 (0)