Skip to content

Commit

Permalink
support worlds with whitespace in command input, closes #60
Browse files Browse the repository at this point in the history
  • Loading branch information
granny committed Dec 12, 2024
1 parent 4ea0f71 commit 4a45bca
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@
*/
package net.pl3x.map.bukkit.command;

import com.mojang.brigadier.arguments.StringArgumentType;
import io.leangen.geantyref.TypeToken;
import net.pl3x.map.core.command.CommandHandler;
import net.pl3x.map.core.command.Sender;
import net.pl3x.map.core.command.parser.PlatformParsers;
import net.pl3x.map.core.command.parser.WorldParser;
import org.bukkit.plugin.Plugin;
import org.incendo.cloud.Command;
import org.incendo.cloud.SenderMapper;
Expand All @@ -49,6 +52,8 @@ public BukkitCommandManager(@NotNull Plugin plugin) throws Exception {
CloudBrigadierManager<Sender, ?> brigadier = getManager().brigadierManager();
if (brigadier != null) {
brigadier.setNativeNumberSuggestions(false);
brigadier.registerMapping(new TypeToken<WorldParser<Sender>>() {
}, builder -> builder.cloudSuggestions().toConstant(StringArgumentType.string()));
}
} else if (getManager().hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
getManager().registerAsynchronousCompletions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public static <C> ParserDescriptor<C, World> parser() {
@Override
public @NonNull ArgumentParseResult<@NonNull @NotNull World> parse(@NonNull CommandContext<@NonNull @NotNull C> commandContext, @NonNull CommandInput commandInput) {
String input = commandInput.peekString();
if (input.startsWith("\"")) {
commandInput.moveCursor(1);
input = commandInput.readUntilAndSkip('"');
} else {
input = commandInput.readString();
}
if (input == null) {
return ArgumentParseResult.failure(new WorldParseException(null, WorldParseException.MUST_SPECIFY_WORLD));
}
Expand All @@ -68,7 +74,6 @@ public static <C> ParserDescriptor<C, World> parser() {
return ArgumentParseResult.failure(new WorldParseException(input, WorldParseException.MAP_NOT_ENABLED));
}

commandInput.readString();
return ArgumentParseResult.success(world);
}

Expand Down Expand Up @@ -97,7 +102,7 @@ public static <C> ParserDescriptor<C, World> parser() {
return Pl3xMap.api().getWorldRegistry()
.values().stream()
.filter(World::isEnabled)
.map(World::getName)
.map(world -> world.getName().contains(" ") ? "\"" + world.getName() + "\"" : world.getName())
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
package net.pl3x.map.fabric.server.command;

import com.mojang.brigadier.arguments.StringArgumentType;
import io.leangen.geantyref.TypeToken;
import net.minecraft.commands.arguments.DimensionArgument;
import net.pl3x.map.core.command.CommandHandler;
import net.pl3x.map.core.command.Sender;
import net.pl3x.map.core.command.parser.PlatformParsers;
Expand All @@ -49,7 +49,7 @@ public FabricCommandManager() {
CloudBrigadierManager<@NotNull Sender, ?> brigadier = getManager().brigadierManager();
brigadier.setNativeNumberSuggestions(false);
brigadier.registerMapping(new TypeToken<WorldParser<Sender>>() {
}, builder -> builder.toConstant(DimensionArgument.dimension()).cloudSuggestions());
}, builder -> builder.cloudSuggestions().toConstant(StringArgumentType.string()));

setupExceptionHandlers();

Expand Down

0 comments on commit 4a45bca

Please sign in to comment.