Skip to content

Commit a5d4733

Browse files
committed
allow disabling msg channel if recipient is now offline
1 parent 0a2de14 commit a5d4733

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package pro.cloudnode.smp.cloudnodemsg.command;
22

3+
import org.bukkit.OfflinePlayer;
34
import org.bukkit.command.CommandSender;
45
import org.bukkit.entity.Player;
56
import org.jetbrains.annotations.NotNull;
@@ -32,16 +33,16 @@ public boolean run(final @NotNull CommandSender sender, final @NotNull String la
3233

3334
final @NotNull Optional<@NotNull Player> recipient = Optional.ofNullable(CloudnodeMSG.getInstance().getServer()
3435
.getPlayer(args[0]));
35-
if (recipient.isEmpty() || (CloudnodeMSG.isVanished(recipient.get()) && !sender.hasPermission(Permission.SEND_VANISHED)))
36-
return new PlayerNotFoundError(args[0]).send(sender);
37-
if (sender instanceof final @NotNull Player player && recipient.get().getUniqueId().equals(player.getUniqueId()))
36+
if (sender instanceof final @NotNull Player player && recipient.isPresent() && recipient.get().getUniqueId().equals(player.getUniqueId()))
3837
return new MessageYourselfError().send(sender);
3938
if (args.length == 1) {
4039
final @NotNull Player player = (Player) sender;
41-
if (Message.getChannel(player).map(r -> r.getUniqueId().equals(recipient.get().getUniqueId())).orElse(false)) {
40+
final @NotNull OfflinePlayer recipientOffline = CloudnodeMSG.getInstance().getServer().getOfflinePlayer(args[0]);
41+
if (Message.getChannel(player).map(r -> r.getUniqueId().equals(recipientOffline.getUniqueId())).orElse(false)) {
4242
Message.exitChannel(player);
43-
return sendMessage(player, CloudnodeMSG.getInstance().config().channelClosed(player.getName(), recipient.get().getName(), label));
43+
return sendMessage(player, CloudnodeMSG.getInstance().config().channelClosed(player.getName(), Optional.ofNullable(recipientOffline.getName()).orElse("Unknown Player"), label));
4444
}
45+
if (recipient.isEmpty() || (CloudnodeMSG.isVanished(recipient.get()) && !player.hasPermission(Permission.SEND_VANISHED))) return new PlayerNotFoundError(args[0]).send(player);
4546
Message.createChannel(player, recipient.get());
4647
return sendMessage(player, CloudnodeMSG.getInstance().config().channelCreated(player.getName(), recipient.get().getName(), label));
4748
}

0 commit comments

Comments
 (0)