Add command argument preprocessors

This commit is contained in:
Alexander Söderberg 2020-10-10 01:24:16 +02:00
parent fcd269b6e7
commit 1f3c3f2bd9
No known key found for this signature in database
GPG key ID: FACEA5B0F4C1BF80
9 changed files with 405 additions and 17 deletions

View file

@ -35,6 +35,7 @@ import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import cloud.commandframework.annotations.Confirmation;
import cloud.commandframework.annotations.Flag;
import cloud.commandframework.annotations.Regex;
import cloud.commandframework.annotations.specifier.Greedy;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.arguments.parser.ArgumentParseResult;
@ -440,4 +441,16 @@ public final class ExamplePlugin extends JavaPlugin {
player.sendMessage(ChatColor.GREEN + String.format("You have been given %d x %s", number, material));
}
@CommandMethod("example pay <money>")
@CommandDescription("Command to test the preprocessing system")
private void commandPay(
final @NonNull CommandSender sender,
final @Argument("money") @Regex("(?=.*?\\d)^\\$?(([1-9]\\d{0,2}(,\\d{3})*)|\\d+)?(\\.\\d{1,2})?$") String money
) {
bukkitAudiences.sender(sender).sendMessage(
Component.text().append(Component.text("You have been given ", NamedTextColor.AQUA))
.append(Component.text(money, NamedTextColor.GOLD))
);
}
}