|
| 1 | +package me.illusion.skyblockcore.spigot.command.island.invite; |
| 2 | + |
| 3 | +import me.illusion.skyblockcore.shared.data.IslandInvite; |
| 4 | +import me.illusion.skyblockcore.shared.packet.impl.instance.PacketInvitePlayer; |
| 5 | +import me.illusion.skyblockcore.shared.packet.impl.proxy.instance.response.PacketInviteResponse; |
| 6 | +import me.illusion.skyblockcore.spigot.SkyblockPlugin; |
| 7 | +import me.illusion.skyblockcore.spigot.command.SkyblockCommand; |
| 8 | +import org.bukkit.Bukkit; |
| 9 | +import org.bukkit.command.CommandSender; |
| 10 | +import org.bukkit.entity.Player; |
| 11 | + |
| 12 | +import java.util.UUID; |
| 13 | +import java.util.concurrent.CompletableFuture; |
| 14 | + |
| 15 | +public class IslandInviteCommand implements SkyblockCommand { |
| 16 | + |
| 17 | + private final SkyblockPlugin main; |
| 18 | + |
| 19 | + public IslandInviteCommand(SkyblockPlugin main) { |
| 20 | + this.main = main; |
| 21 | + } |
| 22 | + |
| 23 | + @Override |
| 24 | + public String getIdentifier() { |
| 25 | + return "island.invite.*"; |
| 26 | + } |
| 27 | + |
| 28 | + @Override |
| 29 | + public boolean canExecute(CommandSender sender) { |
| 30 | + return sender instanceof Player; |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public void execute(CommandSender sender, String... args) { |
| 35 | + String targetPlayer = args[0]; |
| 36 | + Player player = (Player) sender; |
| 37 | + |
| 38 | + // Check if the target is on the current instance |
| 39 | + Player target = Bukkit.getPlayer(targetPlayer); |
| 40 | + |
| 41 | + if (target == null) { |
| 42 | + // Target might be on the proxy, but is not sure |
| 43 | + return; |
| 44 | + } |
| 45 | + |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + private CompletableFuture<PacketInviteResponse.Response> sendInvite(Player origin, String targetName) { |
| 50 | + return CompletableFuture.supplyAsync(() -> { |
| 51 | + UUID inviteID = UUID.randomUUID(); |
| 52 | + |
| 53 | + PacketInvitePlayer packet = new PacketInvitePlayer(main.getBungeeMessaging().getServerIdentifier(), |
| 54 | + new IslandInvite(inviteID, origin.getUniqueId(), targetName)); |
| 55 | + |
| 56 | + main.getPacketManager().send(packet); |
| 57 | + |
| 58 | + PacketInviteResponse response = main.getPacketManager() |
| 59 | + .await(PacketInviteResponse.class, |
| 60 | + (invite) -> invite.getInvite().getInviteId().equals(inviteID), |
| 61 | + 5); |
| 62 | + |
| 63 | + if (response == null) |
| 64 | + return PacketInviteResponse.Response.RESPONSE_NOT_FOUND; |
| 65 | + |
| 66 | + return response.getResponse(); |
| 67 | + }); |
| 68 | + } |
| 69 | +} |
0 commit comments