Skip to content

Commit 0ca9458

Browse files
Map magic item and variable name arguments to a more lenient brigadier argument type
1 parent 62a6324 commit 0ca9458

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

core/src/main/java/com/nisovin/magicspells/commands/MagicCommands.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public static void register(@NotNull PaperCommandManager<CommandSourceStack> man
9999
// Less restrictive in terms of valid non-quoted characters compared to the brigadier string type.
100100
brigadierMapper.mapSimpleNMS(new TypeToken<OwnedSpellParser>() {}, "nbt_path", true);
101101
brigadierMapper.mapSimpleNMS(new TypeToken<SpellParser<CommandSourceStack>>() {}, "nbt_path", true);
102+
brigadierMapper.mapSimpleNMS(new TypeToken<LenientQuotedStringParser<CommandSourceStack>>() {}, "nbt_path", true);
102103

103104
MinecraftExceptionHandler.create(CommandSourceStack::getSender)
104105
.defaultHandlers()

core/src/main/java/com/nisovin/magicspells/commands/MagicItemCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.incendo.cloud.description.Description;
1313
import org.incendo.cloud.parser.flag.CommandFlag;
1414
import org.incendo.cloud.paper.PaperCommandManager;
15-
import org.incendo.cloud.parser.standard.StringParser;
1615
import org.incendo.cloud.parser.standard.IntegerParser;
1716
import org.incendo.cloud.suggestion.SuggestionProvider;
1817
import org.incendo.cloud.bukkit.data.MultiplePlayerSelector;
@@ -26,6 +25,7 @@
2625
import com.nisovin.magicspells.Perm;
2726
import com.nisovin.magicspells.util.magicitems.MagicItem;
2827
import com.nisovin.magicspells.util.magicitems.MagicItems;
28+
import com.nisovin.magicspells.commands.parsers.LenientQuotedStringParser;
2929
import com.nisovin.magicspells.commands.exceptions.InvalidCommandArgumentException;
3030

3131
public class MagicItemCommand {
@@ -49,7 +49,7 @@ static void register(@NotNull PaperCommandManager<CommandSourceStack> manager) {
4949
)
5050
.required(
5151
MAGIC_ITEM_KEY,
52-
StringParser.stringParser(),
52+
LenientQuotedStringParser.lenientQuotedStringParser(),
5353
Description.of("The magic item to give."),
5454
SuggestionProvider.suggestingStrings(MagicItems.getMagicItemKeys())
5555
)

core/src/main/java/com/nisovin/magicspells/commands/VariableCommands.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.nisovin.magicspells.variables.Variable;
3131
import com.nisovin.magicspells.util.managers.VariableManager;
3232
import com.nisovin.magicspells.variables.variabletypes.GlobalVariable;
33+
import com.nisovin.magicspells.commands.parsers.LenientQuotedStringParser;
3334
import com.nisovin.magicspells.variables.variabletypes.GlobalStringVariable;
3435
import com.nisovin.magicspells.commands.exceptions.InvalidCommandArgumentException;
3536

@@ -44,7 +45,7 @@ static void register(@NotNull PaperCommandManager<CommandSourceStack> manager) {
4445

4546
var variableComponent = CommandComponent.<CommandSourceStack, String>builder()
4647
.key(VARIABLE_KEY)
47-
.parser(StringParser.stringParser())
48+
.parser(LenientQuotedStringParser.lenientQuotedStringParser())
4849
.suggestionProvider(SuggestionProvider.suggestingStrings(
4950
() -> MagicSpells.getVariableManager().getVariables().keySet().iterator()
5051
));
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.nisovin.magicspells.commands.parsers;
2+
3+
import org.checkerframework.checker.nullness.qual.NonNull;
4+
5+
import org.incendo.cloud.context.CommandInput;
6+
import org.incendo.cloud.parser.ArgumentParser;
7+
import org.incendo.cloud.context.CommandContext;
8+
import org.incendo.cloud.parser.ParserDescriptor;
9+
import org.incendo.cloud.parser.ArgumentParseResult;
10+
import org.incendo.cloud.parser.standard.StringParser;
11+
12+
public class LenientQuotedStringParser<C> implements ArgumentParser<C, String> {
13+
14+
public static <C> ParserDescriptor<C, String> lenientQuotedStringParser() {
15+
return ParserDescriptor.of(new LenientQuotedStringParser<>(), String.class);
16+
}
17+
18+
private final StringParser<C> stringParser = new StringParser<>(StringParser.StringMode.QUOTED);
19+
20+
@Override
21+
public @NonNull ArgumentParseResult<String> parse(@NonNull CommandContext<C> commandContext, @NonNull CommandInput commandInput) {
22+
return stringParser.parse(commandContext, commandInput);
23+
}
24+
25+
}

0 commit comments

Comments
 (0)