Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Commit 4e0c247

Browse files
committed
Add jakarta extension. Add optional arguments.
1 parent dd217ec commit 4e0c247

17 files changed

+220
-66
lines changed

Writerside/litecommands.tree

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
start-page="Introdution.md">
88

99
<toc-element topic="Introdution.md">
10-
<toc-element topic="Dependency.md"/>
1110
</toc-element>
11+
<toc-element topic="Dependency.md"/>
1212
<toc-element topic="Platforms.md">
1313
<toc-element topic="SENDER.md"/>
1414
</toc-element>
@@ -18,10 +18,18 @@
1818
<toc-element topic="Arg.md"/>
1919
<toc-element topic="Flag.md"/>
2020
<toc-element topic="Join-Argument.md"/>
21-
<toc-element topic="Supported-Types.md"/>
22-
<toc-element topic="Unsupported-Types-TODO.md"/>
21+
<toc-element topic="Optional-Argument.md">
22+
<toc-element topic="optionalarg-null-way.md"/>
23+
<toc-element topic="optional-argument-optional-way.md"/>
24+
</toc-element>
25+
<toc-element topic="Supported-Types.md">
26+
<toc-element topic="Supported-Types-Bukkit.md"/>
27+
<toc-element topic="Supported-Types-Adventure.md"/>
28+
<toc-element topic="Supported-Types-Minestom.md"/>
29+
</toc-element>
2330
<toc-element topic="Custom-Types.md"/>
2431
</toc-element>
32+
<toc-element topic="Jakarta-Extension.md"/>
2533
<toc-element topic="Adventure-Kyori.md">
2634
<toc-element topic="adventure.md"/>
2735
<toc-element topic="adventure-platform.md"/>

Writerside/redirection-rules.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,16 @@
3838
<description>Created after removal of "Configuration - Bukkit" from LiteCommands</description>
3939
<accepts>Configuration-Bukkit.html</accepts>
4040
</rule>
41+
<rule id="1f5cb281">
42+
<description>Created after removal of "Unsupported Types (TODO)" from LiteCommands</description>
43+
<accepts>Unsupported-Types-TODO.html</accepts>
44+
</rule>
45+
<rule id="13f277f2">
46+
<description>Created after removal of "@OptionalArg Argument" from LiteCommands</description>
47+
<accepts>OptionalArg-Argument.html</accepts>
48+
</rule>
49+
<rule id="c9b898c">
50+
<description>Created after removal of "Optional Argument" from LiteCommands</description>
51+
<accepts>Optional-Argument.html</accepts>
52+
</rule>
4153
</rules>

Writerside/topics/Arguments.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ Arguments are used to parse the command sender's input and complete the command.
44

55

66

7-
Sometimes you may want to limit the number of arguments that will be joined.
8-
```java
9-
@Join(limit = 2)
10-
```
117

12-
Or you may want to join arguments with a different separator.
13-
```java
14-
@Join(separator = ", ")
15-
```
168

