package dev.crucifixbeta.mod.commands.impl;

import dev.crucifixbeta.mod.commands.Command;
import java.util.List;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.screen.multiplayer.ConnectScreen;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.network.listener.ClientCommonPacketListener;
import net.minecraft.network.packet.s2c.common.DisconnectS2CPacket;
import net.minecraft.text.Text;

@Environment(EnvType.CLIENT)
public class RejoinCommand extends Command {

   public RejoinCommand() {
      super("rejoin", "");
   }

   @Override
   public void runCommand(String[] parameters) {
      mc.executeTask(() -> {
         if (mc.world != null && mc.getCurrentServerEntry() != null) {
            ServerInfo var0 = mc.getCurrentServerEntry();
            new DisconnectS2CPacket(Text.of("Self kick")).apply((ClientCommonPacketListener)mc.getNetworkHandler());
            ConnectScreen.connect(new TitleScreen(), mc, ServerAddress.parse(var0.address), var0, false, null);
         }
      });
   }

   @Override
   public String[] getAutocorrect(int count, List<String> seperated) {
      return null;
   }
}
