From 5ebb73568e3f711a607c810426a34c8906e9292f Mon Sep 17 00:00:00 2001 From: Flemmli97 Date: Fri, 11 Dec 2020 15:18:24 +0100 Subject: [PATCH] make quoted group names in command possible fix #20 --- .../com/flemmli97/flan/commands/CommandClaim.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/flemmli97/flan/commands/CommandClaim.java b/src/main/java/com/flemmli97/flan/commands/CommandClaim.java index 9cc97fe..58c23a7 100644 --- a/src/main/java/com/flemmli97/flan/commands/CommandClaim.java +++ b/src/main/java/com/flemmli97/flan/commands/CommandClaim.java @@ -41,6 +41,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.CompletableFuture; +import java.util.regex.Pattern; public class CommandClaim { @@ -68,8 +69,8 @@ public class CommandClaim { .then(CommandManager.literal("giveClaimBlocks").requires(src -> src.hasPermissionLevel(ConfigHandler.config.permissionLevel)).then(CommandManager.argument("players", GameProfileArgumentType.gameProfile()) .then(CommandManager.argument("amount", IntegerArgumentType.integer()).executes(CommandClaim::giveClaimBlocks)))) .then(CommandManager.literal("group") - .then(CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.word()).executes(CommandClaim::addGroup))) - .then(CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.word()) + .then(CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.string()).executes(CommandClaim::addGroup))) + .then(CommandManager.literal("remove").then(CommandManager.argument("group", StringArgumentType.string()) .suggests(CommandClaim::groupSuggestion).executes(CommandClaim::removeGroup))) .then(CommandManager.literal("players") .then(CommandManager.literal("add").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion) @@ -90,7 +91,7 @@ public class CommandClaim { .then(CommandManager.literal("permission") .then(CommandManager.literal("global").then(CommandManager.argument("permission", StringArgumentType.word()).suggests((ctx, b) -> permSuggestions(ctx, b, false)) .then(CommandManager.argument("toggle", StringArgumentType.word()).suggests((ctx, b) -> CommandSource.suggestMatching(new String[]{"default", "true", "false"}, b)).executes(CommandClaim::editGlobalPerm)))) - .then(CommandManager.literal("group").then(CommandManager.argument("group", StringArgumentType.word()).suggests(CommandClaim::groupSuggestion) + .then(CommandManager.literal("group").then(CommandManager.argument("group", StringArgumentType.string()).suggests(CommandClaim::groupSuggestion) .then(CommandManager.argument("permission", StringArgumentType.word()).suggests((ctx, b) -> permSuggestions(ctx, b, true)) .then(CommandManager.argument("toggle", StringArgumentType.word()) .suggests((ctx, b) -> CommandSource.suggestMatching(new String[]{"default", "true", "false"}, b)).executes(CommandClaim::editGroupPerm)))))) @@ -395,6 +396,8 @@ public class CommandClaim { return Command.SINGLE_SUCCESS; } + private static final Pattern allowed = Pattern.compile("[a-zA-Z0-9_+.-]+"); + private static CompletableFuture groupSuggestion(CommandContext context, SuggestionsBuilder build) throws CommandSyntaxException { ServerPlayerEntity player = context.getSource().getPlayer(); List list = Lists.newArrayList(); @@ -403,6 +406,11 @@ public class CommandClaim { if (claim != null && claim.canInteract(player, PermissionRegistry.EDITPERMS, player.getBlockPos())) { list = claim.groups(); } + for(int i = 0; i < list.size(); i++){ + if(allowed.matcher(list.get(i)).matches()) + continue; + list.set(i, '\"'+list.get(i)+'\"'); + } return CommandSource.suggestMatching(list, build); }