From 0aeca40137d85d66e6ad0b67a4a42b324cce0b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Sat, 5 Sep 2020 18:48:58 +0200 Subject: [PATCH] Take player visibility into account when sending notify-enter and notify-leave messages. Fixes PS-103. --- .../com/plotsquared/bukkit/player/BukkitPlayer.java | 8 ++++++++ .../com/plotsquared/core/listener/PlotListener.java | 8 ++++---- .../com/plotsquared/core/player/ConsolePlayer.java | 4 ++++ .../java/com/plotsquared/core/player/PlotPlayer.java | 10 ++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index 643039600..1d4a0284e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -32,6 +32,7 @@ import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.location.Location; +import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.PlotWeather; import com.plotsquared.core.util.EconHandler; @@ -354,6 +355,13 @@ public class BukkitPlayer extends PlotPlayer { return this.player.isBanned(); } + @Override public boolean canSee(final PlotPlayer other) { + if (other instanceof ConsolePlayer) { + return true; + } else { + return this.player.canSee(((BukkitPlayer) other).getPlatformPlayer()); + } + } public PlayerTeleportEvent.TeleportCause getTeleportCause(@NotNull final TeleportCause cause) { switch (cause) { diff --git a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java index 361a71b28..bd99fe197 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -160,8 +160,8 @@ public class PlotListener { if (plot.getFlag(NotifyEnterFlag.class)) { if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) { for (UUID uuid : plot.getOwners()) { - final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); - if (owner != null && !owner.getUUID().equals(player.getUUID())) { + final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); + if (owner != null && !owner.getUUID().equals(player.getUUID()) && owner.canSee(player)) { MainUtil.sendMessage(owner, Captions.NOTIFY_ENTER.getTranslated() .replace("%player", player.getName()) .replace("%plot", plot.getId().toString())); @@ -336,8 +336,8 @@ public class PlotListener { if (plot.getFlag(NotifyLeaveFlag.class)) { if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) { for (UUID uuid : plot.getOwners()) { - final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); - if ((owner != null) && !owner.getUUID().equals(player.getUUID())) { + final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); + if ((owner != null) && !owner.getUUID().equals(player.getUUID()) && owner.canSee(player)) { MainUtil.sendMessage(owner, Captions.NOTIFY_LEAVE.getTranslated() .replace("%player", player.getName()) .replace("%plot", plot.getId().toString())); diff --git a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java index 9a97800e7..10a27c0fd 100644 --- a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java @@ -174,4 +174,8 @@ public class ConsolePlayer extends PlotPlayer { return false; } + @Override public boolean canSee(final PlotPlayer other) { + return true; + } + } diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index b11a33ba6..95fba9a60 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -727,6 +727,16 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer } } + /** + * Check if the player is able to see the other player. + * This does not mean that the other player is in line of sight of the player, + * but rather that the player is permitted to see the other player. + * + * @param other Other player + * @return {@code true} if the player is able to see the other player, {@code false} if not + */ + public abstract boolean canSee(PlotPlayer other); + public boolean hasPersistentMeta(String key) { return this.metaMap.containsKey(key); }