use of POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage 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;
}
use of POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method encounterTutorialComplete.
/**
* Encounter tutorial complete. In other words, catch the first Pokémon
*
* @throws RequestFailedException if an exception occurred while sending requests
*/
public void encounterTutorialComplete() throws RequestFailedException {
StarterPokemon starter = StarterPokemon.random();
List<TutorialListener> listeners = api.getListeners(TutorialListener.class);
for (TutorialListener listener : listeners) {
StarterPokemon pokemon = listener.selectStarter(api);
if (pokemon != null) {
starter = pokemon;
break;
}
}
final EncounterTutorialCompleteMessage.Builder builder = EncounterTutorialCompleteMessage.newBuilder().setPokemonId(starter.pokemon);
ServerRequest request = new ServerRequest(RequestType.ENCOUNTER_TUTORIAL_COMPLETE, builder.build());
api.requestHandler.sendServerRequests(request, true);
final GetPlayerMessage getPlayerReqMsg = GetPlayerMessage.newBuilder().setPlayerLocale(playerLocale.getPlayerLocale()).build();
request = new ServerRequest(RequestType.GET_PLAYER, getPlayerReqMsg);
api.requestHandler.sendServerRequests(request, true);
try {
updateProfile(GetPlayerResponse.parseFrom(request.getData()));
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
use of POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method updateProfile.
/**
* Updates the player profile with the latest data.
*
* @throws RequestFailedException if an exception occurred while sending requests
*/
public void updateProfile() throws RequestFailedException {
GetPlayerMessage message = GetPlayerMessage.newBuilder().setPlayerLocale(playerLocale.getPlayerLocale()).build();
ServerRequest request = new ServerRequest(RequestType.GET_PLAYER, message);
api.requestHandler.sendServerRequests(request, false);
try {
updateProfile(GetPlayerResponse.parseFrom(request.getData()));
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
}
Aggregations