mirror of
https://github.com/PaperMC/Paper.git
synced 2024-09-27 14:12:45 +02:00
fe53b0e76f
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 1d522878 PR-966: Introduce getRespawnLocation as a replacement for getBedSpawnLocation cc01b745 PR-965: Add DragonBattle#setPreviouslyKilled 28e3702f SPIGOT-6921, PR-957: Add methods to remove all enchantments on an ItemStack 8872404e PR-961: Add BlockData#copyTo 4054cc7b PR-956: Add method to get an offline player's location CraftBukkit Changes: 292ec79e0 SPIGOT-7568: Call EntityChangeBlockEvent for DecoratedPot b44bf5aa8 SPIGOT-7575: SuspiciousStewMeta creates invalid PotionEffect data 161784713 PR-1340: Centralize the conversion from and to Minecraft / Bukkit registry items even more and add a test case for them b93c5a30d PR-1338: Introduce getRespawnLocation as a replacement for getBedSpawnLocation fb973486c SPIGOT-7570: PrepareItemCraftEvent#isRepair() always returns false c9c24535e PR-1337: Add DragonBattle#setPreviouslyKilled c8b4da803 SPIGOT-6921, PR-1330: Add methods to remove all enchantments on an ItemStack 95bc1c4f5 PR-1333: Add BlockData#copyTo 36e2f9ce1 PR-1329: Add method to get an offline player's location Spigot Changes: c198da22 SPIGOT-7563: Update to latest release of bungeecord-chat
157 lines
12 KiB
Diff
157 lines
12 KiB
Diff
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/net/minecraft/commands/CommandSourceStack.java b/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
|
index faa375f2722793a86265248a4be4fa14736d9818..f341813e9713e39bfe142ca34b751de3d8efd25b 100644
|
|
--- a/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
|
+++ b/src/main/java/net/minecraft/commands/CommandSourceStack.java
|
|
@@ -466,4 +466,20 @@ public class CommandSourceStack implements ExecutionCommandSource<CommandSourceS
|
|
return this.source.getBukkitSender(this);
|
|
}
|
|
// CraftBukkit end
|
|
+ // Paper start - tell clients to ask server for suggestions for EntityArguments
|
|
+ @Override
|
|
+ public Collection<String> getSelectedEntities() {
|
|
+ if (io.papermc.paper.configuration.GlobalConfiguration.get().commands.fixTargetSelectorTagCompletion && this.source instanceof ServerPlayer player) {
|
|
+ final Entity cameraEntity = player.getCamera();
|
|
+ final double pickDistance = player.gameMode.getGameModeForPlayer().isCreative() ? 6.0F : 4.5F;
|
|
+ final Vec3 min = cameraEntity.getEyePosition(1.0F);
|
|
+ final Vec3 viewVector = cameraEntity.getViewVector(1.0F);
|
|
+ final Vec3 max = min.add(viewVector.x * pickDistance, viewVector.y * pickDistance, viewVector.z * pickDistance);
|
|
+ final net.minecraft.world.phys.AABB aabb = cameraEntity.getBoundingBox().expandTowards(viewVector.scale(pickDistance)).inflate(1.0D, 1.0D, 1.0D);
|
|
+ final net.minecraft.world.phys.EntityHitResult hitResult = net.minecraft.world.entity.projectile.ProjectileUtil.getEntityHitResult(cameraEntity, min, max, aabb, (e) -> !e.isSpectator() && e.isPickable(), pickDistance * pickDistance);
|
|
+ return hitResult != null ? java.util.Collections.singletonList(hitResult.getEntity().getStringUUID()) : SharedSuggestionProvider.super.getSelectedEntities();
|
|
+ }
|
|
+ return SharedSuggestionProvider.super.getSelectedEntities();
|
|
+ }
|
|
+ // Paper end - tell clients to ask server for suggestions for EntityArguments
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
|
|
index df06c28c778255cb2d8d5e14960bd38a2af9ad22..b7f338e982d0dcab99137ab6dc200b82ac6b7cba 100644
|
|
--- a/src/main/java/net/minecraft/commands/Commands.java
|
|
+++ b/src/main/java/net/minecraft/commands/Commands.java
|
|
@@ -522,6 +522,7 @@ public class Commands {
|
|
private void fillUsableCommands(CommandNode<CommandSourceStack> tree, CommandNode<SharedSuggestionProvider> result, CommandSourceStack source, Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> resultNodes) {
|
|
Iterator iterator = tree.getChildren().iterator();
|
|
|
|
+ boolean registeredAskServerSuggestionsForTree = false; // Paper - tell clients to ask server for suggestions for EntityArguments
|
|
while (iterator.hasNext()) {
|
|
CommandNode<CommandSourceStack> commandnode2 = (CommandNode) iterator.next();
|
|
// Paper start - Brigadier API
|
|
@@ -548,6 +549,12 @@ public class Commands {
|
|
|
|
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 (io.papermc.paper.configuration.GlobalConfiguration.get().commands.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
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/commands/arguments/EntityArgument.java b/src/main/java/net/minecraft/commands/arguments/EntityArgument.java
|
|
index 8e008e752c5b11781088e2b4b5ba180bacb59326..8d79cfa371546996ef65f94232c1d344e7c590ec 100644
|
|
--- a/src/main/java/net/minecraft/commands/arguments/EntityArgument.java
|
|
+++ b/src/main/java/net/minecraft/commands/arguments/EntityArgument.java
|
|
@@ -132,7 +132,7 @@ public class EntityArgument implements ArgumentType<EntitySelector> {
|
|
final boolean permission = object instanceof CommandSourceStack stack
|
|
? stack.bypassSelectorPermissions || stack.hasPermission(2, "minecraft.command.selector")
|
|
: icompletionprovider.hasPermission(2);
|
|
- EntitySelectorParser argumentparserselector = new EntitySelectorParser(stringreader, permission);
|
|
+ EntitySelectorParser argumentparserselector = new EntitySelectorParser(stringreader, permission, true); // Paper - tell clients to ask server for suggestions for EntityArguments
|
|
// Paper end - Fix EntityArgument suggestion permissions
|
|
|
|
try {
|
|
@@ -142,7 +142,19 @@ public class EntityArgument implements ArgumentType<EntitySelector> {
|
|
}
|
|
|
|
return argumentparserselector.fillSuggestions(suggestionsbuilder, (suggestionsbuilder1) -> {
|
|
- Collection<String> collection = icompletionprovider.getOnlinePlayerNames();
|
|
+ // Paper start - tell clients to ask server for suggestions for EntityArguments
|
|
+ final Collection<String> collection;
|
|
+ if (icompletionprovider instanceof CommandSourceStack commandSourceStack && commandSourceStack.getEntity() instanceof ServerPlayer sourcePlayer) {
|
|
+ collection = new java.util.ArrayList<>();
|
|
+ for (final ServerPlayer player : commandSourceStack.getServer().getPlayerList().getPlayers()) {
|
|
+ if (sourcePlayer.getBukkitEntity().canSee(player.getBukkitEntity())) {
|
|
+ collection.add(player.getGameProfile().getName());
|
|
+ }
|
|
+ }
|
|
+ } else {
|
|
+ collection = icompletionprovider.getOnlinePlayerNames();
|
|
+ }
|
|
+ // Paper end - tell clients to ask server for suggestions for EntityArguments
|
|
Iterable<String> iterable = this.playersOnly ? collection : Iterables.concat(collection, icompletionprovider.getSelectedEntities());
|
|
|
|
SharedSuggestionProvider.suggest((Iterable) iterable, suggestionsbuilder1);
|
|
diff --git a/src/main/java/net/minecraft/commands/arguments/selector/EntitySelectorParser.java b/src/main/java/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
|
|
index 3d897ec6920eff6176ddac9f0442a997b9ef14fd..abaf1ea340c69c8bee80e64567b44b5ce66d5fa3 100644
|
|
--- a/src/main/java/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
|
|
+++ b/src/main/java/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
|
|
@@ -113,12 +113,19 @@ public class EntitySelectorParser {
|
|
private boolean hasScores;
|
|
private boolean hasAdvancements;
|
|
private boolean usesSelectors;
|
|
+ public boolean parsingEntityArgumentSuggestions; // Paper - tell clients to ask server for suggestions for EntityArguments
|
|
|
|
public EntitySelectorParser(StringReader reader) {
|
|
this(reader, true);
|
|
}
|
|
|
|
public EntitySelectorParser(StringReader reader, boolean atAllowed) {
|
|
+ // Paper start - tell clients to ask server for suggestions for EntityArguments
|
|
+ this(reader, atAllowed, false);
|
|
+ }
|
|
+ public EntitySelectorParser(StringReader reader, boolean atAllowed, boolean parsingEntityArgumentSuggestions) {
|
|
+ this.parsingEntityArgumentSuggestions = parsingEntityArgumentSuggestions;
|
|
+ // Paper end - tell clients to ask server for suggestions for EntityArguments
|
|
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
|
|
index 7863833c9a761a2b9364ff572ec909ec5a4538c3..36e26929306c04af7a44012fd7fc9902027e9ea2 100644
|
|
--- a/src/main/java/net/minecraft/commands/arguments/selector/options/EntitySelectorOptions.java
|
|
+++ b/src/main/java/net/minecraft/commands/arguments/selector/options/EntitySelectorOptions.java
|
|
@@ -69,6 +69,19 @@ public class EntitySelectorOptions {
|
|
public static final DynamicCommandExceptionType ERROR_ENTITY_TYPE_INVALID = new DynamicCommandExceptionType((entity) -> {
|
|
return Component.translatableEscape("argument.entity.options.type.invalid", entity);
|
|
});
|
|
+ // Paper start - tell clients to ask server for suggestions for EntityArguments
|
|
+ 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 - tell clients to ask server for suggestions for EntityArguments
|
|
|
|
private static void register(String id, EntitySelectorOptions.Modifier handler, Predicate<EntitySelectorParser> condition, Component description) {
|
|
OPTIONS.put(id, new EntitySelectorOptions.Option(handler, condition, description));
|
|
@@ -316,6 +329,12 @@ public class EntitySelectorOptions {
|
|
|
|
if (reader.isTag()) {
|
|
TagKey<EntityType<?>> tagKey = TagKey.create(Registries.ENTITY_TYPE, ResourceLocation.read(reader.getReader()));
|
|
+ // Paper start - tell clients to ask server for suggestions for EntityArguments; throw error if invalid entity tag (only on suggestions to keep cmd success behavior)
|
|
+ if (reader.parsingEntityArgumentSuggestions && io.papermc.paper.configuration.GlobalConfiguration.get().commands.fixTargetSelectorTagCompletion && net.minecraft.core.registries.BuiltInRegistries.ENTITY_TYPE.getTag(tagKey).isEmpty()) {
|
|
+ reader.getReader().setCursor(i);
|
|
+ throw ERROR_ENTITY_TAG_INVALID.createWithContext(reader.getReader(), tagKey);
|
|
+ }
|
|
+ // Paper end - tell clients to ask server for suggestions for EntityArguments
|
|
reader.addPredicate((entity) -> {
|
|
return entity.getType().is(tagKey) != bl;
|
|
});
|