content: package net.alex9849.arm.subregions.commands;
  
  import net.alex9849.arm.AdvancedRegionMarket;
  import net.alex9849.arm.Messages;
  import net.alex9849.arm.Permission;
  import net.alex9849.arm.commands.BasicArmCommand;
  import net.alex9849.arm.exceptions.CmdSyntaxException;
  import net.alex9849.arm.exceptions.InputException;
  import net.alex9849.arm.exceptions.NoSaveLocationException;
  import net.alex9849.arm.minifeatures.PlayerRegionRelationship;
  import net.alex9849.arm.minifeatures.teleporter.Teleporter;
  import net.alex9849.arm.regions.Region;
  import org.bukkit.command.CommandSender;
  import org.bukkit.entity.Player;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.List;
  
  public class TPCommand extends BasicArmCommand {
  
      public TPCommand(AdvancedRegionMarket plugin) {
          super(false, plugin, "tp",
                  Arrays.asList("(?i)tp [^;\n ]+"),
                  Arrays.asList("tp [REGION]"),
                  Arrays.asList(Permission.SUBREGION_TP));
      }
  
      @Override
      protected boolean runCommandLogic(CommandSender sender, String command, String commandLabel) throws InputException, CmdSyntaxException {
          Player player = (Player) sender;
          Region region = getPlugin().getRegionManager()
                  .getRegionbyNameAndWorldCommands(command.split(" ")[1], player.getWorld().getName());
  
          if (region == null) {
              throw new InputException(player, Messages.REGION_DOES_NOT_EXIST);
          }
  
          if (!region.isSubregion()) {
              throw new InputException(sender, Messages.REGION_NOT_A_SUBREGION);
          }
  
          if (!region.getParentRegion().getRegion().hasOwner(player.getUniqueId())) {
              throw new InputException(sender, Messages.PARENT_REGION_NOT_OWN);
          }
  
          try {
              Teleporter.teleport(player, region);
          } catch (NoSaveLocationException e) {
              throw new InputException(sender, Messages.TELEPORTER_NO_SAVE_LOCATION_FOUND);
          }
          return true;
      }
  
      @Override
      protected List<String> onTabCompleteArguments(Player player, String[] args) {
          if(args.length != 2) {
              return new ArrayList<>();
          }
          return getPlugin().getRegionManager()
                  .completeTabRegions(player, args[1], PlayerRegionRelationship.PARENTREGION_OWNER, false, true);
      }
  }
  