|
6 | 6 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
7 | 7 | import com.mojang.brigadier.builder.RequiredArgumentBuilder; |
8 | 8 | import com.mojang.brigadier.context.CommandContext; |
| 9 | +import com.mojang.brigadier.exceptions.CommandSyntaxException; |
| 10 | +import com.mojang.brigadier.StringReader; |
9 | 11 | import com.mojang.brigadier.tree.CommandNode; |
10 | 12 | import fr.xephi.authme.AuthMe; |
11 | 13 | import fr.xephi.authme.command.CommandArgumentDescription; |
12 | 14 | import fr.xephi.authme.command.CommandDescription; |
13 | 15 | import fr.xephi.authme.command.CommandUtils; |
14 | 16 | import io.papermc.paper.command.brigadier.CommandSourceStack; |
15 | 17 | import io.papermc.paper.command.brigadier.Commands; |
| 18 | +import io.papermc.paper.command.brigadier.argument.CustomArgumentType; |
16 | 19 | import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents; |
17 | 20 | import org.bukkit.command.CommandSender; |
18 | 21 |
|
@@ -110,15 +113,31 @@ private RequiredArgumentBuilder<CommandSourceStack, String> createFallbackArgume |
110 | 113 | .executes(this::executeInput); |
111 | 114 | } |
112 | 115 |
|
113 | | - /** Reads any non-whitespace characters — unlike {@code word()}, accepts {@code @}, {@code #}, etc. */ |
| 116 | + /** |
| 117 | + * Returns a Paper-compatible argument type that reads any non-whitespace characters — |
| 118 | + * unlike {@code word()}, accepts {@code @}, {@code #}, etc. Wrapped in {@link CustomArgumentType} |
| 119 | + * so Paper's Brigadier bridge does not reject it as an unknown raw argument type. |
| 120 | + */ |
114 | 121 | private static ArgumentType<String> anyWord() { |
115 | | - return reader -> { |
| 122 | + return AnyWordArgumentType.INSTANCE; |
| 123 | + } |
| 124 | + |
| 125 | + private static final class AnyWordArgumentType implements CustomArgumentType<String, String> { |
| 126 | + static final AnyWordArgumentType INSTANCE = new AnyWordArgumentType(); |
| 127 | + |
| 128 | + @Override |
| 129 | + public String parse(StringReader reader) throws CommandSyntaxException { |
116 | 130 | int start = reader.getCursor(); |
117 | 131 | while (reader.canRead() && reader.peek() != ' ') { |
118 | 132 | reader.skip(); |
119 | 133 | } |
120 | 134 | return reader.getString().substring(start, reader.getCursor()); |
121 | | - }; |
| 135 | + } |
| 136 | + |
| 137 | + @Override |
| 138 | + public ArgumentType<String> getNativeType() { |
| 139 | + return StringArgumentType.word(); |
| 140 | + } |
122 | 141 | } |
123 | 142 |
|
124 | 143 | private int executeInput(CommandContext<CommandSourceStack> context) { |
|
0 commit comments