179
## Full Example
1810

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Jakarta Extension
2+
3+
The `litecommands-jakarta` is a extension for supporting Jakarta EE annotation validation.
4+
5+
```Java
6+
@Execute
7+
void ban(@Arg @Pattern(regexp = "[a-zA-Z_]+") String name)
8+
```
9+
10+
## Dependency
11+
Add the following dependency to your project:
12+
13+
<tabs>
14+
<tab title="Gradle KTS">
15+
16+
```kotlin
17+
implementation("dev.rollczi:litecommands-adventure:%latest_version%")
18+
```
19+
</tab>
20+
<tab title="Maven">
21+
22+
```xml
23+
<dependency>
24+
<groupId>dev.rollczi</groupId>
25+
<artifactId>litecommands-jakarta</artifactId>
26+
<version>%latest_version%</version>
27+
</dependency>
28+
```
29+
</tab>
30+
</tabs>
31+
32+
33+
## Registering the extension
34+
35+
Register the extension in the `LiteCommands` builder:
36+
37+
```java
38+
.extension(new LiteJakartaExtension<>())
39+
```
40+
41+
## Example
42+
43+
```Java
44+
@Command(name = "ban")
45+
public class BanCommand {
46+
47+
@Execute
48+
void ban(
49+
@Arg @Pattern(regexp = "[a-zA-Z_]+") String name,
50+
@Arg @Future Instant date,
51+
) {
52+
// Command implementation
53+
}
54+
55+
}
56+
```
57+
58+
See documentation for [Jakarta EE Bean Validation](https://jakarta.ee/specifications/bean-validation/3.0/apidocs/jakarta/validation/constraints/package-summary) to learn more about validation annotations.
59+
60+
## Handling validation errors
61+
62+
If the validation fails, then the handler for `JakartaResult` will be called.
63+
64+
```Java
65+
public class JakartaResultHandler implements ResultHandler<SENDER, JakartaResult> {
66+
67+
@Override
68+
public void handle(Invocation<SENDER> invocation, JakartaResult result, ResultHandlerChain<SENDER> chain) {
69+
for (ConstraintViolation<Object> violation : result.getViolations()) {
70+
String message = violation.getMessage();
71+
String messageKey = violation.getMessageTemplate();
72+
73+
// ... (send message to the sender)
74+
}
75+
}
76+
77+
}
78+
```
79+
80+
And register it in the `LiteCommands` builder:
81+
82+
```Java
83+
.result(new JakartaResultHandler())
84+
```

Writerside/topics/Join-Argument.md

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ useful when you want to combine several input parameters into a cohesive
66
text representation, such as creating a reason for a ban command.
77

88
## Usage
9-
The `@Join` annotation is applied to a parameter within a command method
10-
that should be treated as a concatenated string. Here is an example of
11-
how to use the `@Join` annotation:
9+
Here is an example of how to use the `@Join` annotation:
1210

1311
```Java
1412
@Command(name = "ban")
@@ -23,26 +21,26 @@ public class BanCommand {
2321
}
2422
```
2523

26-
## Example
2724
Let's consider the following command usage:
2825

2926
```
30-
/ban JohnDoe Offensive language and behavior
31-
target = JohnDoe
32-
reason = Offensive language and behavior
27+
input: /ban JohnDoe Offensive language and behavior
28+
reason: Offensive language and behavior
3329
```
3430

35-
## Notes
36-
- The `@Join` annotation is particularly useful when you want to capture a variable number of arguments into a single string.
37-
- The joined string includes spaces between the original arguments, making it suitable for textual descriptions or reasons.
38-
3931
## Additional Options
4032

33+
Sometimes you may want to limit the number of arguments that will be joined.
34+
```java
35+
@Join(limit = 2)
36+
```
37+
38+
Or you may want to join arguments with a different separator.
39+
```java
40+
@Join(separator = ", ")
41+
```
4142

42-
- The `limit` option allows developers to specify the
43-
maximum number of arguments to include in the joined string.
44-
- On the other hand, the `separator` option enables developers to define a custom string that separates each joined
45-
argument, allowing for fine-grained control over formatting.
43+
Or both:
4644

4745
```java
4846
@Command(name = "ban")
@@ -61,6 +59,5 @@ Let's consider the following command usage:
6159

6260
```
6361
/ban JohnDoe Offensive language and behavior
64-
target = JohnDoe
65-
reason = Offensive-language-and-behavior
62+
reason: Offensive-language-and-behavior
6663
```
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Optional Argument
2+
3+
The **Optional Argument** in the LiteCommands framework is used to define optional
4+
parameters within command methods. Optional arguments are parameters that may or may
5+
not be provided by the user when invoking a command.
6+
7+
There are two ways to define optional arguments in LiteCommands:
8+
9+
- [@Arg Optional&lt;T&gt; optional](optionalarg-null-way.md)
10+
- [@OptionalArg T optional](optional-argument-optional-way.md)

Writerside/topics/Platforms.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,3 @@ LiteCommands supports multiple platforms and extensions for them. You can find a
99
| `litecommands-bungeecord` | BungeeCord, Waterfall | 1.20-R0.1 |
1010
| `litecommands-minestom` | Minestom | 1.20.2 |
1111
| `litecommands-jda` | JDA | 5.0.0-beta.15 |
12-
13-
14-
15-
<tabs>
16-
17-
</tabs>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Supported Types Adventure
2+
3+
| Argument Type | Values | Example |
4+
|---------------|------------|---------|
5+
| `Component` | Any string | `text` |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Supported Types Bukkit
2+
3+
| Argument Type | Values | Example |
4+
|---------------|------------------------------------------------|------------------------------------------|
5+
| `Player` | Any player | `Rollczi` |
6+
| `World` | Any world | `world`, `world_nether`, `world_the_end` |
7+
| `Location` | Any location | `10 100 20`, `~ ~ ~`, `~ 100 ~` |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Supported Types Minestom
2+
3+
| Argument Type | Values | Example |
4+
|---------------|------------|-----------|
5+
| `Player` | Any player | `Rollczi` |

0 commit comments

Comments
 (0)