refactor ig
This commit is contained in:
parent
ef32f9dbc4
commit
336ac4cad5
54 changed files with 528 additions and 444 deletions
39
README.md
39
README.md
|
|
@ -1,13 +1,16 @@
|
|||
## TODO
|
||||
|
||||
CI/CD to publish automatically
|
||||
|
||||
## Build
|
||||
|
||||
after installing bazel:
|
||||
```shell
|
||||
bazel build //kencommandapi-bukkit:bukkit
|
||||
bazel build //kencommandapi-core:core
|
||||
bazel build //bukkit
|
||||
bazel build //core
|
||||
bazel build //velocity
|
||||
```
|
||||
|
||||
can't compile -velocity module yet.
|
||||
|
||||
## Limitations & Bugs
|
||||
|
||||
- argument's can't require specific permissions.
|
||||
|
|
@ -29,12 +32,12 @@ arguments can have suggestions.
|
|||
To allow the use of `/feed` without giving a user's name, i.e. to make the argument optional, we need to assign the
|
||||
user-argument a default value.
|
||||
|
||||
## An example command
|
||||
### An example command
|
||||
|
||||
Let's say we want to make a command that allows seeing how many coins another User has.
|
||||
If we don't specify a user, it should instead show the coins the sender has.
|
||||
|
||||
## As a tree
|
||||
### As a tree
|
||||
|
||||
Visualized as a tree, we have a Node/Literal `coins` with an alias `balance` with an optional argument called `user`.
|
||||
To make an argument optional, it must have a default value.
|
||||
|
|
@ -45,38 +48,42 @@ literal:coins/balance
|
|||
- has executor:getCoins
|
||||
```
|
||||
|
||||
## As code
|
||||
### As code
|
||||
|
||||
```java
|
||||
import de.kentoj.kencommandapi.api.literal.RootLiteral;
|
||||
|
||||
/**
|
||||
* Show the amount coins a user has.
|
||||
* If no user is given, it should show the amount the sender of the command has.
|
||||
*/
|
||||
@NoArgsConstructor(access = AccessLevel.NONE)
|
||||
public class CoinsCommand {
|
||||
|
||||
@Getter
|
||||
private final Literal<User> rootLiteral;
|
||||
private final RootLiteral<User> rootLiteral;
|
||||
private final CommandArgumentSpec<User, User> userArg;
|
||||
|
||||
public CoinsCommand() {
|
||||
userArg = CommandArgumentSpec.builder("user", new UserArgumentType<User>())
|
||||
.withRequirement(p -> !p.hasPermission("economy.immune.getcoins"),
|
||||
"you can't see that player's balance")
|
||||
.withDefaultValue(CommandContext::getSender)
|
||||
.withDefaultValue(CommandContext::sender)
|
||||
.build();
|
||||
rootLiteral = Literal.<User>builder("coins", "balance")
|
||||
.withStyle(MessageStyle.PLAIN)
|
||||
.withPermission("economy.command.coins")
|
||||
.withArgument(userArg)
|
||||
.withSyncExecutor(this::getCoins)
|
||||
.build();
|
||||
.asRootLiteral(MessageStyle.PLAIN);
|
||||
}
|
||||
|
||||
private Result<Object, String> getCoins(CommandContext<User> ctx) {
|
||||
var player = ctx.getArg(userArg);
|
||||
ctx.getSender().sendMessage(player.getName() + " has " + player.getCoins() + " coins");
|
||||
var user = ctx.getArg(userArg);
|
||||
ctx.getSender().sendMessage(user.name() + " has " + user.coins() + " coins");
|
||||
return Results.success(new Object());
|
||||
}
|
||||
|
||||
public RootLiteral<User> rootLiteral() {
|
||||
return rootLiteral;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
|
@ -87,5 +94,5 @@ Additionally, we can also a Requirement in the CommandArgumentSpec.
|
|||
The registration of the command is platform-dependant. Typically, a class called CommandAPI can be used.
|
||||
```java
|
||||
CommandAPI api = new CommandAPI();
|
||||
register(new CoinsCommand().getRootLiteral());
|
||||
register(new CoinsCommand().rootLiteral());
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue