Skip to content

Commit 732f946

Browse files
committed
Remove scoreholder wrapper argument type hack
1 parent 89d714d commit 732f946

2 files changed

Lines changed: 15 additions & 44 deletions

File tree

paper-server/src/main/java/io/papermc/paper/command/brigadier/ApiMirrorRootNode.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ public static void validatePrimitiveType(ArgumentType<?> type) {
124124
}
125125

126126
converted = this.unwrapArgumentWrapper(pureArgumentNode, customArgumentType, customArgumentType.getNativeType(), suggestionProvider);
127-
} else if (pureArgumentType instanceof final VanillaArgumentProviderImpl.ScoreHolderWrapperArgumentType scoreHolderWrapperArgumentType) {
128-
// This is a special case, as we override the suggestions here
129-
converted = this.unwrapArgumentWrapper(pureArgumentNode, scoreHolderWrapperArgumentType, scoreHolderWrapperArgumentType, VanillaArgumentProviderImpl.ScoreHolderWrapperArgumentType.SUGGESTIONS);
130127
} else if (pureArgumentType instanceof final VanillaArgumentProviderImpl.NativeWrapperArgumentType<?, ?> nativeWrapperArgumentType) {
131128
converted = this.unwrapArgumentWrapper(pureArgumentNode, nativeWrapperArgumentType, nativeWrapperArgumentType, null); // "null" for suggestion provider so it uses the argument type's suggestion provider
132129

paper-server/src/main/java/io/papermc/paper/command/brigadier/argument/VanillaArgumentProviderImpl.java

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.mojang.brigadier.arguments.ArgumentType;
99
import com.mojang.brigadier.context.CommandContext;
1010
import com.mojang.brigadier.exceptions.CommandSyntaxException;
11-
import com.mojang.brigadier.suggestion.SuggestionProvider;
1211
import com.mojang.brigadier.suggestion.Suggestions;
1312
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
1413
import io.papermc.paper.adventure.PaperAdventure;
@@ -35,6 +34,7 @@
3534
import io.papermc.paper.registry.RegistryKey;
3635
import io.papermc.paper.registry.TypedKey;
3736
import io.papermc.paper.util.MCUtil;
37+
import java.util.ArrayList;
3838
import java.util.Collection;
3939
import java.util.Collections;
4040
import java.util.List;
@@ -47,7 +47,6 @@
4747
import net.kyori.adventure.text.format.Style;
4848
import net.minecraft.advancements.critereon.MinMaxBounds;
4949
import net.minecraft.commands.CommandSourceStack;
50-
import net.minecraft.commands.SharedSuggestionProvider;
5150
import net.minecraft.commands.arguments.ColorArgument;
5251
import net.minecraft.commands.arguments.ComponentArgument;
5352
import net.minecraft.commands.arguments.DimensionArgument;
@@ -78,7 +77,6 @@
7877
import net.minecraft.commands.arguments.coordinates.Vec3Argument;
7978
import net.minecraft.commands.arguments.item.ItemArgument;
8079
import net.minecraft.commands.arguments.item.ItemPredicateArgument;
81-
import net.minecraft.commands.arguments.selector.EntitySelectorParser;
8280
import net.minecraft.core.BlockPos;
8381
import net.minecraft.core.registries.Registries;
8482
import net.minecraft.resources.ResourceKey;
@@ -112,6 +110,7 @@
112110
import org.bukkit.scoreboard.Criteria;
113111
import org.bukkit.scoreboard.DisplaySlot;
114112
import org.bukkit.scoreboard.Objective;
113+
import org.bukkit.scoreboard.ScoreHolder;
115114
import org.bukkit.scoreboard.Scoreboard;
116115
import org.checkerframework.checker.nullness.qual.NonNull;
117116
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -122,6 +121,16 @@
122121
@DefaultQualifier(NonNull.class)
123122
public class VanillaArgumentProviderImpl implements VanillaArgumentProvider {
124123

124+
private static ScoreHolderResolver convertScoreHolders(ScoreHolderArgument.Result result) {
125+
return sourceStack -> {
126+
List<ScoreHolder> list = new ArrayList<>();
127+
for (net.minecraft.world.scores.ScoreHolder scoreHolder : result.getNames((CommandSourceStack) sourceStack, Collections::emptyList)) {
128+
list.add(CraftScoreHolder.fromNms(scoreHolder));
129+
}
130+
return list;
131+
};
132+
}
133+
125134
@Override
126135
public ArgumentType<EntitySelectorArgumentResolver> entity() {
127136
return this.wrap(EntityArgument.entity(), (result) -> sourceStack -> {
@@ -245,12 +254,12 @@ public ArgumentType<DisplaySlot> scoreboardDisplaySlot() {
245254

246255
@Override
247256
public ArgumentType<ScoreHolderResolver> scoreHolder() {
248-
return new ScoreHolderWrapperArgumentType(ScoreHolderArgument.scoreHolder());
257+
return this.wrap(ScoreHolderArgument.scoreHolder(), VanillaArgumentProviderImpl::convertScoreHolders);
249258
}
250259

251260
@Override
252261
public ArgumentType<ScoreHolderResolver> scoreHolders() {
253-
return new ScoreHolderWrapperArgumentType(ScoreHolderArgument.scoreHolders());
262+
return this.wrap(ScoreHolderArgument.scoreHolders(), VanillaArgumentProviderImpl::convertScoreHolders);
254263
}
255264

256265
@Override
@@ -410,7 +419,7 @@ interface ResultConverter<T, R> {
410419
R convert(T type) throws CommandSyntaxException;
411420
}
412421

413-
public static sealed class NativeWrapperArgumentType<M, P> implements ArgumentType<P> permits ScoreHolderWrapperArgumentType {
422+
public static final class NativeWrapperArgumentType<M, P> implements ArgumentType<P> {
414423

415424
private final ArgumentType<M> nmsBase;
416425
private final ResultConverter<M, P> converter;
@@ -444,39 +453,4 @@ public Collection<String> getExamples() {
444453
return this.nmsBase.getExamples();
445454
}
446455
}
447-
448-
public static final class ScoreHolderWrapperArgumentType extends NativeWrapperArgumentType<ScoreHolderArgument.Result, ScoreHolderResolver> {
449-
/**
450-
* Copied from {@code ScoreHolderArgument.SUGGEST_SCORE_HOLDERS}
451-
*
452-
* @see ScoreHolderArgument
453-
*/
454-
public static final SuggestionProvider<?> SUGGESTIONS = (context, builder) -> {
455-
if (context.getSource() instanceof CommandSourceStack cast) {
456-
StringReader stringReader = new StringReader(builder.getInput());
457-
stringReader.setCursor(builder.getStart());
458-
EntitySelectorParser entitySelectorParser = new EntitySelectorParser(stringReader, EntitySelectorParser.allowSelectors(context.getSource()));
459-
460-
try {
461-
entitySelectorParser.parse();
462-
} catch (CommandSyntaxException var5) {
463-
// Ignored
464-
}
465-
466-
return entitySelectorParser.fillSuggestions(
467-
builder, offsetBuilder -> SharedSuggestionProvider.suggest(cast.getOnlinePlayerNames(), offsetBuilder)
468-
);
469-
} else {
470-
throw new RuntimeException("Failed to provide suggestions for ScoreHolder argument type.");
471-
}
472-
};
473-
474-
private ScoreHolderWrapperArgumentType(final ArgumentType<ScoreHolderArgument.Result> nmsBase) {
475-
super(nmsBase, result -> sourceStack -> result.getNames((CommandSourceStack) sourceStack, Collections::emptyList)
476-
.stream()
477-
.map(CraftScoreHolder::fromNms)
478-
.map(craft -> (org.bukkit.scoreboard.ScoreHolder) craft)
479-
.toList());
480-
}
481-
}
482456
}

0 commit comments

Comments
 (0)