Пример #1
0
  @Override
  public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
    UserProfileProvider result = new UserProfileProvider();
    result.setUserType("mojang");
    if (ua.canPlayOnline()) {
      result.setUserName(info.username);
      result.setUserId(UUIDTypeAdapter.fromUUID(ua.getSelectedProfile().id));
    } else {
      String usr = info.username;
      if (info.username == null || !info.username.contains("@"))
        throw new AuthenticationException(C.i18n("login.not_email"));
      String pwd = info.password;

      if (!ua.isLoggedIn()) ua.setPassword(pwd);
      ua.setUsername(usr);
      ua.logIn();
      if (!ua.isLoggedIn()) throw new AuthenticationException(C.i18n("login.wrong_password"));
      GameProfile selectedProfile = ua.getSelectedProfile();
      GameProfile[] profiles = ua.getAvailableProfiles();
      String username;
      if (selectedProfile == null)
        if (ArrayUtils.isNotEmpty(profiles)) {
          String[] names = new String[profiles.length];
          for (int i = 0; i < profiles.length; i++) names[i] = profiles[i].name;
          Selector s = new Selector(null, names, C.i18n("login.choose_charactor"));
          s.setVisible(true);
          selectedProfile = profiles[s.sel];
          username = names[s.sel];
        } else username = JOptionPane.showInputDialog(C.i18n("login.no_charactor"));
      else username = selectedProfile.name;
      result.setUserName(username);
      result.setUserId(
          selectedProfile == null
              ? OfflineAuthenticator.getUUIDFromUserName(username)
              : UUIDTypeAdapter.fromUUID(selectedProfile.id));
    }
    result.setUserProperties(
        new GsonBuilder()
            .registerTypeAdapter(PropertyMap.class, new PropertyMap.LegacySerializer())
            .create()
            .toJson(ua.getUserProperties()));
    result.setUserPropertyMap(
        new GsonBuilder()
            .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
            .create()
            .toJson(ua.getUserProperties()));
    result.setAccessToken(ua.getAuthenticatedToken());
    result.setSession(ua.getAuthenticatedToken());
    return result;
  }
Пример #2
0
 @Override
 public UserProfileProvider loginBySettings() throws AuthenticationException {
   UserProfileProvider result = new UserProfileProvider();
   ua.logIn();
   if (!ua.isLoggedIn()) throw new AuthenticationException(C.i18n("login.wrong_password"));
   GameProfile profile = ua.getSelectedProfile();
   result.setUserName(profile.name);
   result.setUserId(profile.id.toString());
   result.setUserProperties(
       new GsonBuilder()
           .registerTypeAdapter(PropertyMap.class, new PropertyMap.LegacySerializer())
           .create()
           .toJson(ua.getUserProperties()));
   result.setUserPropertyMap(
       new GsonBuilder()
           .registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
           .create()
           .toJson(ua.getUserProperties()));
   result.setAccessToken(ua.getAuthenticatedToken());
   result.setSession(ua.getAuthenticatedToken());
   return result;
 }