2021-12-22 06:34:20 +01:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
|
|
Date: Sun, 22 Aug 2021 15:21:57 -0700
|
|
|
|
Subject: [PATCH] Fix entity type tags suggestions in selectors
|
|
|
|
|
|
|
|
This would really be better as a client fix because just to fix it
|
|
|
|
all EntityArguments have been told to ask the server for completions
|
|
|
|
when if this was fixed on the client, that wouldn't be needed.
|
|
|
|
|
|
|
|
Mojira Issue: https://bugs.mojang.com/browse/MC-235045
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/PaperConfig.java b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
2022-06-08 14:33:46 +02:00
|
|
|
index a98cd0aecc034038d81194fd87c4f8df65b86095..a1e36435187a51d2fe100945b90f409b8f9305c1 100644
|
2021-12-22 06:34:20 +01:00
|
|
|
--- a/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/PaperConfig.java
|
2022-06-08 14:33:46 +02:00
|
|
|
@@ -523,6 +523,11 @@ public class PaperConfig {
|
2021-12-22 06:34:20 +01:00
|
|
|
itemValidationBookPageLength = getInt("settings.item-validation.book.page", itemValidationBookPageLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public static boolean fixTargetSelectorTagCompletion = true;
|
|
|
|
+ private static void fixTargetSelectorTagCompletion() {
|
|
|
|
+ fixTargetSelectorTagCompletion = getBoolean("settings.fix-target-selector-tag-completion", fixTargetSelectorTagCompletion);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
public static final class PacketLimit {
|
|
|
|
public final double packetLimitInterval;
|
|
|
|
public final double maxPacketRate;
|
2021-12-30 08:11:40 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/commands/CommandSourceStack.java b/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
2022-06-08 14:33:46 +02:00
|
|
|
index 3ad9f1327cd99e16e8eca86d72cb8a57f28b245e..e6c254cfa83b218ad2a0e957306d8019adf0aaa7 100644
|
2021-12-30 08:11:40 +01:00
|
|
|
--- a/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
|
|
|
+++ b/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
2022-06-08 14:33:46 +02:00
|
|
|
@@ -366,4 +366,20 @@ public class CommandSourceStack implements SharedSuggestionProvider, com.destroy
|
2021-12-30 08:11:40 +01:00
|
|
|
return this.source.getBukkitSender(this);
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
+ // Paper start - override getSelectedEntities
|
|
|
|
+ @Override
|
|
|
|
+ public Collection<String> getSelectedEntities() {
|
|
|
|
+ if (com.destroystokyo.paper.PaperConfig.fixTargetSelectorTagCompletion && this.source instanceof ServerPlayer player) {
|
|
|
|
+ double pickDistance = player.gameMode.getGameModeForPlayer().isCreative() ? 5.0F : 4.5F;
|
|
|
|
+ Vec3 min = player.getEyePosition(1.0F);
|
|
|
|
+ Vec3 viewVector = player.getViewVector(1.0F);
|
|
|
|
+ Vec3 max = min.add(viewVector.x * pickDistance, viewVector.y * pickDistance, viewVector.z * pickDistance);
|
|
|
|
+ net.minecraft.world.phys.AABB aabb = player.getBoundingBox().expandTowards(viewVector.scale(pickDistance)).inflate(1.0D, 1.0D, 1.0D);
|
|
|
|
+ pickDistance = player.gameMode.getGameModeForPlayer().isCreative() ? 6.0F : pickDistance;
|
|
|
|
+ net.minecraft.world.phys.EntityHitResult hitResult = net.minecraft.world.entity.projectile.ProjectileUtil.getEntityHitResult(player, min, max, aabb, (e) -> !e.isSpectator() && e.isPickable(), pickDistance);
|
|
|
|
+ return hitResult != null ? java.util.Collections.singletonList(hitResult.getEntity().getStringUUID()) : SharedSuggestionProvider.super.getSelectedEntities();
|
|
|
|
+ }
|
|
|
|
+ return SharedSuggestionProvider.super.getSelectedEntities();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
}
|
2021-12-22 06:34:20 +01:00
|
|
|
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
|
2022-06-08 14:33:46 +02:00
|
|
|
index af00f7dcbc1c4fb8da25128d5603b3ef041db7da..a51040aec86c0be2b124619d8fea2111778ad684 100644
|
2021-12-22 06:34:20 +01:00
|
|
|
--- a/src/main/java/net/minecraft/commands/Commands.java
|
|
|
|
+++ b/src/main/java/net/minecraft/commands/Commands.java
|
2022-06-08 14:33:46 +02:00
|
|
|
@@ -411,6 +411,7 @@ public class Commands {
|
2021-12-30 08:11:40 +01:00
|
|
|
private void fillUsableCommands(CommandNode<CommandSourceStack> tree, CommandNode<SharedSuggestionProvider> result, CommandSourceStack source, Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> resultNodes) {
|
|
|
|
Iterator iterator = tree.getChildren().iterator();
|
2021-12-22 06:34:20 +01:00
|
|
|
|
2021-12-30 08:11:40 +01:00
|
|
|
+ boolean registeredAskServerSuggestionsForTree = false; // Paper - tell clients to ask server for suggestions for EntityArguments
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
CommandNode<CommandSourceStack> commandnode2 = (CommandNode) iterator.next();
|
|
|
|
if ( !org.spigotmc.SpigotConfig.sendNamespaced && commandnode2.getName().contains( ":" ) ) continue; // Spigot
|
2022-06-08 14:33:46 +02:00
|
|
|
@@ -432,6 +433,12 @@ public class Commands {
|
2021-12-30 08:11:40 +01:00
|
|
|
|
|
|
|
if (requiredargumentbuilder.getSuggestionsProvider() != null) {
|
|
|
|
requiredargumentbuilder.suggests(SuggestionProviders.safelySwap(requiredargumentbuilder.getSuggestionsProvider()));
|
|
|
|
+ // Paper start - tell clients to ask server for suggestions for EntityArguments
|
|
|
|
+ registeredAskServerSuggestionsForTree = requiredargumentbuilder.getSuggestionsProvider() == net.minecraft.commands.synchronization.SuggestionProviders.ASK_SERVER;
|
|
|
|
+ } else if (com.destroystokyo.paper.PaperConfig.fixTargetSelectorTagCompletion && !registeredAskServerSuggestionsForTree && requiredargumentbuilder.getType() instanceof net.minecraft.commands.arguments.EntityArgument) {
|
|
|
|
+ requiredargumentbuilder.suggests(requiredargumentbuilder.getType()::listSuggestions);
|
|
|
|
+ registeredAskServerSuggestionsForTree = true; // You can only
|
|
|
|
+ // Paper end - tell clients to ask server for suggestions for EntityArguments
|
|
|
|
}
|
|
|
|
}
|
2021-12-22 06:34:20 +01:00
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/commands/arguments/EntityArgument.java b/src/main/java/net/minecraft/commands/arguments/EntityArgument.java
|
2022-06-08 14:33:46 +02:00
|
|
|
index 850db283bf12345e9e7d7e8e590dbe8135c6dce1..a2ea64b7ec5f47224312a1e08dd64347be6f7c43 100644
|
2021-12-22 06:34:20 +01:00
|
|
|
--- a/src/main/java/net/minecraft/commands/arguments/EntityArgument.java
|
|
|
|
+++ b/src/main/java/net/minecraft/commands/arguments/EntityArgument.java
|
2022-06-08 14:33:46 +02:00
|
|
|
@@ -128,7 +128,7 @@ public class EntityArgument implements ArgumentType<EntitySelector> {
|
|
|
|
StringReader stringreader = new StringReader(suggestionsbuilder.getInput());
|
2021-12-22 06:34:20 +01:00
|
|
|
|
|
|
|
stringreader.setCursor(suggestionsbuilder.getStart());
|
|
|
|
- EntitySelectorParser argumentparserselector = new EntitySelectorParser(stringreader, icompletionprovider.hasPermission(2));
|
|
|
|
+ EntitySelectorParser argumentparserselector = new EntitySelectorParser(stringreader, icompletionprovider.hasPermission(2), true); // Paper
|
|
|
|
|
|
|
|
try {
|
|
|
|
argumentparserselector.parse();
|
|
|
|
diff --git a/src/main/java/net/minecraft/commands/arguments/selector/EntitySelectorParser.java b/src/main/java/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
|
2022-06-08 14:33:46 +02:00
|
|
|
index ad99d67af92cda03beb1142b02082ee1bfc8a64a..a57ae219d57ed47baedfb73b3d815f39d4f87035 100644
|
2021-12-22 06:34:20 +01:00
|
|
|
--- a/src/main/java/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
|
|
|
|
+++ b/src/main/java/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
|
|
|
|
@@ -115,12 +115,19 @@ public class EntitySelectorParser {
|
|
|
|
private boolean hasScores;
|
|
|
|
private boolean hasAdvancements;
|
|
|
|
private boolean usesSelectors;
|
|
|
|
+ public boolean parsingEntityArgumentSuggestions; // Paper - track when parsing EntityArgument suggestions
|
|
|
|
|
|
|
|
public EntitySelectorParser(StringReader reader) {
|
|
|
|
this(reader, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public EntitySelectorParser(StringReader reader, boolean atAllowed) {
|
|
|
|
+ // Paper start
|
|
|
|
+ this(reader, atAllowed, false);
|
|
|
|
+ }
|
|
|
|
+ public EntitySelectorParser(StringReader reader, boolean atAllowed, boolean parsingEntityArgumentSuggestions) {
|
|
|
|
+ this.parsingEntityArgumentSuggestions = parsingEntityArgumentSuggestions;
|
|
|
|
+ // Paper end
|
|
|
|
this.distance = MinMaxBounds.Doubles.ANY;
|
|
|
|
this.level = MinMaxBounds.Ints.ANY;
|
|
|
|
this.rotX = WrappedMinMaxBounds.ANY;
|
|
|
|
diff --git a/src/main/java/net/minecraft/commands/arguments/selector/options/EntitySelectorOptions.java b/src/main/java/net/minecraft/commands/arguments/selector/options/EntitySelectorOptions.java
|
2022-06-08 14:33:46 +02:00
|
|
|
index c2b26a089c423e5df9a5cbfd1c70efbd1acb0e7a..f15e6fd9b9d35554044bf9f713b60d4c549d9b5e 100644
|
2021-12-22 06:34:20 +01:00
|
|
|
--- a/src/main/java/net/minecraft/commands/arguments/selector/options/EntitySelectorOptions.java
|
|
|
|
+++ b/src/main/java/net/minecraft/commands/arguments/selector/options/EntitySelectorOptions.java
|
2022-06-08 14:33:46 +02:00
|
|
|
@@ -67,6 +67,19 @@ public class EntitySelectorOptions {
|
2021-12-22 06:34:20 +01:00
|
|
|
public static final DynamicCommandExceptionType ERROR_ENTITY_TYPE_INVALID = new DynamicCommandExceptionType((entity) -> {
|
2022-06-08 14:33:46 +02:00
|
|
|
return Component.translatable("argument.entity.options.type.invalid", entity);
|
2021-12-22 06:34:20 +01:00
|
|
|
});
|
|
|
|
+ // Paper start
|
|
|
|
+ public static final DynamicCommandExceptionType ERROR_ENTITY_TAG_INVALID = new DynamicCommandExceptionType((object) -> {
|
|
|
|
+ return io.papermc.paper.adventure.PaperAdventure
|
|
|
|
+ .asVanilla(net.kyori.adventure.text.Component
|
|
|
|
+ .text("Invalid or unknown entity type tag '" + object + "'")
|
|
|
|
+ .hoverEvent(net.kyori.adventure.text.event.HoverEvent
|
|
|
|
+ .showText(net.kyori.adventure.text.Component
|
|
|
|
+ .text("You can disable this error in 'paper.yml'")
|
|
|
|
+ )
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ });
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
private static void register(String id, EntitySelectorOptions.Modifier handler, Predicate<EntitySelectorParser> condition, Component description) {
|
|
|
|
OPTIONS.put(id, new EntitySelectorOptions.Option(handler, condition, description));
|
2022-06-08 14:33:46 +02:00
|
|
|
@@ -314,6 +327,12 @@ public class EntitySelectorOptions {
|
2021-12-22 06:34:20 +01:00
|
|
|
|
|
|
|
if (reader.isTag()) {
|
2022-02-28 23:16:17 +01:00
|
|
|
TagKey<EntityType<?>> tagKey = TagKey.create(Registry.ENTITY_TYPE_REGISTRY, ResourceLocation.read(reader.getReader()));
|
2021-12-22 06:34:20 +01:00
|
|
|
+ // Paper start - throw error if invalid entity tag (only on suggestions to keep cmd success behavior)
|
2022-02-28 23:16:17 +01:00
|
|
|
+ if (com.destroystokyo.paper.PaperConfig.fixTargetSelectorTagCompletion && reader.parsingEntityArgumentSuggestions && !Registry.ENTITY_TYPE.isKnownTagName(tagKey)) {
|
2021-12-22 06:34:20 +01:00
|
|
|
+ reader.getReader().setCursor(i);
|
2022-02-28 23:16:17 +01:00
|
|
|
+ throw ERROR_ENTITY_TAG_INVALID.createWithContext(reader.getReader(), tagKey);
|
2021-12-22 06:34:20 +01:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
reader.addPredicate((entity) -> {
|
2022-02-28 23:16:17 +01:00
|
|
|
return entity.getType().is(tagKey) != bl;
|
2021-12-22 06:34:20 +01:00
|
|
|
});
|