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

Commit 636bed6

Browse files
committed
Update arguments topics.
1 parent 7bf2bef commit 636bed6

File tree

8 files changed

+148
-59
lines changed

8 files changed

+148
-59
lines changed

Writerside/litecommands.tree

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
<toc-element topic="Platforms.md">
1313
<toc-element topic="SENDER.md"/>
1414
</toc-element>
15-
<toc-element topic="Features.md">
16-
<toc-element topic="Arguments.md">
17-
</toc-element>
18-
</toc-element>
1915
<toc-element topic="Command-Structure.md"/>
16+
<toc-element topic="Arguments.md">
17+
<toc-element topic="Supported-Types.md"/>
18+
<toc-element topic="Unsupported-Types-TODO.md"/>
19+
<toc-element topic="Custom-Types.md"/>
20+
</toc-element>
2021
<toc-element topic="Adventure-Kyori.md">
2122
<toc-element topic="adventure.md"/>
2223
<toc-element topic="adventure-platform.md"/>

Writerside/redirection-rules.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@
3030
<description>Created after removal of "Programmatic Argument" from LiteCommands</description>
3131
<accepts>Programmatic-Argument.html</accepts>
3232
</rule>
33+
<rule id="2fe346aa">
34+
<description>Created after removal of "| III | Command Str" from LiteCommands</description>
35+
<accepts>Features.html</accepts>
36+
</rule>
3337
</rules>

Writerside/topics/Arguments.md

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,67 @@
11
# Argument
22

3-
Argument is a value that is passed to the command.
4-
For example, you can use the `String` object as an argument in your command:
3+
Arguments are used to get the values from the command sender.
54

6-
<tabs>
7-
<tab title="Annotation">
5+
## @Arg Argument
6+
7+
`@Arg` is the most common argument. It is used to get the value from the command sender.
88

99
```java
10-
@Command(name = "say")
11-
public class SayCommand {
10+
@Command(name = "ban")
11+
public class BanCommand {
1212
@Execute
13-
public void ban(@Arg String text) {
13+
public void ban(@Arg Player player) {
1414
// ...
1515
}
1616
}
1717
```
18-
</tab>
19-
<tab title="Programmatically">
18+
19+
## @Flag Argument
20+
21+
`@Flag` is used to get the value from the command sender, but it is optional.
2022

2123
```java
22-
new LiteCommand<CommandSender>("say")
23-
.argument("text", String.class)
24-
.onExecute(context -> {
25-
String text = context.argument("text", String.class);
24+
@Command(name = "ban")
25+
public class BanCommand {
26+
@Execute
27+
public void ban(@Flag("-s") boolean isSilent) {
2628
// ...
27-
})
29+
}
30+
}
2831
```
29-
</tab>
3032

31-
<tab title="Programmatic (class)">
33+
## @Join Argument
3234

