From 6d4cbb2df64cbc1fdde0592d3fed3d728751872b Mon Sep 17 00:00:00 2001 From: Pierre Maurice Schwang Date: Sat, 1 Oct 2022 21:55:14 +0200 Subject: [PATCH] feat: check visibility of player in `/plot near` --- Core/src/main/java/com/plotsquared/core/command/Near.java | 7 ++++++- Core/src/main/java/com/plotsquared/core/plot/Plot.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/command/Near.java b/Core/src/main/java/com/plotsquared/core/command/Near.java index 449be991b..840d54e7d 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Near.java +++ b/Core/src/main/java/com/plotsquared/core/command/Near.java @@ -26,6 +26,7 @@ import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; import net.kyori.adventure.text.minimessage.Template; +import java.util.List; import java.util.concurrent.CompletableFuture; @CommandDeclaration(command = "near", @@ -48,9 +49,13 @@ public class Near extends Command { final Plot plot = check(player.getCurrentPlot(), TranslatableCaption.of("errors.not_in_plot")); player.sendMessage( TranslatableCaption.of("near.plot_near"), - Template.of("list", StringMan.join(plot.getPlayersInPlot(), ", ")) + Template.of("list", StringMan.join(getPlayersInPlotVisible(plot, player), ", ")) ); return CompletableFuture.completedFuture(true); } + private List> getPlayersInPlotVisible(Plot plot, PlotPlayer executor) { + return plot.getPlayersInPlot().stream().filter(executor::canSee).toList(); + } + } diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 1f91da15a..fd3e68046 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -457,7 +457,7 @@ public class Plot { * that could alter the de facto owner of the plot. * * @return The plot owner of this particular (sub-)plot - * as stored in the database, if one exists. Else, null. + * as stored in the database, if one exists. Else, null. */ public @Nullable UUID getOwnerAbs() { return this.owner;