Incendo / cloud-minecraft

Integrations between Minecraft and Cloud Command Framework
https://cloud.incendo.org/minecraft/
MIT License
27 stars 8 forks source link

Modern Paper command doesn't support parsing asian languages or specific symbols (like '?') #89

Closed nostalfinals closed 3 months ago

nostalfinals commented 3 months ago

I'm using the latest snapshot of cloud and cloud-minecraft.

When I try to add an argument to my command that may contain Chinese characters, the command doesn't work.

image image

In SINGLE mode, StringParser seems to read all contents from the CommandInput. I suspect this issue is related to the platform's CommandManager.

public @NonNull ArgumentParseResult<String> parse(final @NonNull CommandContext<C> commandContext, final @NonNull CommandInput commandInput) {
    if (this.stringMode == StringParser.StringMode.SINGLE) {
        return ArgumentParseResult.success(commandInput.readString());
    } else {
        return this.stringMode == StringParser.StringMode.QUOTED ? this.parseQuoted(commandContext, commandInput) : this.parseGreedy(commandInput);
    }
}

When I switch to LegacyPaperCommandManager and register a legacy Paper brigadier, the command works correctly.

lateinit var commandManager: LegacyPaperCommandManager<CommandSender>
commandManager = LegacyPaperCommandManager.createNative(this, ExecutionCoordinator.asyncCoordinator())
commandManager.registerLegacyPaperBrigadier()

image

Here is how I create my command:

commandManager.commandBuilder("home")
    .required("name", StringParser.stringParser())
    .suspendingHandler {
        ...
    }
jpenilla commented 3 months ago

Legacy brig only appears to work as it does nothing (Paper never re-implemented the old API on 1.20.6+). https://github.com/Mojang/brigadier/blob/master/src/main/java/com/mojang/brigadier/StringReader.java#L169-L175 Mojang is very restrictive on what is allowed in unquoted strings. You must map your argument to a Brigadier type that accepts Chinese characters, like greedy or quoted string.