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

Commit e17fbd3

Browse files
committed
Add arg flag and join arguments
1 parent 361561e commit e17fbd3

File tree

9 files changed

+168
-51
lines changed

9 files changed

+168
-51
lines changed
Binary file not shown.
Binary file not shown.

Writerside/litecommands.tree

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88

99
<toc-element topic="Introdution.md">
1010
<toc-element topic="Dependency.md"/>
11-
<toc-element topic="Configuration.md"/>
1211
</toc-element>
1312
<toc-element topic="Platforms.md">
1413
<toc-element topic="SENDER.md"/>
1514
</toc-element>
15+
<toc-element topic="Configuration.md"/>
1616
<toc-element topic="Command.md"/>
1717
<toc-element topic="Arguments.md">
18+
<toc-element topic="Arg.md"/>
19+
<toc-element topic="Flag.md"/>
20+
<toc-element topic="Join-Argument.md"/>
1821
<toc-element topic="Supported-Types.md"/>
1922
<toc-element topic="Unsupported-Types-TODO.md"/>
2023
<toc-element topic="Custom-Types.md"/>

Writerside/topics/Arg.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# @Arg Argument
2+
3+
The `@Arg` annotation in the LiteCommands framework is used to define command method
4+
parameters that represent required arguments. Arguments are essential pieces of information
5+
that the user must provide when invoking a command. The `@Arg` annotation helps structure
6+
and validate these inputs within the command method.
7+
8+
## Usage
9+
10+
The `@Arg` annotation is applied to parameters within a command method that represent
11+
required arguments. Here is an example of how to use the `@Arg` annotation:
12+
13+
`/give <player> <type> <amount>`
14+
15+
```java
16+
@Command(name = "give")
17+
public class GiveCommand {
18+
@Execute
19+
void give(@Arg Player target, @Arg Material type, @Arg int amount) {
20+
// Command implementation
21+
}
22+
}
23+
```
24+
25+
In this example:
26+
27+
- `@Arg Player` target represents a required argument for a player.
28+
- `@Arg Item` item represents a required argument for an item.
29+
- `@Arg int` amount represents a required argument for an integer value.
30+
31+
## Example
32+
33+
Let's consider the following command usage:
34+
35+
```
36+
/give JohnDoe diamond 3
37+
```
38+
39+
In this case, the `target` parameter will represent the player "JohnDoe,"
40+
the `item` parameter will represent the material DIAMOND,
41+
and the `amount` parameter will represent the integer value 3.
42+
43+
<video src="../images/argument/arg/giveCommandExample.mp4" controls/>

Writerside/topics/Arguments.md

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,8 @@
11
# Argument
22

3-
Arguments are used to get the values from the command sender.
3+
Arguments are used to parse the command sender's input and complete the command.
44

5-
## @Arg Argument
65

7-
`@Arg` is the most common argument. It is used to get the value from the command sender.
8-
9-
```java
10-
@Command(name = "ban")
11-
public class BanCommand {
12-
@Execute
13-
public void ban(@Arg Player player) {
14-
// ...
15-
}
16-
}
17-
```
18-
19-
## @Flag Argument
20-
21-
`@Flag` is used to get the value from the command sender, but it is optional.
22-
23-
```java
24-
@Command(name = "ban")
25-
public class BanCommand {
26-
@Execute
27-
public void ban(@Flag("-s") boolean isSilent) {
28-
// ...
29-
}
30-
}
31-
```
32-
33-
## @Join Argument
34-
35-
`@Join` is used to get the value from the command sender, it joins all arguments into one string.
36-
37-
```java
38-
@Command(name = "ban")
39-
public class BanCommand {
40-
@Execute
41-
public void ban(@Join String reason) {
42-
// ...
43-
}
44-
}
45-
```
466

