Merge pull request #43

*  Add a new caption system to allow for the configuration of…

*  Add caption support to all numerical types

* Add more standard pasres to the registry

* Add default messages for captions

*  Improve captions in core

* Add captions for Bukkit

*  Add FactoryDelegatingCaptionRegistry.java
This commit is contained in:
Alexander Söderberg 2020-10-12 18:13:23 +02:00 committed by GitHub
parent 378d57964f
commit 6ab1c8a2e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 1482 additions and 200 deletions

View file

@ -53,6 +53,8 @@ import cloud.commandframework.bukkit.parsers.EnchantmentArgument;
import cloud.commandframework.bukkit.parsers.MaterialArgument;
import cloud.commandframework.bukkit.parsers.WorldArgument;
import cloud.commandframework.bukkit.parsers.selector.SingleEntitySelectorArgument;
import cloud.commandframework.captions.Caption;
import cloud.commandframework.captions.SimpleCaptionRegistry;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
import cloud.commandframework.execution.CommandExecutionCoordinator;
@ -409,6 +411,15 @@ public final class ExamplePlugin extends JavaPlugin {
context.getSender().sendMessage("You wrote: " + StringUtils.join(args, " "));
})
);
/* Register a custom regex caption */
final Caption moneyCaption = Caption.of("regex.money");
if (manager.getCaptionRegistry() instanceof SimpleCaptionRegistry) {
((SimpleCaptionRegistry<CommandSender>) manager.getCaptionRegistry()).registerMessageFactory(
moneyCaption,
(sender, key) -> "'{input}' is not very cash money of you"
);
}
}
@CommandMethod("example help [query]")
@ -466,7 +477,8 @@ public final class ExamplePlugin extends JavaPlugin {
@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
final @Argument("money") @Regex(value = "(?=.*?\\d)^\\$?(([1-9]\\d{0,2}(,\\d{3})*)|\\d+)?(\\.\\d{1,2})?$",
failureCaption = "regex.money") String money
) {
bukkitAudiences.sender(sender).sendMessage(
Component.text().append(Component.text("You have been given ", NamedTextColor.AQUA))