Skip to content

Commit

Permalink
Make CommandSourceStack respect hidden players
Browse files Browse the repository at this point in the history
  • Loading branch information
notTamion committed Jan 4, 2025
1 parent edde726 commit 9b03afc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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/net/minecraft/commands/CommandSourceStack.java b/net/minecraft/commands/CommandSourceStack.java
index 704a63890a06d793f8ac3452838917e7c7335232..75262c8c9eaecb4a88a94f4076d67119c67a97da 100644
index 6d169492a3a052491232c2851a2fef8a7b4ac8f0..0790b12825b31190234210525b0e0ac7bccc14fc 100644
--- a/net/minecraft/commands/CommandSourceStack.java
+++ b/net/minecraft/commands/CommandSourceStack.java
@@ -652,4 +652,20 @@ public class CommandSourceStack implements ExecutionCommandSource<CommandSourceS
Expand Down Expand Up @@ -60,7 +60,7 @@ index fa8c5ba4e0efd0c36613aaa8eaafba0cb70ceb87..19ccf3abf14c67f72a1ca065e4a304f5
}

diff --git a/net/minecraft/commands/arguments/EntityArgument.java b/net/minecraft/commands/arguments/EntityArgument.java
index 0a01df6ebd14afe79bc76364cb1df5e0c5c08074..7a06ad9940d25e163178370bfa9ccc3bbd3d1189 100644
index 0a01df6ebd14afe79bc76364cb1df5e0c5c08074..77a68052c7653aee54c60f4bded9fa5337e3e4db 100644
--- a/net/minecraft/commands/arguments/EntityArgument.java
+++ b/net/minecraft/commands/arguments/EntityArgument.java
@@ -138,7 +138,7 @@ public class EntityArgument implements ArgumentType<EntitySelector> {
Expand All @@ -72,27 +72,6 @@ index 0a01df6ebd14afe79bc76364cb1df5e0c5c08074..7a06ad9940d25e163178370bfa9ccc3b
// Paper end - Fix EntityArgument permissions

try {
@@ -149,7 +149,19 @@ public class EntityArgument implements ArgumentType<EntitySelector> {
return entitySelectorParser.fillSuggestions(
builder,
offsetBuilder -> {
- Collection<String> onlinePlayerNames = sharedSuggestionProvider.getOnlinePlayerNames();
+ // Paper start - tell clients to ask server for suggestions for EntityArguments
+ final Collection<String> onlinePlayerNames;
+ if (sharedSuggestionProvider instanceof CommandSourceStack commandSourceStack && commandSourceStack.getEntity() instanceof ServerPlayer sourcePlayer) {
+ onlinePlayerNames = new java.util.ArrayList<>();
+ for (final ServerPlayer player : commandSourceStack.getServer().getPlayerList().getPlayers()) {
+ if (sourcePlayer.getBukkitEntity().canSee(player.getBukkitEntity())) {
+ onlinePlayerNames.add(player.getGameProfile().getName());
+ }
+ }
+ } else {
+ onlinePlayerNames = sharedSuggestionProvider.getOnlinePlayerNames();
+ }
+ // Paper end - tell clients to ask server for suggestions for EntityArguments
Iterable<String> iterable = (Iterable<String>)(this.playersOnly
? onlinePlayerNames
: Iterables.concat(onlinePlayerNames, sharedSuggestionProvider.getSelectedEntities()));
diff --git a/net/minecraft/commands/arguments/selector/EntitySelectorParser.java b/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
index a6f232747df631f6afe440606bea94c588f1a0dd..fb42630741674c6cbd20b7d45d78dea1dc73a78f 100644
--- a/net/minecraft/commands/arguments/selector/EntitySelectorParser.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@
}
}

@@ -523,7 +_,7 @@

@Override
public Collection<String> getOnlinePlayerNames() {
- return Lists.newArrayList(this.server.getPlayerNames());
+ return this.entity instanceof ServerPlayer sourcePlayer && !sourcePlayer.getBukkitEntity().hasPermission("paper.bypass-visibility.tab-completion") ? this.getServer().getPlayerList().getPlayers().stream().filter(serverPlayer -> sourcePlayer.getBukkitEntity().canSee(serverPlayer.getBukkitEntity())).map(serverPlayer -> serverPlayer.getGameProfile().getName()).toList() : Lists.newArrayList(this.server.getPlayerNames()); // Paper - Make CommandSourceStack respect hidden players
}

@Override
@@ -598,4 +_,16 @@
public boolean isSilent() {
return this.silent;
Expand Down

0 comments on commit 9b03afc

Please sign in to comment.