|
8 | 8 | import com.mojang.brigadier.arguments.ArgumentType; |
9 | 9 | import com.mojang.brigadier.context.CommandContext; |
10 | 10 | import com.mojang.brigadier.exceptions.CommandSyntaxException; |
11 | | -import com.mojang.brigadier.suggestion.SuggestionProvider; |
12 | 11 | import com.mojang.brigadier.suggestion.Suggestions; |
13 | 12 | import com.mojang.brigadier.suggestion.SuggestionsBuilder; |
14 | 13 | import io.papermc.paper.adventure.PaperAdventure; |
|
35 | 34 | import io.papermc.paper.registry.RegistryKey; |
36 | 35 | import io.papermc.paper.registry.TypedKey; |
37 | 36 | import io.papermc.paper.util.MCUtil; |
| 37 | +import java.util.ArrayList; |
38 | 38 | import java.util.Collection; |
39 | 39 | import java.util.Collections; |
40 | 40 | import java.util.List; |
|
47 | 47 | import net.kyori.adventure.text.format.Style; |
48 | 48 | import net.minecraft.advancements.critereon.MinMaxBounds; |
49 | 49 | import net.minecraft.commands.CommandSourceStack; |
50 | | -import net.minecraft.commands.SharedSuggestionProvider; |
51 | 50 | import net.minecraft.commands.arguments.ColorArgument; |
52 | 51 | import net.minecraft.commands.arguments.ComponentArgument; |
53 | 52 | import net.minecraft.commands.arguments.DimensionArgument; |
|
78 | 77 | import net.minecraft.commands.arguments.coordinates.Vec3Argument; |
79 | 78 | import net.minecraft.commands.arguments.item.ItemArgument; |
80 | 79 | import net.minecraft.commands.arguments.item.ItemPredicateArgument; |
81 | | -import net.minecraft.commands.arguments.selector.EntitySelectorParser; |
82 | 80 | import net.minecraft.core.BlockPos; |
83 | 81 | import net.minecraft.core.registries.Registries; |
84 | 82 | import net.minecraft.resources.ResourceKey; |
|
112 | 110 | import org.bukkit.scoreboard.Criteria; |
113 | 111 | import org.bukkit.scoreboard.DisplaySlot; |
114 | 112 | import org.bukkit.scoreboard.Objective; |
| 113 | +import org.bukkit.scoreboard.ScoreHolder; |
115 | 114 | import org.bukkit.scoreboard.Scoreboard; |
116 | 115 | import org.checkerframework.checker.nullness.qual.NonNull; |
117 | 116 | import org.checkerframework.checker.nullness.qual.Nullable; |
|
122 | 121 | @DefaultQualifier(NonNull.class) |
123 | 122 | public class VanillaArgumentProviderImpl implements VanillaArgumentProvider { |
124 | 123 |
|
| 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 | + |
125 | 134 | @Override |
126 | 135 | public ArgumentType<EntitySelectorArgumentResolver> entity() { |
127 | 136 | return this.wrap(EntityArgument.entity(), (result) -> sourceStack -> { |
@@ -245,12 +254,12 @@ public ArgumentType<DisplaySlot> scoreboardDisplaySlot() { |
245 | 254 |
|
246 | 255 | @Override |
247 | 256 | public ArgumentType<ScoreHolderResolver> scoreHolder() { |
248 | | - return new ScoreHolderWrapperArgumentType(ScoreHolderArgument.scoreHolder()); |
| 257 | + return this.wrap(ScoreHolderArgument.scoreHolder(), VanillaArgumentProviderImpl::convertScoreHolders); |
249 | 258 | } |
250 | 259 |
|
251 | 260 | @Override |
252 | 261 | public ArgumentType<ScoreHolderResolver> scoreHolders() { |
253 | | - return new ScoreHolderWrapperArgumentType(ScoreHolderArgument.scoreHolders()); |
| 262 | + return this.wrap(ScoreHolderArgument.scoreHolders(), VanillaArgumentProviderImpl::convertScoreHolders); |
254 | 263 | } |
255 | 264 |
|
256 | 265 | @Override |
@@ -410,7 +419,7 @@ interface ResultConverter<T, R> { |
410 | 419 | R convert(T type) throws CommandSyntaxException; |
411 | 420 | } |
412 | 421 |
|
413 | | - public static sealed class NativeWrapperArgumentType<M, P> implements ArgumentType<P> permits ScoreHolderWrapperArgumentType { |
| 422 | + public static final class NativeWrapperArgumentType<M, P> implements ArgumentType<P> { |
414 | 423 |
|
415 | 424 | private final ArgumentType<M> nmsBase; |
416 | 425 | private final ResultConverter<M, P> converter; |
@@ -444,39 +453,4 @@ public Collection<String> getExamples() { |
444 | 453 | return this.nmsBase.getExamples(); |
445 | 454 | } |
446 | 455 | } |
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 | | - } |
482 | 456 | } |
0 commit comments