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
4 changed files with 26 additions and 4 deletions

View File

@ -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()));

View File

@ -174,4 +174,8 @@ public class ConsolePlayer extends PlotPlayer<Actor> {
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) {
return this.metaMap.containsKey(key);
}