Skip to content

Commit 3796ab3

Browse files
committed
Improved detection of vanished players
1 parent fc244f8 commit 3796ab3

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/java/pro/cloudnode/smp/cloudnodemsg/CloudnodeMSG.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public void onDisable() {
4646
// Plugin shutdown logic
4747
}
4848

49-
public static boolean isVanished(final @NotNull Player player) {
49+
public static boolean isVanished(final @NotNull Player player, final @NotNull Player observer) {
50+
if (!observer.canSee(player))
51+
return true;
5052
for (final @NotNull MetadataValue meta : player.getMetadata("vanished"))
5153
if (meta.asBoolean()) return true;
5254
return false;

src/main/java/pro/cloudnode/smp/cloudnodemsg/Message.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void send(final @NotNull Context context) throws InvalidPlayerError {
5757
final @NotNull Optional<@NotNull Player> senderPlayer = Optional.ofNullable(this.sender.getPlayer());
5858
final @NotNull Optional<@NotNull Player> recipientPlayer = Optional.ofNullable(this.recipient.getPlayer());
5959

60-
if (!recipient.getUniqueId().equals(console.getUniqueId()) && recipientPlayer.isEmpty() || (recipientPlayer.isPresent() && senderPlayer.isPresent() && CloudnodeMSG.isVanished(recipientPlayer.get()) && !senderPlayer.get().hasPermission(Permission.SEND_VANISHED))) {
60+
if (!recipient.getUniqueId().equals(console.getUniqueId()) && recipientPlayer.isEmpty() || (recipientPlayer.isPresent() && senderPlayer.isPresent() && CloudnodeMSG.isVanished(recipientPlayer.get(), senderPlayer.get()) && !senderPlayer.get().hasPermission(Permission.SEND_VANISHED))) {
6161
if (context == Context.CHANNEL) {
6262
final @NotNull Player player = Objects.requireNonNull(sender.getPlayer());
6363
Message.exitChannel(player);

src/main/java/pro/cloudnode/smp/cloudnodemsg/command/MessageCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public boolean run(final @NotNull CommandSender sender, final @NotNull String la
4444
return sendMessage(player, CloudnodeMSG.getInstance().config().channelClosed(player.getName(), Optional.ofNullable(recipientOffline.getName()).orElse("Unknown Player"), label));
4545
}
4646
}
47-
if (recipient.isEmpty() || (CloudnodeMSG.isVanished(recipient.get()) && !player.hasPermission(Permission.SEND_VANISHED))) return new PlayerNotFoundError(args[0]).send(player);
47+
if (recipient.isEmpty() || (CloudnodeMSG.isVanished(recipient.get(), player) && !player.hasPermission(Permission.SEND_VANISHED))) return new PlayerNotFoundError(args[0]).send(player);
4848
if (!Message.isIncomingEnabled(recipient.get())) return new PlayerHasIncomingDisabledError(recipient.get().getName()).send(player);
4949
Message.createChannel(player, recipient.get());
5050
return sendMessage(player, CloudnodeMSG.getInstance().config().channelCreated(player.getName(), recipient.get().getName(), label));

0 commit comments

Comments
 (0)