/** @param player */
  public static void onPlayerLogin(Player player) {
    int worldId = player.getWorldId();

    WorldMapTemplate worldTemplate = DataManager.WORLD_MAPS_DATA.getTemplate(worldId);
    if (worldTemplate.isInstance()) {
      PortalTemplate portalTemplate =
          DataManager.PORTAL_DATA.getInstancePortalTemplate(
              worldId, player.getCommonData().getRace());

      if (portalTemplate == null) {
        log.error("No portal template found for " + worldId);
        return;
      }

      int lookupId = player.getObjectId();
      if (portalTemplate.isGroup() && player.getPlayerGroup() != null) {
        lookupId = player.getPlayerGroup().getGroupId();
      }

      WorldMapInstance registeredInstance = getRegisteredInstance(worldId, lookupId);
      if (registeredInstance != null) {
        World.getInstance()
            .setPosition(
                player,
                worldId,
                registeredInstance.getInstanceId(),
                player.getX(),
                player.getY(),
                player.getZ(),
                player.getHeading());
        return;
      }

      moveToEntryPoint(player, portalTemplate, false);
    }
  }
  /**
   * @param player
   * @param portalTemplates
   */
  private static void moveToEntryPoint(
      Player player, PortalTemplate portalTemplate, boolean useTeleport) {
    EntryPoint entryPoint = null;
    List<EntryPoint> entryPoints = portalTemplate.getEntryPoint();

    for (EntryPoint point : entryPoints) {
      if (point.getRace() == null || point.getRace().equals(player.getCommonData().getRace())) {
        entryPoint = point;
        break;
      }
    }

    if (entryPoint == null) {
      log.warn(
          "Entry point not found for "
              + player.getCommonData().getRace()
              + " "
              + player.getWorldId());
      return;
    }

    if (useTeleport) {
      TeleportService.teleportTo(
          player,
          entryPoint.getMapId(),
          1,
          entryPoint.getX(),
          entryPoint.getY(),
          entryPoint.getZ(),
          0);
    } else {
      World.getInstance()
          .setPosition(
              player,
              entryPoint.getMapId(),
              1,
              entryPoint.getX(),
              entryPoint.getY(),
              entryPoint.getZ(),
              player.getHeading());
    }
  }