use of POGOProtos.Networking.Responses.ClaimCodenameResponseOuterClass.ClaimCodenameResponse in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method claimCodeName.
/**
* Setup an user name for our account
*
* @param lastFailure the last name used that was already taken; null for first try.
* @return the claimed codename
* @throws RequestFailedException if an exception occurred while sending requests
*/
public String claimCodeName(String lastFailure) throws RequestFailedException {
if (getPlayerData().getRemainingCodenameClaims() <= 0) {
throw new RuntimeException("You have no remaining codename claims!");
}
String name = randomCodenameGenerator();
List<TutorialListener> listeners = api.getListeners(TutorialListener.class);
for (TutorialListener listener : listeners) {
String listenerName = listener.claimName(api, lastFailure);
if (listenerName != null) {
name = listenerName;
break;
}
}
ClaimCodenameMessage claimCodenameMessage = ClaimCodenameMessage.newBuilder().setCodename(name).build();
ServerRequest request = new ServerRequest(RequestType.CLAIM_CODENAME, claimCodenameMessage);
api.requestHandler.sendServerRequests(request, true);
String updatedCodename;
try {
ClaimCodenameResponse claimCodenameResponse = ClaimCodenameResponse.parseFrom(request.getData());
if (claimCodenameResponse.getStatus() != ClaimCodenameResponse.Status.SUCCESS) {
return claimCodeName(name);
}
updatedCodename = claimCodenameResponse.getCodename();
if (claimCodenameResponse.hasUpdatedPlayer()) {
updateProfile(claimCodenameResponse.getUpdatedPlayer());
}
if (updatedCodename != null) {
markTutorial(TutorialStateOuterClass.TutorialState.NAME_SELECTION);
final GetPlayerMessage getPlayerReqMsg = GetPlayerMessage.newBuilder().setPlayerLocale(playerLocale.getPlayerLocale()).build();
request = new ServerRequest(RequestType.GET_PLAYER, getPlayerReqMsg);
api.requestHandler.sendServerRequests(request, true);
updateProfile(GetPlayerResponse.parseFrom(request.getData()));
}
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
return updatedCodename;
}
Aggregations