|
| 1 | +package pro.cloudnode.smp.cloudnodemsg.command; |
| 2 | + |
| 3 | +import org.bukkit.OfflinePlayer; |
| 4 | +import org.bukkit.command.CommandSender; |
| 5 | +import org.jetbrains.annotations.NotNull; |
| 6 | +import pro.cloudnode.smp.cloudnodemsg.CloudnodeMSG; |
| 7 | +import pro.cloudnode.smp.cloudnodemsg.Permission; |
| 8 | +import pro.cloudnode.smp.cloudnodemsg.error.InvalidPlayerError; |
| 9 | +import pro.cloudnode.smp.cloudnodemsg.error.NoPermissionError; |
| 10 | +import pro.cloudnode.smp.cloudnodemsg.error.NobodyReplyError; |
| 11 | +import pro.cloudnode.smp.cloudnodemsg.error.ReplyOfflineError; |
| 12 | +import pro.cloudnode.smp.cloudnodemsg.message.Message; |
| 13 | + |
| 14 | +import java.util.ArrayList; |
| 15 | +import java.util.List; |
| 16 | +import java.util.Optional; |
| 17 | + |
| 18 | +public final class ReplyCommand extends Command { |
| 19 | + public static final @NotNull String usage = "<message>"; |
| 20 | + |
| 21 | + @Override |
| 22 | + public boolean onCommand(final @NotNull CommandSender sender, final @NotNull org.bukkit.command.Command command, final @NotNull String label, @NotNull String @NotNull [] args) { |
| 23 | + if (!sender.hasPermission(Permission.USE)) return new NoPermissionError().send(sender); |
| 24 | + if (args.length == 0) return sendMessage(sender, CloudnodeMSG.getInstance().config().usage(label, usage)); |
| 25 | + |
| 26 | + final @NotNull Optional<@NotNull OfflinePlayer> recipient = Message.getReplyTo(Message.offlinePlayer(sender)); |
| 27 | + if (recipient.isEmpty()) return new NobodyReplyError().send(sender); |
| 28 | + if (!recipient.get().getUniqueId().equals(Message.console.getUniqueId()) && !recipient.get().isOnline()) return new ReplyOfflineError(Optional.ofNullable(recipient.get().getName()).orElse("Unknown Player")).send(sender); |
| 29 | + |
| 30 | + try { |
| 31 | + new Message(Message.offlinePlayer(sender), recipient.get(), String.join(" ", args)).send(); |
| 32 | + return true; |
| 33 | + } |
| 34 | + catch (final @NotNull InvalidPlayerError e) { |
| 35 | + return e.log().send(sender); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public @NotNull List<@NotNull String> onTabComplete(final @NotNull CommandSender sender, final @NotNull org.bukkit.command.Command command, final @NotNull String label, final @NotNull String @NotNull [] args) { |
| 41 | + return new ArrayList<>(); |
| 42 | + } |
| 43 | +} |
0 commit comments