package dev.crucifixbeta.mod.commands.impl;

import dev.crucifixbeta.mod.commands.Command;
import java.text.DecimalFormat;
import java.util.List;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

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

   public ClipCommand() {
      super("clip", "[x] [y] [z]");
   }

   @Override
   public void runCommand(String[] parameters) {
      if (parameters.length != 3) {
         this.sendUsage();
      } else if (!this.isNumeric(parameters[0])) {
         this.sendUsage();
      } else {
         double var2 = mc.player.getX() + Double.parseDouble(parameters[0]);
         if (!this.isNumeric(parameters[1])) {
            this.sendUsage();
         } else {
            double var4 = mc.player.getY() + Double.parseDouble(parameters[1]);
            if (!this.isNumeric(parameters[2])) {
               this.sendUsage();
            } else {
               double var6 = mc.player.getZ() + Double.parseDouble(parameters[2]);
               mc.player.setPosition(var2, var4, var6);
               DecimalFormat var8 = new DecimalFormat("0.0");
               this.sendChatMessage("§fTeleported to §e" + var8.format(var2) + ", " + var8.format(var4) + ", " + var8.format(var6));
            }
         }
      }
   }

   private boolean isNumeric(String str) {
      return str.matches("-?\\d+(\\.\\d+)?");
   }

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