|
| 1 | +package pro.cloudnode.smp.smpcore.command; |
| 2 | + |
| 3 | +import org.bukkit.command.CommandSender; |
| 4 | +import org.bukkit.entity.Player; |
| 5 | +import org.jetbrains.annotations.NotNull; |
| 6 | +import org.jetbrains.annotations.Nullable; |
| 7 | +import pro.cloudnode.smp.smpcore.Member; |
| 8 | +import pro.cloudnode.smp.smpcore.Nation; |
| 9 | +import pro.cloudnode.smp.smpcore.Permission; |
| 10 | +import pro.cloudnode.smp.smpcore.SMPCore; |
| 11 | + |
| 12 | +import java.util.Arrays; |
| 13 | +import java.util.List; |
| 14 | +import java.util.Optional; |
| 15 | + |
| 16 | +public class CitizensCommand extends Command { |
| 17 | + @Override |
| 18 | + public boolean run( |
| 19 | + final @NotNull CommandSender sender, |
| 20 | + final @NotNull String label, |
| 21 | + @NotNull String @NotNull [] args |
| 22 | + ) { |
| 23 | + if (!sender.hasPermission(Permission.NATION)) |
| 24 | + return sendMessage(sender, SMPCore.messages().errorNoPermission()); |
| 25 | + |
| 26 | + final @NotNull Optional<@NotNull Member> member = sender instanceof final @NotNull Player player ? Member.get( |
| 27 | + player) : Optional.empty(); |
| 28 | + |
| 29 | + final @NotNull Optional<@NotNull Nation> nation; |
| 30 | + if (args.length > 0 && args[0].startsWith("id:")) { |
| 31 | + final @NotNull String id = args[0].substring(3); |
| 32 | + nation = Nation.get(id); |
| 33 | + args = Arrays.copyOfRange(args, 1, args.length); |
| 34 | + if (nation.isEmpty()) |
| 35 | + return sendMessage(sender, SMPCore.messages().errorNationNotFound(id)); |
| 36 | + } |
| 37 | + else |
| 38 | + nation = member.flatMap(Member::nation); |
| 39 | + |
| 40 | + if (nation.isEmpty()) |
| 41 | + return sendMessage(sender, SMPCore.messages().errorNotCitizen()); |
| 42 | + |
| 43 | + if (args.length == 0) |
| 44 | + return NationCommand.citizensSubcommands(member.orElse(null), nation.get(), sender, label); |
| 45 | + |
| 46 | + return NationCommand.citizens(member.orElse(null), nation.get(), sender, label, args); |
| 47 | + } |
| 48 | + |
| 49 | + @Override |
| 50 | + public @Nullable List<@NotNull String> tab( |
| 51 | + final @NotNull CommandSender sender, |
| 52 | + final @NotNull String label, |
| 53 | + final @NotNull String @NotNull [] args |
| 54 | + ) { |
| 55 | + return List.of(); |
| 56 | + } |
| 57 | +} |
0 commit comments