Skip to content

Commit 4628f8f

Browse files
authored
Improved detection of vanished players (#75)
2 parents af4de6a + d89816b commit 4628f8f

3 files changed

Lines changed: 5 additions & 4 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
@@ -49,7 +49,9 @@ public void onDisable() {
4949
// Plugin shutdown logic
5050
}
5151

52-
public static boolean isVanished(final @NotNull Player player) {
52+
public static boolean isVanished(final @NotNull Player player, final @NotNull Player observer) {
53+
if (!observer.canSee(player))
54+
return true;
5355
for (final @NotNull MetadataValue meta : player.getMetadata("vanished"))
5456
if (meta.asBoolean()) return true;
5557
return false;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +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(
61-
Permissions.SEND_VANISHED))) {
60+
if (!recipient.getUniqueId().equals(console.getUniqueId()) && recipientPlayer.isEmpty() || (recipientPlayer.isPresent() && senderPlayer.isPresent() && CloudnodeMSG.isVanished(recipientPlayer.get(), senderPlayer.get()) && !senderPlayer.get().hasPermission(Permissions.SEND_VANISHED))) {
6261
if (context == Context.CHANNEL) {
6362
final @NotNull Player player = Objects.requireNonNull(sender.getPlayer());
6463
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(Permissions.SEND_VANISHED))) return new PlayerNotFoundError(args[0]).send(player);
47+
if (recipient.isEmpty() || (CloudnodeMSG.isVanished(recipient.get(), player) && !player.hasPermission(Permissions.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)