Skip to content
This repository was archived by the owner on May 5, 2026. It is now read-only.

Commit 474f3ea

Browse files
committed
fix: Brigadier await his types
1 parent 0a1770c commit 474f3ea

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

authme-paper-common/src/main/java/fr/xephi/authme/platform/PaperBrigadierCommandRegistrar.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
77
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
88
import com.mojang.brigadier.context.CommandContext;
9+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
10+
import com.mojang.brigadier.StringReader;
911
import com.mojang.brigadier.tree.CommandNode;
1012
import fr.xephi.authme.AuthMe;
1113
import fr.xephi.authme.command.CommandArgumentDescription;
1214
import fr.xephi.authme.command.CommandDescription;
1315
import fr.xephi.authme.command.CommandUtils;
1416
import io.papermc.paper.command.brigadier.CommandSourceStack;
1517
import io.papermc.paper.command.brigadier.Commands;
18+
import io.papermc.paper.command.brigadier.argument.CustomArgumentType;
1619
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEvents;
1720
import org.bukkit.command.CommandSender;
1821

@@ -110,15 +113,31 @@ private RequiredArgumentBuilder<CommandSourceStack, String> createFallbackArgume
110113
.executes(this::executeInput);
111114
}
112115

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+
*/
114121
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 {
116130
int start = reader.getCursor();
117131
while (reader.canRead() && reader.peek() != ' ') {
118132
reader.skip();
119133
}
120134
return reader.getString().substring(start, reader.getCursor());
121-
};
135+
}
136+
137+
@Override
138+
public ArgumentType<String> getNativeType() {
139+
return StringArgumentType.word();
140+
}
122141
}
123142

124143
private int executeInput(CommandContext<CommandSourceStack> context) {

0 commit comments

Comments
 (0)