|
1 | 1 | package pro.cloudnode.smp.cloudnodemsg.command; |
2 | 2 |
|
| 3 | +import org.bukkit.OfflinePlayer; |
3 | 4 | import org.bukkit.command.CommandSender; |
4 | 5 | import org.bukkit.entity.Player; |
5 | 6 | import org.jetbrains.annotations.NotNull; |
@@ -32,16 +33,16 @@ public boolean run(final @NotNull CommandSender sender, final @NotNull String la |
32 | 33 |
|
33 | 34 | final @NotNull Optional<@NotNull Player> recipient = Optional.ofNullable(CloudnodeMSG.getInstance().getServer() |
34 | 35 | .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())) |
38 | 37 | return new MessageYourselfError().send(sender); |
39 | 38 | if (args.length == 1) { |
40 | 39 | 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)) { |
42 | 42 | 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)); |
44 | 44 | } |
| 45 | + if (recipient.isEmpty() || (CloudnodeMSG.isVanished(recipient.get()) && !player.hasPermission(Permission.SEND_VANISHED))) return new PlayerNotFoundError(args[0]).send(player); |
45 | 46 | Message.createChannel(player, recipient.get()); |
46 | 47 | return sendMessage(player, CloudnodeMSG.getInstance().config().channelCreated(player.getName(), recipient.get().getName(), label)); |
47 | 48 | } |
|
0 commit comments