Take player visibility into account when sending notify-enter and notify-leave messages. Fixes PS-103.

This commit is contained in:
Alexander Söderberg 2020-09-05 18:48:58 +02:00
parent 5c48e4ad19
commit 0aeca40137
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
4 changed files with 26 additions and 4 deletions

View File

@ -32,6 +32,7 @@ import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.ConsolePlayer;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import com.plotsquared.core.plot.PlotWeather; import com.plotsquared.core.plot.PlotWeather;
import com.plotsquared.core.util.EconHandler; import com.plotsquared.core.util.EconHandler;
@ -354,6 +355,13 @@ public class BukkitPlayer extends PlotPlayer<Player> {
return this.player.isBanned(); 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) { public PlayerTeleportEvent.TeleportCause getTeleportCause(@NotNull final TeleportCause cause) {
switch (cause) { switch (cause) {

View File

@ -160,8 +160,8 @@ public class PlotListener {
if (plot.getFlag(NotifyEnterFlag.class)) { if (plot.getFlag(NotifyEnterFlag.class)) {
if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) { if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) {
for (UUID uuid : plot.getOwners()) { for (UUID uuid : plot.getOwners()) {
final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); final PlotPlayer<?> owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
if (owner != null && !owner.getUUID().equals(player.getUUID())) { if (owner != null && !owner.getUUID().equals(player.getUUID()) && owner.canSee(player)) {
MainUtil.sendMessage(owner, Captions.NOTIFY_ENTER.getTranslated() MainUtil.sendMessage(owner, Captions.NOTIFY_ENTER.getTranslated()
.replace("%player", player.getName()) .replace("%player", player.getName())
.replace("%plot", plot.getId().toString())); .replace("%plot", plot.getId().toString()));
@ -336,8 +336,8 @@ public class PlotListener {
if (plot.getFlag(NotifyLeaveFlag.class)) { if (plot.getFlag(NotifyLeaveFlag.class)) {
if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) { if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) {
for (UUID uuid : plot.getOwners()) { for (UUID uuid : plot.getOwners()) {
final PlotPlayer owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid); final PlotPlayer<?> owner = PlotSquared.imp().getPlayerManager().getPlayerIfExists(uuid);
if ((owner != null) && !owner.getUUID().equals(player.getUUID())) { if ((owner != null) && !owner.getUUID().equals(player.getUUID()) && owner.canSee(player)) {
MainUtil.sendMessage(owner, Captions.NOTIFY_LEAVE.getTranslated() MainUtil.sendMessage(owner, Captions.NOTIFY_LEAVE.getTranslated()
.replace("%player", player.getName()) .replace("%player", player.getName())
.replace("%plot", plot.getId().toString())); .replace("%plot", plot.getId().toString()));

View File

@ -174,4 +174,8 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
return false; return false;
} }
@Override public boolean canSee(final PlotPlayer<?> other) {
return true;
}
} }

View File

@ -727,6 +727,16 @@ public abstract class PlotPlayer<P> 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) { public boolean hasPersistentMeta(String key) {
return this.metaMap.containsKey(key); return this.metaMap.containsKey(key);
} }