public static void doTeleport(EntityPlayerMP player, WarpPoint point) {
    // TODO: Handle teleportation of mounted entity
    player.mountEntity(null);

    if (player.dimension != point.getDimension())
      MinecraftServer.getServer()
          .getConfigurationManager()
          .transferPlayerToDimension(
              player, point.getDimension(), new SimpleTeleporter(point.getWorld()));
    player.playerNetServerHandler.setPlayerLocation(
        point.getX(), point.getY(), point.getZ(), point.getYaw(), point.getPitch());
  }
 public static boolean canTeleportTo(WarpPoint point) {
   if (point.getY() < 0) return false;
   Block block1 =
       point.getWorld().getBlock(point.getBlockX(), point.getBlockY(), point.getBlockZ());
   Block block2 =
       point.getWorld().getBlock(point.getBlockX(), point.getBlockY() + 1, point.getBlockZ());
   boolean block1Free =
       !block1.getMaterial().isSolid()
           || block1.getBlockBoundsMaxX() < 1
           || block1.getBlockBoundsMaxY() > 0;
   boolean block2Free =
       !block2.getMaterial().isSolid()
           || block2.getBlockBoundsMaxX() < 1
           || block2.getBlockBoundsMaxY() > 0;
   return block1Free && block2Free;
 }
 public boolean check() {
   if (playerPos.distance(new WarpPoint(player)) > 0.2) {
     ChatOutputHandler.chatWarning(player, "Teleport cancelled.");
     return true;
   }
   if (System.currentTimeMillis() - start < timeout) {
     return false;
   }
   checkedTeleport(player, point);
   ChatOutputHandler.chatConfirmation(player, "Teleported.");
   return true;
 }
  public static void teleport(EntityPlayerMP player, WarpPoint point) {
    if (point.getWorld() == null) {
      DimensionManager.initDimension(point.getDimension());
      if (point.getWorld() == null) {
        ChatOutputHandler.chatError(
            player, Translator.translate("Unable to teleport! Target dimension does not exist"));
        return;
      }
    }

    // Check permissions
    UserIdent ident = UserIdent.get(player);
    if (!APIRegistry.perms.checkPermission(player, TELEPORT_FROM))
      throw new TranslatedCommandException("You are not allowed to teleport from here.");
    if (!APIRegistry.perms.checkUserPermission(ident, point.toWorldPoint(), TELEPORT_TO))
      throw new TranslatedCommandException("You are not allowed to teleport to that location.");
    if (player.dimension != point.getDimension()
        && !APIRegistry.perms.checkUserPermission(ident, point.toWorldPoint(), TELEPORT_CROSSDIM))
      throw new TranslatedCommandException("You are not allowed to teleport across dimensions.");

    // Get and check teleport cooldown
    int teleportCooldown =
        ServerUtil.parseIntDefault(
                APIRegistry.perms.getUserPermissionProperty(ident, TELEPORT_COOLDOWN), 0)
            * 1000;
    if (teleportCooldown > 0) {
      PlayerInfo pi = PlayerInfo.get(player);
      long cooldownDuration =
          (pi.getLastTeleportTime() + teleportCooldown) - System.currentTimeMillis();
      if (cooldownDuration >= 0) {
        ChatOutputHandler.chatNotification(
            player,
            Translator.format("Cooldown still active. %d seconds to go.", cooldownDuration / 1000));
        return;
      }
    }

    // Get and check teleport warmup
    int teleportWarmup =
        ServerUtil.parseIntDefault(
            APIRegistry.perms.getUserPermissionProperty(ident, TELEPORT_WARMUP), 0);
    if (teleportWarmup <= 0) {
      checkedTeleport(player, point);
      return;
    }

    if (!canTeleportTo(point)) {
      ChatOutputHandler.chatError(
          player, Translator.translate("Unable to teleport! Target location obstructed."));
      return;
    }

    // Setup timed teleport
    tpInfos.put(player.getPersistentID(), new TeleportInfo(player, point, teleportWarmup * 1000));
    ChatOutputHandler.chatNotification(
        player,
        Translator.format(
            "Teleporting. Please stand still for %s.",
            ChatOutputHandler.formatTimeDurationReadable(teleportWarmup, true)));
  }
 public static void doTeleportEntity(Entity entity, WarpPoint point) {
   if (entity.dimension != point.getDimension()) entity.travelToDimension(point.getDimension());
   entity.setLocationAndAngles(
       point.getX(), point.getY(), point.getZ(), point.getYaw(), point.getPitch());
 }
  @Override
  public void parse(final CommandParserArgs arguments) {
    if (arguments.isEmpty()) {
      arguments.confirm("/tpa <player>: Request being teleported to another player");
      arguments.confirm("/tpa <player> <here|x y z>: Propose another player to be teleported");
      return;
    }

    final UserIdent player = arguments.parsePlayer(true);
    if (arguments.isEmpty()) {
      if (arguments.isTabCompletion) return;
      try {
        arguments.confirm(
            Translator.format("Waiting for response by %s", player.getUsernameOrUuid()));
        Questioner.add(
            player.getPlayer(),
            Translator.format(
                "Allow teleporting %s to your location?", arguments.sender.getCommandSenderName()),
            new QuestionerCallback() {
              @Override
              public void respond(Boolean response) {
                if (response == null) arguments.error("TPA request timed out");
                else if (response == false) arguments.error("TPA declined");
                else
                  TeleportHelper.teleport(
                      arguments.senderPlayer, new WarpPoint(player.getPlayer()));
              }
            },
            20);
      } catch (QuestionerStillActiveException e) {
        throw new QuestionerStillActiveException.CommandException();
      }
      return;
    }

    arguments.tabComplete("here");

    final WarpPoint point;
    final String locationName;
    if (arguments.peek().equalsIgnoreCase("here")) {
      arguments.checkPermission(PERM_HERE);
      point = new WarpPoint(arguments.senderPlayer);
      locationName = arguments.sender.getCommandSenderName();
      arguments.remove();
    } else {
      arguments.checkPermission(PERM_LOCATION);
      point =
          new WarpPoint(
              (WorldServer) arguments.senderPlayer.worldObj, //
              arguments.parseDouble(),
              arguments.parseDouble(),
              arguments.parseDouble(), //
              player.getPlayer().rotationPitch,
              player.getPlayer().rotationYaw);
      locationName = point.toReadableString();
    }

    if (arguments.isTabCompletion) return;
    try {
      Questioner.add(
          player.getPlayer(),
          Translator.format("Do you want to be teleported to %s?", locationName),
          new QuestionerCallback() {
            @Override
            public void respond(Boolean response) {
              if (response == null) arguments.error("TPA request timed out");
              else if (response == false) arguments.error("TPA declined");
              else TeleportHelper.teleport(player.getPlayerMP(), point);
            }
          },
          20);
    } catch (QuestionerStillActiveException e) {
      throw new QuestionerStillActiveException.CommandException();
    }
  }