477
Sometimes you may want to limit the number of arguments that will be joined.
488
```java

Writerside/topics/Command.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,46 @@
11
# Command
22

3-
<tldr>
4-
<p>
5-
Annotations <shortcut>@Command</shortcut> <shortcut>@Execute</shortcut>
6-
</p>
7-
</tldr>
8-
93
The command structure is the most important part of the command. It is the structure that determines how the command will be executed.
104

11-
For example, the command `/time day`
5+
For example, the command `/time set day`
126

137
```java
148
@Command(name = "time")
159
public class TimeCommand {
1610

11+
@Execute(name = "set day")
12+
public void day() {
13+
// ... /time set day
14+
}
15+
16+
}
17+
```
18+
19+
You can do the same thing with the other way:
20+
21+
```java
22+
@Command(name = "time set")
23+
public class TimeSetCommand {
24+
1725
@Execute(name = "day")
1826
public void day() {
19-
// ... set time to day
27+
// ... /time set day
2028
}
2129

2230
}
2331
```
32+
33+
It not requires to use the `name` parameter in the `@Execute` annotation.
34+
For example `/day` command:
35+
36+
```java
37+
@Command(name = "day")
38+
public class DayCommand {
39+
40+
@Execute
41+
public void day() {
42+
// ... /day
43+
}
44+
45+
}
46+
```

Writerside/topics/Configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Configuration
1+
# Builder Configuration
22

33
Create a new instance of `LiteCommands` using specific factory for your platform.
44

Writerside/topics/Flag.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# @Flag Argument
2+
3+
The @Flag annotation in the LiteCommands framework is used to define flags for command methods.
4+
Flags are optional parameters that modify the behavior of a command.
5+
They are specified by adding certain keywords or symbols (flags) to the command input.
6+
Flags in LiteCommands provide a convenient way to enable
7+
or disable specific functionalities within a command.
8+
9+
## Usage
10+
11+
The `@Flag` annotation is applied to boolean parameters within a command method.
12+
Here is an example of how to use the `@Flag` annotation:
13+
14+
`/mute <player> -s`
15+
16+
```java
17+
@Command(name = "mute")
18+
public class MuteCommand {
19+
@Execute
20+
public void mute(
21+
@Arg Player player,
22+
@Flag("-s") boolean isSilent
23+
) {
24+
// ..
25+
}
26+
}
27+
```
28+
29+
- `@Flag("-s")` declares a flag with the identifier `-s`.
30+
- `boolean isSilent` is the corresponding parameter that will be set to true if the -s flag is provided in the command input. If the flag is not present, the parameter will be set to false by default.
31+
- The identifier for the flag, typically a string starting with a symbol like `-` or `--`.
32+
33+
Example of command input and the corresponding result:
34+
35+
```
36+
input: /mute Notch
37+
result: isSilent = false
38+
39+
input: /mute Notch -s
40+
result: isSilent = true
41+
```
42+
43+
> The order of flags in the input does matter.
44+
{ style="warning" }
45+
>
46+
<video src="../images/argument/flag/muteCommandExample.mp4" controls/>

Writerside/topics/Join-Argument.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# @Join Argument
2+
3+
The `@Join` annotation in the LiteCommands framework is used to concatenate
4+
multiple arguments into a single string. This annotation is particularly
5+
useful when you want to combine several input parameters into a cohesive
6+
text representation, such as creating a reason for a ban command.
7+
8+
## 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:
12+
13+
```Java
14+
@Command(name = "ban")
15+
public class BanCommand {
16+
@Execute
17+
public void ban(
18+
@Arg Player target,
19+
@Join String reason
20+
) {
21+
// Command implementation
22+
}
23+
}
24+
```
25+
26+
## Example
27+
Let's consider the following command usage:
28+
29+
```
30+
/ban JohnDoe Offensive language and behavior
31+
In this case, the `target` parameter will represent the player "JohnDoe", and the `reason` parameter will represent the string "Offensive language and behavior." The @Join annotation automatically combines all the remaining text arguments into the reason parameter.
32+
```
33+
34+
## Notes
35+
- The `@Join `annotation is particularly useful when you want to capture a variable number of arguments into a single string.
36+
- The joined string includes spaces between the original arguments, making it suitable for textual descriptions or reasons.
37+
38+
## Additional Options
39+
40+
41+
42+
In LiteCommands, the @Join annotation offers additional options for customization, namely limit and separator. The limit option allows developers to specify the maximum number of arguments to include in the joined string, providing control over the length of the concatenated result. On the other hand, the separator option enables developers to define a custom string that separates each joined argument, allowing for fine-grained control over formatting. These options enhance the flexibility of the @Join annotation, allowing developers to tailor the concatenated string output to their specific needs.

0 commit comments

Comments
 (0)