33-
```java
34-
public class SayCommand extends LiteCommand<CommandSender> {
35-
public SayCommand() {
36-
super("say");
37-
argument("text", String.class);
38-
}
35+
`@Join` is used to get the value from the command sender, it joins all arguments into one string.
3936

40-
@Override
41-
public void execute(Context<CommandSender> context) {
42-
String text = context.argument("text", String.class);
37+
```java
38+
@Command(name = "ban")
39+
public class BanCommand {
40+
@Execute
41+
public void ban(@Join String reason) {
4342
// ...
4443
}
4544
}
4645
```
47-
</tab>
48-
</tabs>
4946

50-
LiteCommands supports multiple argument types. You can find all of them in the table below.
47+
Sometimes you may want to limit the number of arguments that will be joined.
48+
```java
49+
@Join(limit = 2)
50+
```
5151

52-
| Argument Type | Values | Platforms |
53-
|---------------|------------------------------------------------|-----------|
54-
| `Boolean` | `true`, `false` | * |
55-
| `Byte` | `-128` - `127` | * |
56-
| `Short` | `-32768` - `32767` | * |
57-
| `Integer` | `-2147483648` - `2147483647` | * |
58-
| `Long` | `-9223372036854775808` - `9223372036854775807` | * |
59-
| `Float` | `0.0` - `3.4028235E38` | * |
60-
| `Double` | `0.0` - `1.7976931348623157E308` | * |
61-
| `String` | Any string | * |
62-
| `Enum` | Any enum | * |
63-
| `Duration` | 1d, 1h, 1m, 1s, 1ms | * |
64-
| `Period` | 1y, 1mo, 1w, 1d | * |
65-
| `Instant` | yyyy-MM-dd HH:mm:ss | * |
66-
| `Component` | Any string | Adventure |
67-
| `Component` | Any string | Adventure |
68-
| `Player` | Any player | Bukkit |
69-
| `World` | Any world | Bukkit |
70-
| `Location` | Any location | Bukkit |
71-
| `Player` | Any player | Minestom |
52+
Or you may want to join arguments with a different separator.
53+
```java
54+
@Join(separator = ", ")
55+
```
7256

73-
// TODO: Add more argument types
74-
| `UUID` | Any UUID | All |
75-
| `Color` | Any color | All |
76-
| `Enchantment` | Any enchantment | All |
77-
| `ChatColor` | Any chat color | All |
57+
## Full Example
7858

59+
```java
60+
@Command(name = "ban")
61+
public class BanCommand {
62+
@Execute
63+
public void ban(@Arg Player player, @Flag("-s") boolean isSilent, @Join String reason) {
64+
// ...
65+
}
66+
}
67+
```

Writerside/topics/Command-Structure.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,36 @@
22

33
<tldr>
44
<p>
5-
Annotations <shortcut>@Command</shortcut> <shortcut>@RootCommand</shortcut> <shortcut>@Execute</shortcut>
5+
Annotations <shortcut>@Command</shortcut> <shortcut>@Execute</shortcut>
66
</p>
77
</tldr>
88

99
The command structure is the most important part of the command. It is the structure that determines how the command will be executed.
1010

11+
For example, the command structure of the `/ban` command is:
12+
13+
```java
14+
@Command(name = "ban")
15+
public class BanCommand {
16+
17+
@Execute
18+
void ban() {
19+
// ...
20+
}
21+
22+
}
23+
```
24+
25+
For the `/ban ip` command, the structure is:
26+
27+
```java
28+
@Command(name = "ban")
29+
public class BanCommand {
30+
31+
@Execute(name = "ip")
32+
void banIp() {
33+
// ...
34+
}
35+
36+
}
37+
```

Writerside/topics/Custom-Types.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Custom Types
2+
3+
You can create your own argument types! It's very simple and easy.
4+
5+
To create a custom type, you need to create a class that extends the `ArgumentResolver`!
6+
7+
```java
8+
public class PlotResolver extends ArgumentResolver<SENDER, Plot> {
9+
10+
private final PlotManager plotManager;
11+
12+
public PlotResolver(PlotManager plotManager) {
13+
this.plotManager = plotManager;
14+
}
15+
16+
@Override
17+
protected ParseResult<Plot> parse(Invocation<SENDER> invocation, Argument<String> context, String argument) {
18+
Plot plot = this.plotManager.getPlot(argument);
19+
20+
if (plot == null) {
21+
return ParseResult.failure("Plot not found!");
22+
}
23+
24+
return ParseResult.success(plot);
25+
}
26+
27+
@Override
28+
public SuggestionResult suggest(Invocation<SENDER> invocation, Argument<String> argument, SuggestionContext context) {
29+
return this.plotManager.getPlots().stream()
30+
.map(plot -> plot.getName())
31+
.collect(SuggestionResult.collector());
32+
}
33+
34+
}
35+
```

Writerside/topics/Features.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

Writerside/topics/Supported-Types.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Supported Types
2+
3+
LiteCommands supports multiple argument types. You can find all of them in the table below.
4+
5+
| Argument Type | Values | Platforms |
6+
|---------------|------------------------------------------------|-----------|
7+
| `Boolean` | `true`, `false` | * |
8+
| `Byte` | `-128` - `127` | * |
9+
| `Short` | `-32768` - `32767` | * |
10+
| `Integer` | `-2147483648` - `2147483647` | * |
11+
| `Long` | `-9223372036854775808` - `9223372036854775807` | * |
12+
| `Float` | `0.0` - `3.4028235E38` | * |
13+
| `Double` | `0.0` - `1.7976931348623157E308` | * |
14+
| `String` | Any string | * |
15+
| `Enum` | Any enum | * |
16+
| `Duration` | 1d, 1h, 1m, 1s, 1ms | * |
17+
| `Period` | 1y, 1mo, 1w, 1d | * |
18+
| `Instant` | yyyy-MM-dd HH:mm:ss | * |
19+
| `Component` | Any string | Adventure |
20+
| `Component` | Any string | Adventure |
21+
| `Player` | Any player | Bukkit |
22+
| `World` | Any world | Bukkit |
23+
| `Location` | Any location | Bukkit |
24+
| `Player` | Any player | Minestom |
25+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Unsupported Types (TODO)
2+
3+
| Argument Type | Values | Platforms |
4+
|-----------------|------------------------------------------------|-----------|
5+
| `UUID` | Any UUID | All |
6+
| `Color` | Any color | Bukkit |
7+
| `Enchantment` | Any enchantment | Bukkit |
8+
| `ChatColor` | Any chat color | Bukkit |
9+

0 commit comments

Comments
 (0)