Skip to content

Commit

Permalink
Fixed Shell-Only First time run, Updated Console Gui, Navigation Sleeps
Browse files Browse the repository at this point in the history
  • Loading branch information
SippieCup committed Aug 2, 2016
1 parent 2ccbf30 commit 1f673df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
13 changes: 10 additions & 3 deletions src/main/java/dekk/pw/pokemate/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,20 @@ private static CredentialProvider Login(Context context, OkHttpClient httpClient
return new GoogleUserCredentialProvider(httpClient, token, time);
}
} else {
String access;
GoogleUserCredentialProvider provider = new GoogleUserCredentialProvider(httpClient, time);
System.out.println("-----------------------------------------");
System.out.println(" Please go to the following URL");
System.out.println(GoogleUserCredentialProvider.LOGIN_URL);
Desktop.getDesktop().browse(URI.create(GoogleUserCredentialProvider.LOGIN_URL));

String access = JOptionPane.showInputDialog("Enter authorization code: ");
if (Config.isShowUI()) {
Desktop.getDesktop().browse(URI.create(GoogleUserCredentialProvider.LOGIN_URL));
access = JOptionPane.showInputDialog("Enter authorization code: ");
}
else {
System.out.println("Enter authorization code: ");
Scanner sc = new Scanner(System.in);
access = sc.nextLine();
}
provider.login(access);
try (PrintWriter p = new PrintWriter("tokens/" + Context.getUsernameHash() + ".txt")) {
p.println(provider.getRefreshToken());
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/dekk/pw/pokemate/tasks/ConsoleGUIUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;

import static dekk.pw.pokemate.Context.millisToTimeString;
import static dekk.pw.pokemate.util.StringConverter.convertItemAwards;

/**
Expand All @@ -32,12 +33,9 @@ public class ConsoleGUIUpdate extends Task implements Runnable {

@Override
public void run() {
calcXPH();

// Clears old console output. (Probably won't work on windows)
System.out.print("\033[H\033[2J");
System.out.print("Console GUI: [" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "]\n");

System.out.println(header());
context.getConsoleStrings().forEach( (key,value) -> {
if (value.isEmpty()) {
System.out.println(key + ":");
Expand All @@ -48,19 +46,22 @@ public void run() {
context.addTask(new ConsoleGUIUpdate(context));
}

private void calcXPH() {
private String header() {
try {
long runTime = System.currentTimeMillis() - PokeMate.startTime;
long curTotalXP = context.getProfile().getStats().getExperience();

if (curTotalXP > lastExperience) {
if (lastExperience != 0) {
experienceGained += curTotalXP - lastExperience;
context.setConsoleString("Update", String.format("[%s] %5sXP/H", new SimpleDateFormat("HH:mm:ss").format(new Date()), new DecimalFormat("###,###,###").format((experienceGained / (runTime / 3.6E6)))));
context.setConsoleString("Update", String.format("[%s] %5sXP/H", new SimpleDateFormat("HH:mm:ss").format(new Date()), new DecimalFormat("#,###,###").format((experienceGained / (runTime / 3.6E6)))));
}
lastExperience = curTotalXP;
}
int curLevel = context.getProfile().getStats().getLevel();
double nextXP = REQUIRED_EXPERIENCES[context.getProfile().getStats().getLevel()] - REQUIRED_EXPERIENCES[context.getProfile().getStats().getLevel() - 1];
double curLevelXP = context.getProfile().getStats().getExperience() - REQUIRED_EXPERIENCES[context.getProfile().getStats().getLevel() - 1];

if (curLevel > lastLevel) {
PlayerLevelUpRewards rewards = context.getProfile().acceptLevelUpRewards(curLevel - 1);
if (rewards.getStatus() == PlayerLevelUpRewards.Status.NEW) {
Expand All @@ -70,8 +71,12 @@ private void calcXPH() {
}
lastLevel = curLevel;
}

return "Name: " + context.getProfile().getPlayerData().getUsername() + "\tCurrent Level: " + context.getProfile().getStats().getLevel() + " - "+ new DecimalFormat("#,###,###").format((experienceGained / (runTime / 3.6E6))) +
"XP/Hour - XP to next level: " + new DecimalFormat("###,###,###").format(nextXP - curLevelXP) + " Runtime: " + millisToTimeString(runTime);
} catch (LoginFailedException | RemoteServerException e) {
e.printStackTrace();
return "Error Updating Header";
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/dekk/pw/pokemate/tasks/Navigate.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import dekk.pw.pokemate.Config;
import dekk.pw.pokemate.Context;
import dekk.pw.pokemate.Walking;
import dekk.pw.pokemate.util.Time;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
Expand Down Expand Up @@ -69,6 +70,7 @@ public static List<S2LatLng> getRoute() {
*/
private void populateRoute(Context context) {
try {
Time.sleepRate();
List<Pokestop> stops = context.getMap().getMapObjects().getPokestops().stream().filter(a ->
//only pokestops in our region
a.getLatitude() >= min.lat &&
Expand Down

0 comments on commit 1f673df

Please sign in to comment.