├── .gitattributes ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .gitmodules ├── .travis.yml ├── LICENSE.txt ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── build.gradle ├── config │ ├── checkstyle.xml │ └── suppressions.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── pokegoapi │ │ │ ├── api │ │ │ ├── PokemonGo.java │ │ │ ├── device │ │ │ │ ├── ActivityStatus.java │ │ │ │ ├── DeviceInfo.java │ │ │ │ ├── DeviceInfos.java │ │ │ │ ├── LocationFixes.java │ │ │ │ ├── SensorInfo.java │ │ │ │ └── SensorInfos.java │ │ │ ├── gym │ │ │ │ ├── Battle.java │ │ │ │ └── Gym.java │ │ │ ├── inventory │ │ │ │ ├── CandyJar.java │ │ │ │ ├── EggIncubator.java │ │ │ │ ├── Hatchery.java │ │ │ │ ├── Inventories.java │ │ │ │ ├── Item.java │ │ │ │ ├── ItemBag.java │ │ │ │ ├── PokeBank.java │ │ │ │ ├── Pokeball.java │ │ │ │ ├── Pokedex.java │ │ │ │ └── Stats.java │ │ │ ├── listener │ │ │ │ ├── HeartbeatListener.java │ │ │ │ ├── Listener.java │ │ │ │ ├── LocationListener.java │ │ │ │ ├── LoginListener.java │ │ │ │ ├── PlayerListener.java │ │ │ │ ├── PokemonListener.java │ │ │ │ ├── PokestopListener.java │ │ │ │ ├── RequestInterceptor.java │ │ │ │ └── TutorialListener.java │ │ │ ├── map │ │ │ │ ├── Map.java │ │ │ │ ├── MapObjects.java │ │ │ │ ├── Point.java │ │ │ │ ├── fort │ │ │ │ │ ├── Fort.java │ │ │ │ │ ├── FortDetails.java │ │ │ │ │ ├── Pokestop.java │ │ │ │ │ ├── PokestopLootResult.java │ │ │ │ │ └── Raid.java │ │ │ │ └── pokemon │ │ │ │ │ ├── CatchablePokemon.java │ │ │ │ │ ├── DiskEncounter.java │ │ │ │ │ ├── Encounter.java │ │ │ │ │ ├── EncounterResult.java │ │ │ │ │ ├── EvolutionResult.java │ │ │ │ │ ├── IncenseEncounter.java │ │ │ │ │ ├── NearbyPokemon.java │ │ │ │ │ └── ThrowProperties.java │ │ │ ├── news │ │ │ │ └── News.java │ │ │ ├── player │ │ │ │ ├── Avatar.java │ │ │ │ ├── ContactSettings.java │ │ │ │ ├── DailyBonus.java │ │ │ │ ├── Medal.java │ │ │ │ ├── PlayerAvatar.java │ │ │ │ ├── PlayerGender.java │ │ │ │ ├── PlayerLevelUpRewards.java │ │ │ │ ├── PlayerLocale.java │ │ │ │ ├── PlayerProfile.java │ │ │ │ ├── Team.java │ │ │ │ └── TutorialState.java │ │ │ ├── pokemon │ │ │ │ ├── Buddy.java │ │ │ │ ├── EggPokemon.java │ │ │ │ ├── Evolution.java │ │ │ │ ├── Evolutions.java │ │ │ │ ├── HatchedEgg.java │ │ │ │ ├── MovementType.java │ │ │ │ ├── Pokemon.java │ │ │ │ ├── PokemonClass.java │ │ │ │ ├── PokemonCpUtils.java │ │ │ │ ├── PokemonDetails.java │ │ │ │ ├── PokemonType.java │ │ │ │ └── StarterPokemon.java │ │ │ └── settings │ │ │ │ ├── FortSettings.java │ │ │ │ ├── GpsSettings.java │ │ │ │ ├── InventorySettings.java │ │ │ │ ├── LevelUpSettings.java │ │ │ │ ├── MapSettings.java │ │ │ │ ├── PokeballSelector.java │ │ │ │ ├── Settings.java │ │ │ │ └── templates │ │ │ │ ├── DirectTemplateProvider.java │ │ │ │ ├── FileTemplateProvider.java │ │ │ │ ├── ItemTemplateProvider.java │ │ │ │ ├── ItemTemplates.java │ │ │ │ └── TempFileTemplateProvider.java │ │ │ ├── auth │ │ │ ├── CredentialProvider.java │ │ │ ├── GoogleAuthJson.java │ │ │ ├── GoogleAuthTokenJson.java │ │ │ ├── GoogleAutoCredentialProvider.java │ │ │ ├── GoogleCredentialProvider.java │ │ │ ├── GoogleUserCredentialProvider.java │ │ │ ├── PtcAuthError.java │ │ │ ├── PtcAuthJson.java │ │ │ └── PtcCredentialProvider.java │ │ │ ├── exceptions │ │ │ ├── AsyncPokemonGoException.java │ │ │ ├── EncounterFailedException.java │ │ │ ├── InsufficientLevelException.java │ │ │ ├── InvalidCurrencyException.java │ │ │ ├── NoSuchItemException.java │ │ │ └── request │ │ │ │ ├── BadRequestException.java │ │ │ │ ├── BannedException.java │ │ │ │ ├── CaptchaActiveException.java │ │ │ │ ├── HashException.java │ │ │ │ ├── HashLimitExceededException.java │ │ │ │ ├── HashUnauthorizedException.java │ │ │ │ ├── InvalidCredentialsException.java │ │ │ │ ├── LoginFailedException.java │ │ │ │ └── RequestFailedException.java │ │ │ ├── google │ │ │ └── common │ │ │ │ └── geometry │ │ │ │ ├── MutableInteger.java │ │ │ │ ├── R1Interval.java │ │ │ │ ├── R2Vector.java │ │ │ │ ├── S1Angle.java │ │ │ │ ├── S1Interval.java │ │ │ │ ├── S2.java │ │ │ │ ├── S2AreaCentroid.java │ │ │ │ ├── S2Cap.java │ │ │ │ ├── S2Cell.java │ │ │ │ ├── S2CellId.java │ │ │ │ ├── S2CellUnion.java │ │ │ │ ├── S2Edge.java │ │ │ │ ├── S2EdgeIndex.java │ │ │ │ ├── S2EdgeUtil.java │ │ │ │ ├── S2LatLng.java │ │ │ │ ├── S2LatLngRect.java │ │ │ │ ├── S2Point.java │ │ │ │ ├── S2Polyline.java │ │ │ │ ├── S2Projections.java │ │ │ │ ├── S2Region.java │ │ │ │ ├── S2RegionCoverer.java │ │ │ │ └── Utils.java │ │ │ ├── main │ │ │ ├── CommonRequests.java │ │ │ ├── Heartbeat.java │ │ │ ├── RequestHandler.java │ │ │ ├── RequestIdGenerator.java │ │ │ ├── ResultOrException.java │ │ │ ├── ServerPlatformRequest.java │ │ │ ├── ServerRequest.java │ │ │ ├── ServerRequestEnvelope.java │ │ │ ├── ServerResponse.java │ │ │ └── Utils.java │ │ │ └── util │ │ │ ├── AsyncHelper.java │ │ │ ├── BaseLogger.java │ │ │ ├── CaptchaSolveHelper.java │ │ │ ├── ClientInterceptor.java │ │ │ ├── Log.java │ │ │ ├── Logger.java │ │ │ ├── MapPoint.java │ │ │ ├── MapUtil.java │ │ │ ├── NiaHash.java │ │ │ ├── PokeDictionary.java │ │ │ ├── PokeNames.java │ │ │ ├── Signature.java │ │ │ ├── SystemTimeImpl.java │ │ │ ├── Time.java │ │ │ ├── UInt128.java │ │ │ ├── hash │ │ │ ├── Hash.java │ │ │ ├── HashProvider.java │ │ │ ├── crypto │ │ │ │ ├── Crypto.java │ │ │ │ ├── Shuffle.java │ │ │ │ └── TwoFish.java │ │ │ ├── legacy │ │ │ │ └── LegacyHashProvider.java │ │ │ └── pokehash │ │ │ │ ├── PokeHashKey.java │ │ │ │ └── PokeHashProvider.java │ │ │ └── path │ │ │ └── Path.java │ └── resources │ │ ├── item_names.properties │ │ ├── item_names_de.properties │ │ ├── item_names_en.properties │ │ ├── item_names_es.properties │ │ ├── item_names_fr.properties │ │ ├── item_names_it.properties │ │ ├── item_names_ja.properties │ │ ├── item_names_ko.properties │ │ ├── pokemon_descriptions.properties │ │ ├── pokemon_descriptions_de.properties │ │ ├── pokemon_descriptions_en.properties │ │ ├── pokemon_descriptions_es.properties │ │ ├── pokemon_descriptions_fr.properties │ │ ├── pokemon_descriptions_it.properties │ │ ├── pokemon_descriptions_ja.properties │ │ ├── pokemon_descriptions_ko.properties │ │ ├── pokemon_names.properties │ │ ├── pokemon_names_de.properties │ │ ├── pokemon_names_en.properties │ │ ├── pokemon_names_es.properties │ │ ├── pokemon_names_fr.properties │ │ ├── pokemon_names_it.properties │ │ ├── pokemon_names_ja.properties │ │ ├── pokemon_names_ko.properties │ │ ├── pokemon_names_ru.properties │ │ ├── pokemon_names_zh_CN.properties │ │ ├── pokemon_names_zh_HK.properties │ │ └── pokemon_names_zh_TW.properties │ └── resources │ └── .gitignore ├── project_code_style.xml ├── sample ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── pokegoapi │ └── examples │ ├── CatchPokemonAtAreaExample.java │ ├── CheckEvolutionExample.java │ ├── DisplayPokenameExample.java │ ├── ExampleConstants.java │ ├── FightGymExample.java │ ├── GoogleUserInteractionExample.java │ ├── SolveCaptchaExample.java │ ├── TransferMultiplePokemon.java │ ├── TransferOnePidgeyExample.java │ ├── TranslatePokenameExample.java │ ├── TravelToPokestopExample.java │ ├── TutorialHandleExample.java │ └── UseIncenseExample.java └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | Thank you for wanting to help with this project! Pull requests and bug reports are always welcome, there are just some small things you should review before submitting. 3 | 4 | ## Issues 5 | If you find any issue with the library, feel free to open an issue report. If it's just a small issue you might want to consider just asking on Slack (see below). 6 | 7 | ## Feature Requests 8 | You may open an issue also to request new features. Make sure you describe what you are missing in the library and add any pointers someone might need to implement it. 9 | 10 | ## Pull Requests 11 | If you consider submitting a pull request, please note the following: 12 | 13 | 1. All pull requests **must** be submitted to the `Development` branch. The `master` branch is exclusively mutable by release. PRs against `master` will not be merged. 14 | 2. Please make sure you follow the projects code style. To make sure you did, you can use `./gradlew checkstyleMain`. 15 | 3. The project is licensed under [GNU GPLv3](../LICENSE.txt) thus all code you submit will be subject to this license. 16 | 17 | ## Contact 18 | If you have any questions regarding the library you can ask those on the `#javaapi` channel on the [Pokemon GO Reverse Engineering Slack](https://pkre.slack.com/). You can [get your invite here](https://shielded-earth-81203.herokuapp.com/). 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | [Short description of the issue observed. If this is a feature request you can modify the template as required.] 3 | 4 | **Steps to reproduce:** 5 | 6 | 1. [Step 1] 7 | 2. [Step 2] 8 | 9 | **Expected behavior:** 10 | [What should happen?] 11 | 12 | **Actual behavior:** 13 | [What actually happens] 14 | 15 | **Stacktrace (If it's a crash):** 16 | [Please use pastebin if it's too long] 17 | 18 | **Version:** 19 | [The version of the lib you used] 20 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Prerequisites (Remove this section if you want) 2 | Make sure you... 3 | 4 | * Follow the [contribution guidelines](CONTRIBUTING.md) 5 | * Follow the code style (run `./gradlew checkstyleMain`) 6 | * Submit this PR against the `Development` branch. 7 | 8 | **Fixed issue:** [Reference the issue number here, or remove if not a fix] 9 | 10 | **Changes made:** 11 | 12 | * List your changes here 13 | * Change 2... -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ######## 2 | 3 | This file is a general collection of gitignore rules compiled from the 4 | collection at . I have put it together to 5 | serve as a standard template for any Bapcraft Java projects. 6 | 7 | - Treyzania (2016-04-23) 8 | 9 | ######## 10 | 11 | ### Java 12 | *.class 13 | 14 | # Mobile Tools for Java (J2ME) 15 | .mtj.tmp/ 16 | 17 | # Package Files # 18 | *.jar 19 | *.war 20 | *.ear 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | 25 | ### Maven 26 | target/ 27 | pom.xml.tag 28 | pom.xml.releaseBackup 29 | pom.xml.versionsBackup 30 | pom.xml.next 31 | release.properties 32 | dependency-reduced-pom.xml 33 | buildNumber.properties 34 | .mvn/timing.properties 35 | 36 | ### Gradle 37 | .gradle 38 | build/ 39 | 40 | # Ignore Gradle GUI config 41 | gradle-app.setting 42 | 43 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 44 | !gradle-wrapper.jar 45 | 46 | # Cache of project 47 | .gradletasknamecache 48 | 49 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 50 | # gradle/wrapper/gradle-wrapper.properties 51 | 52 | ### Eclipse 53 | .metadata 54 | bin/ 55 | tmp/ 56 | *.tmp 57 | *.bak 58 | *.swp 59 | *~.nib 60 | local.properties 61 | .settings/ 62 | .loadpath 63 | .recommenders 64 | .classpath 65 | 66 | 67 | # Eclipse Core 68 | .project 69 | 70 | # External tool builders 71 | .externalToolBuilders/ 72 | 73 | # Locally stored "Eclipse launch configurations" 74 | *.launch 75 | 76 | # PyDev specific (Python IDE for Eclipse) 77 | *.pydevproject 78 | 79 | # CDT-specific (C/C++ Development Tooling) 80 | .cproject 81 | 82 | # JDT-specific (Eclipse Java Development Tools) 83 | .classpath 84 | 85 | # Java annotation processor (APT) 86 | .factorypath 87 | 88 | # PDT-specific (PHP Development Tools) 89 | .buildpath 90 | 91 | # sbteclipse plugin 92 | .target 93 | 94 | # Tern plugin 95 | .tern-project 96 | 97 | # TeXlipse plugin 98 | .texlipse 99 | 100 | # STS (Spring Tool Suite) 101 | .springBeans 102 | 103 | # Code Recommenders 104 | .recommenders/ 105 | 106 | ### JetBrains (All) 107 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 108 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 109 | 110 | # User-specific stuff: 111 | .idea/workspace.xml 112 | .idea/tasks.xml 113 | .idea/dictionaries 114 | .idea/vcs.xml 115 | .idea/jsLibraryMappings.xml 116 | 117 | # Sensitive or high-churn files: 118 | .idea/dataSources.ids 119 | .idea/dataSources.xml 120 | .idea/dataSources.local.xml 121 | .idea/sqlDataSources.xml 122 | .idea/dynamic.xml 123 | .idea/uiDesigner.xml 124 | 125 | # Gradle: 126 | .idea/gradle.xml 127 | .idea/libraries 128 | 129 | # Mongo Explorer plugin: 130 | .idea/mongoSettings.xml 131 | 132 | ## File-based project format: 133 | *.iws 134 | 135 | ## Plugin-specific files: 136 | 137 | # IntelliJ 138 | /out/ 139 | 140 | # mpeltonen/sbt-idea plugin 141 | .idea_modules/ 142 | 143 | # JIRA plugin 144 | atlassian-ide-plugin.xml 145 | 146 | # Crashlytics plugin (for Android Studio and IntelliJ) 147 | com_crashlytics_export_strings.xml 148 | crashlytics.properties 149 | crashlytics-build.properties 150 | fabric.properties 151 | 152 | # Intellij 153 | .idea/ 154 | 155 | # Mac OS 156 | *.DS_Store 157 | .AppleDouble 158 | .LSOverride 159 | 160 | 161 | *.iml 162 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "library/src/resources/protobuf"] 2 | path = library/src/resources/protobuf 3 | url = https://github.com/Furtif/POGOProtos.git 4 | branch = master 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk8 5 | 6 | branches: 7 | only: 8 | - master 9 | - Development 10 | 11 | before_cache: 12 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 13 | - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ 14 | cache: 15 | directories: 16 | - $HOME/.gradle/caches/ 17 | - $HOME/.gradle/wrapper/ 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | allprojects { 2 | apply plugin: 'java' 3 | group = 'com.pokegoapi' 4 | version = '0.4.1' 5 | archivesBaseName = 'PokeGOAPI' 6 | sourceCompatibility = 1.7 7 | targetCompatibility = 1.7 8 | description = """Pokemon Go Java API""" 9 | repositories { 10 | jcenter() 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Grover-c13/PokeGOAPI-Java/d17889b8b2611b090d5770f6277deaf7d73b4f15/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Sep 08 21:54:26 CEST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.0-all.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/config/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/device/ActivityStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.device; 17 | 18 | import com.google.protobuf.ByteString; 19 | import com.pokegoapi.api.PokemonGo; 20 | 21 | import java.util.Random; 22 | 23 | import POGOProtos.Networking.Envelopes.SignatureOuterClass; 24 | 25 | /** 26 | * Created by fabianterhorst on 22.08.16. 27 | */ 28 | 29 | public class ActivityStatus { 30 | 31 | private SignatureOuterClass.Signature.ActivityStatus.Builder activityStatusBuilder; 32 | 33 | public ActivityStatus() { 34 | activityStatusBuilder = SignatureOuterClass.Signature.ActivityStatus.newBuilder(); 35 | } 36 | 37 | /** 38 | * Gets the default activity status for the given api 39 | * 40 | * @param api the api 41 | * @param random random object 42 | * @return the default activity status for the given api 43 | */ 44 | public static SignatureOuterClass.Signature.ActivityStatus getDefault(PokemonGo api, Random random) { 45 | boolean tilting = random.nextInt() % 2 == 0; 46 | ActivityStatus activityStatus = api.activityStatus; 47 | if (activityStatus == null) { 48 | activityStatus = new ActivityStatus(); 49 | api.activityStatus = activityStatus; 50 | } 51 | activityStatus.setStationary(true); 52 | if (tilting) { 53 | activityStatus.setTilting(true); 54 | } 55 | return activityStatus.getActivityStatus(); 56 | } 57 | 58 | public void setAutomotive(boolean automotive) { 59 | activityStatusBuilder.setAutomotive(automotive); 60 | } 61 | 62 | public void setCycling(boolean cycling) { 63 | activityStatusBuilder.setCycling(cycling); 64 | } 65 | 66 | public void setTilting(boolean tilting) { 67 | activityStatusBuilder.setTilting(tilting); 68 | } 69 | 70 | public void setRunning(boolean running) { 71 | activityStatusBuilder.setRunning(running); 72 | } 73 | 74 | public void setStationary(boolean stationary) { 75 | activityStatusBuilder.setStationary(stationary); 76 | } 77 | 78 | public void setWalking(boolean walking) { 79 | activityStatusBuilder.setWalking(walking); 80 | } 81 | 82 | public void setStartTimeMs(long startTimeMs) { 83 | activityStatusBuilder.setStartTimeMs(startTimeMs); 84 | } 85 | 86 | public void setStatus(ByteString status) { 87 | activityStatusBuilder.setStatus(status); 88 | } 89 | 90 | public void setUnknownStatus(boolean unknownStatus) { 91 | activityStatusBuilder.setUnknownStatus(unknownStatus); 92 | } 93 | 94 | /** 95 | * Gets the activity status builder 96 | * 97 | * @return the activity status builder 98 | */ 99 | public SignatureOuterClass.Signature.ActivityStatus.Builder getBuilder() { 100 | return activityStatusBuilder; 101 | } 102 | 103 | public SignatureOuterClass.Signature.ActivityStatus getActivityStatus() { 104 | return activityStatusBuilder.build(); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/device/DeviceInfos.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.device; 17 | 18 | /** 19 | * Created by fabianterhorst on 08.08.16. 20 | */ 21 | 22 | public interface DeviceInfos { 23 | /** 24 | * adb.exe shell getprop ro.product.board 25 | * 26 | * @return android board name, for example: "angler" 27 | */ 28 | String getAndroidBoardName(); 29 | 30 | /** 31 | * adb.exe shell getprop ro.boot.bootloader 32 | * 33 | * @return android bootloader, for example: "angler-03.58" 34 | */ 35 | String getAndroidBootloader(); 36 | 37 | /** 38 | * adb.exe shell getprop ro.product.brand 39 | * 40 | * @return device brand, for example: "google" 41 | */ 42 | String getDeviceBrand(); 43 | 44 | /** 45 | * adb.exe shell settings get secure android_id 46 | * UUID.randomUUID().toString(); 47 | * 48 | * @return device id, for example: "****************" 49 | */ 50 | String getDeviceId(); 51 | 52 | /** 53 | * adb.exe shell getprop ro.product.model 54 | * 55 | * @return device model, for example: "Nexus 6P" 56 | */ 57 | String getDeviceModel(); 58 | 59 | /** 60 | * adb.exe shell getprop ro.product.name 61 | * 62 | * @return device model identifier, for example: "angler" 63 | */ 64 | String getDeviceModelIdentifier(); 65 | 66 | /** 67 | * Always qcom 68 | * 69 | * @return device boot model, for example: "qcom" 70 | */ 71 | String getDeviceModelBoot(); 72 | 73 | /** 74 | * adb.exe shell getprop ro.product.manufacturer 75 | * 76 | * @return hardware manufacturer, for example: "Huawei" 77 | */ 78 | String getHardwareManufacturer(); 79 | 80 | /** 81 | * adb.exe shell getprop ro.product.model 82 | * 83 | * @return hardware model, for example: "Nexus 6P" 84 | */ 85 | String getHardwareModel(); 86 | 87 | /** 88 | * adb.exe shell getprop ro.product.name 89 | * 90 | * @return firmware brand, for example: "angler" 91 | */ 92 | String getFirmwareBrand(); 93 | 94 | /** 95 | * adb.exe shell getprop ro.build.tags 96 | * 97 | * @return firmware tags, for example: "release-keys" 98 | */ 99 | String getFirmwareTags(); 100 | 101 | /** 102 | * adb.exe shell getprop ro.build.type 103 | * 104 | * @return firmware type, for example: "user" 105 | */ 106 | String getFirmwareType(); 107 | 108 | /** 109 | * adb.exe shell getprop ro.build.fingerprint 110 | * 111 | * @return firmware fingerprint, for example: "google/angler/angler:7.0/NPD90G/3051502:user/release-keys" 112 | */ 113 | String getFirmwareFingerprint(); 114 | } 115 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/device/SensorInfos.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.device; 17 | 18 | /** 19 | * Created by fabianterhorst on 08.08.16. 20 | */ 21 | 22 | public interface SensorInfos { 23 | /** 24 | * @return timestamp snapshot in ms since start 25 | */ 26 | long getTimestampSnapshot(); 27 | 28 | /** 29 | * @return accelerometer axes, always 3 30 | */ 31 | long getAccelerometerAxes(); 32 | 33 | /** 34 | * @return accel normalized x 35 | */ 36 | double getAccelNormalizedX(); 37 | 38 | /** 39 | * @return accel normalized y 40 | */ 41 | double getAccelNormalizedY(); 42 | 43 | /** 44 | * @return accel normalized z 45 | */ 46 | double getAccelNormalizedZ(); 47 | 48 | /** 49 | * @return accel raw x 50 | */ 51 | double getAccelRawX(); 52 | 53 | /** 54 | * @return accel raw y 55 | */ 56 | double getAccelRawY(); 57 | 58 | /** 59 | * @return accel raw z 60 | */ 61 | double getAccelRawZ(); 62 | 63 | /** 64 | * @return angel normalized x 65 | */ 66 | double getAngleNormalizedX(); 67 | 68 | /** 69 | * @return angel normalized y 70 | */ 71 | double getAngleNormalizedY(); 72 | 73 | /** 74 | * @return angel normalized z 75 | */ 76 | double getAngleNormalizedZ(); 77 | 78 | /** 79 | * @return gyroscope raw x 80 | */ 81 | double getGyroscopeRawX(); 82 | 83 | /** 84 | * @return gyroscope raw y 85 | */ 86 | double getGyroscopeRawY(); 87 | 88 | /** 89 | * @return gyroscope raw z 90 | */ 91 | double getGyroscopeRawZ(); 92 | } 93 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/inventory/CandyJar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.inventory; 17 | 18 | import POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId; 19 | import com.pokegoapi.api.PokemonGo; 20 | import lombok.ToString; 21 | 22 | import java.util.Collections; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | @ToString 27 | public class CandyJar { 28 | private final PokemonGo api; 29 | private final Map candies = 30 | Collections.synchronizedMap(new HashMap()); 31 | private final Object lock = new Object(); 32 | 33 | public CandyJar(PokemonGo api) { 34 | this.api = api; 35 | } 36 | 37 | /** 38 | * Resets this candy jar and removes all candies 39 | */ 40 | public void reset() { 41 | synchronized (this.lock) { 42 | candies.clear(); 43 | } 44 | } 45 | 46 | /** 47 | * Sets the number of candies in the jar. 48 | * 49 | * @param family Pokemon family id 50 | * @param candies Amount to set it to 51 | */ 52 | public void setCandy(PokemonFamilyId family, int candies) { 53 | synchronized (this.lock) { 54 | this.candies.put(family, candies); 55 | } 56 | } 57 | 58 | /** 59 | * Adds a candy to the candy jar. 60 | * 61 | * @param family Pokemon family id 62 | * @param amount Amount of candies to add 63 | */ 64 | public void addCandy(PokemonFamilyId family, int amount) { 65 | synchronized (this.lock) { 66 | if (candies.containsKey(family)) { 67 | candies.put(family, candies.get(family) + amount); 68 | } else { 69 | candies.put(family, amount); 70 | } 71 | } 72 | } 73 | 74 | /** 75 | * Remove a candy from the candy jar. 76 | * 77 | * @param family Pokemon family id 78 | * @param amount Amount of candies to remove 79 | */ 80 | public void removeCandy(PokemonFamilyId family, int amount) { 81 | synchronized (this.lock) { 82 | if (candies.containsKey(family)) { 83 | if (candies.get(family) - amount < 0) { 84 | candies.put(family, 0); 85 | } else { 86 | candies.put(family, candies.get(family) - amount); 87 | } 88 | } else { 89 | candies.put(family, 0); 90 | } 91 | } 92 | } 93 | 94 | /** 95 | * Get number of candies from the candyjar. 96 | * 97 | * @param family Pokemon family id 98 | * @return number of candies in jar 99 | */ 100 | public int getCandies(PokemonFamilyId family) { 101 | synchronized (this.lock) { 102 | if (candies.containsKey(family)) { 103 | return this.candies.get(family); 104 | } else { 105 | return 0; 106 | } 107 | } 108 | } 109 | 110 | /** 111 | * Gets all candies in the jar 112 | * 113 | * @return the candies 114 | */ 115 | public Map getCandies() { 116 | synchronized (lock) { 117 | return candies; 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/inventory/Pokeball.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.inventory; 17 | 18 | import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; 19 | import lombok.Getter; 20 | 21 | public enum Pokeball { 22 | POKEBALL(ItemId.ITEM_POKE_BALL, 1.0), 23 | GREATBALL(ItemId.ITEM_GREAT_BALL, 0.4), 24 | ULTRABALL(ItemId.ITEM_ULTRA_BALL, 0.2), 25 | MASTERBALL(ItemId.ITEM_MASTER_BALL, 0.0); 26 | 27 | @Getter 28 | public final ItemId ballType; 29 | @Getter 30 | public final double captureProbability; 31 | 32 | Pokeball(ItemId type, double probability) { 33 | ballType = type; 34 | captureProbability = probability; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/inventory/Pokedex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.inventory; 17 | 18 | import POGOProtos.Data.PokedexEntryOuterClass.PokedexEntry; 19 | import POGOProtos.Enums.PokemonIdOuterClass.PokemonId; 20 | 21 | import java.util.Collections; 22 | import java.util.EnumMap; 23 | import java.util.Map; 24 | 25 | public class Pokedex { 26 | private final Map pokedexMap = 27 | Collections.synchronizedMap(new EnumMap(PokemonId.class)); 28 | private final Object lock = new Object(); 29 | 30 | /** 31 | * Resets the pokedex and removes all entries 32 | */ 33 | public void reset() { 34 | synchronized (this.lock) { 35 | pokedexMap.clear(); 36 | } 37 | } 38 | 39 | /** 40 | * Add/Update a PokdexEntry. 41 | * 42 | * @param entry The entry to add or update 43 | */ 44 | public void add(PokedexEntry entry) { 45 | PokemonId id = PokemonId.forNumber(entry.getPokemonId().getNumber()); 46 | synchronized (this.lock) { 47 | pokedexMap.put(id, entry); 48 | } 49 | } 50 | 51 | /** 52 | * Get a pokedex entry value. 53 | * 54 | * @param pokemonId the ID of the pokemon to get 55 | * @return Entry if in pokedex or null if it doesn't 56 | */ 57 | public PokedexEntry getPokedexEntry(PokemonId pokemonId) { 58 | synchronized (this.lock) { 59 | return pokedexMap.get(pokemonId); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/inventory/Stats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.inventory; 17 | 18 | import POGOProtos.Data.Player.PlayerStatsOuterClass; 19 | import lombok.Getter; 20 | 21 | public class Stats { 22 | @Getter 23 | private PlayerStatsOuterClass.PlayerStats proto; 24 | 25 | public Stats(PlayerStatsOuterClass.PlayerStats proto) { 26 | this.proto = proto; 27 | } 28 | 29 | public int getLevel() { 30 | return proto.getLevel(); 31 | } 32 | 33 | public long getExperience() { 34 | return proto.getExperience(); 35 | } 36 | 37 | public long getPrevLevelXp() { 38 | return proto.getPrevLevelXp(); 39 | } 40 | 41 | public long getNextLevelXp() { 42 | return proto.getNextLevelXp(); 43 | } 44 | 45 | public float getKmWalked() { 46 | return proto.getKmWalked(); 47 | } 48 | 49 | public int getPokemonsEncountered() { 50 | return proto.getPokemonsEncountered(); 51 | } 52 | 53 | public int getUniquePokedexEntries() { 54 | return proto.getUniquePokedexEntries(); 55 | } 56 | 57 | public int getPokemonsCaptured() { 58 | return proto.getPokemonsCaptured(); 59 | } 60 | 61 | public int getEvolutions() { 62 | return proto.getEvolutions(); 63 | } 64 | 65 | public int getPokeStopVisits() { 66 | return proto.getPokeStopVisits(); 67 | } 68 | 69 | public int getPokeballsThrown() { 70 | return proto.getPokeballsThrown(); 71 | } 72 | 73 | public int getEggsHatched() { 74 | return proto.getEggsHatched(); 75 | } 76 | 77 | public int getBigMagikarpCaught() { 78 | return proto.getBigMagikarpCaught(); 79 | } 80 | 81 | public int getBattleAttackWon() { 82 | return proto.getBattleAttackWon(); 83 | } 84 | 85 | public int getBattleAttackTotal() { 86 | return proto.getBattleAttackTotal(); 87 | } 88 | 89 | public int getBattleDefendedWon() { 90 | return proto.getBattleDefendedWon(); 91 | } 92 | 93 | public int getBattleTrainingWon() { 94 | return proto.getBattleTrainingWon(); 95 | } 96 | 97 | public int getBattleTrainingTotal() { 98 | return proto.getBattleTrainingTotal(); 99 | } 100 | 101 | public int getPrestigeRaisedTotal() { 102 | return proto.getPrestigeRaisedTotal(); 103 | } 104 | 105 | public int getPrestigeDroppedTotal() { 106 | return proto.getPrestigeDroppedTotal(); 107 | } 108 | 109 | public int getPokemonDeployed() { 110 | return proto.getPokemonDeployed(); 111 | } 112 | 113 | public int getSmallRattataCaught() { 114 | return proto.getSmallRattataCaught(); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/listener/HeartbeatListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.listener; 17 | 18 | import com.pokegoapi.api.PokemonGo; 19 | import com.pokegoapi.api.map.MapObjects; 20 | 21 | /** 22 | * Listener to handle all heartbeat related events such as map updates 23 | */ 24 | public interface HeartbeatListener extends Listener { 25 | /** 26 | * Called when the map is updated 27 | * 28 | * @param api the current API 29 | * @param mapObjects the updated map objects 30 | */ 31 | void onMapUpdate(PokemonGo api, MapObjects mapObjects); 32 | 33 | /** 34 | * Called when an exception occurs while the map is being updated. 35 | * 36 | * @param api the current API 37 | * @param exception the exception that occurred while updating the map 38 | */ 39 | void onMapUpdateException(PokemonGo api, Exception exception); 40 | } 41 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/listener/Listener.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.listener; 2 | 3 | public interface Listener { 4 | } 5 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/listener/LocationListener.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.listener; 2 | 3 | import com.pokegoapi.api.PokemonGo; 4 | import com.pokegoapi.api.map.Point; 5 | 6 | public interface LocationListener extends Listener { 7 | /** 8 | * Called when the player location updates 9 | * @param api the current api 10 | * @param point the point moved to 11 | */ 12 | void onLocationUpdate(PokemonGo api, Point point); 13 | } 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/listener/LoginListener.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.listener; 2 | 3 | import com.pokegoapi.api.PokemonGo; 4 | 5 | /** 6 | * Listener for all login related events. 7 | */ 8 | public interface LoginListener extends Listener { 9 | /** 10 | * Called when this api performs a successful login via PokemonGo#login 11 | * 12 | * @param api the api that has logged in 13 | */ 14 | void onLogin(PokemonGo api); 15 | 16 | /** 17 | * Called when a challenge is requested. 18 | * 19 | * @param api the current api 20 | * @param challengeURL the challenge url 21 | */ 22 | void onChallenge(PokemonGo api, String challengeURL); 23 | } 24 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/listener/PlayerListener.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.listener; 2 | 3 | import com.pokegoapi.api.PokemonGo; 4 | import com.pokegoapi.api.player.Medal; 5 | import com.pokegoapi.api.player.PlayerProfile; 6 | 7 | /** 8 | * Listener for all player related events. 9 | */ 10 | public interface PlayerListener extends Listener { 11 | /** 12 | * Called when the player levels up 13 | * 14 | * @param api the current api instance 15 | * @param oldLevel the old player level 16 | * @param newLevel the new player level 17 | */ 18 | void onLevelUp(PokemonGo api, int oldLevel, int newLevel); 19 | 20 | /** 21 | * Called when a new medal is awarded or leveled up for the current player 22 | * 23 | * @param api the current api 24 | * @param profile the player receiving this medal 25 | * @param medal the medal awarded 26 | */ 27 | void onMedalAwarded(PokemonGo api, PlayerProfile profile, Medal medal); 28 | 29 | /** 30 | * Called when a warning received 31 | * @param api the current api 32 | */ 33 | void onWarningReceived(PokemonGo api); 34 | } 35 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/listener/PokemonListener.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.listener; 2 | 3 | import POGOProtos.Enums.EncounterTypeOuterClass.EncounterType; 4 | import POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId; 5 | import com.pokegoapi.api.PokemonGo; 6 | import com.pokegoapi.api.inventory.Pokeball; 7 | import com.pokegoapi.api.map.pokemon.CatchablePokemon; 8 | import com.pokegoapi.api.pokemon.HatchedEgg; 9 | 10 | /** 11 | * Listener for all pokemon related events. 12 | */ 13 | public interface PokemonListener extends Listener { 14 | /** 15 | * Called when an egg is hatched. 16 | * 17 | * @param api the current api 18 | * @param hatchedEgg the hatched egg 19 | * @return true if this egg should be removed, if not required for later access via Hatchery#getHatchedEggs 20 | */ 21 | boolean onEggHatch(PokemonGo api, HatchedEgg hatchedEgg); 22 | 23 | /** 24 | * Called when a pokemon is encountered 25 | * 26 | * @param api the current api 27 | * @param encounterId the current encounter id 28 | * @param pokemon the pokemon encountered 29 | * @param encounterType the type of encounter made 30 | */ 31 | void onEncounter(PokemonGo api, long encounterId, CatchablePokemon pokemon, EncounterType encounterType); 32 | 33 | /** 34 | * Called after a miss or pokeball escape when capturing a pokemon. 35 | * 36 | * @param api the current api 37 | * @param pokemon the pokemon being caught 38 | * @param pokeball the pokeball being used 39 | * @param throwCount the current amount of times a pokeball has been thrown 40 | * @return true to abort the capture and false to retry 41 | */ 42 | boolean onCatchEscape(PokemonGo api, CatchablePokemon pokemon, Pokeball pokeball, int throwCount); 43 | 44 | /** 45 | * Called when your buddy pokemon finds candies 46 | * 47 | * @param api the current api 48 | * @param family the candy family type 49 | * @param candyCount the amount of candies found 50 | */ 51 | void onBuddyFindCandy(PokemonGo api, PokemonFamilyId family, int candyCount); 52 | } 53 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/listener/PokestopListener.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.listener; 2 | 3 | import com.pokegoapi.api.map.fort.PokestopLootResult; 4 | import com.pokegoapi.api.map.fort.Fort; 5 | 6 | /** 7 | * Listener for all pokestop related events. 8 | */ 9 | public interface PokestopListener extends Listener { 10 | /** 11 | * Called when a Pokestop is looted 12 | * 13 | * @param result the loot result from this pokestop 14 | * @param pokestop the pokestop being looted 15 | */ 16 | void onLoot(PokestopLootResult result, Fort pokestop); 17 | } 18 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/listener/RequestInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.listener; 17 | 18 | import com.pokegoapi.api.PokemonGo; 19 | import com.pokegoapi.main.ServerRequest; 20 | import com.pokegoapi.main.ServerRequestEnvelope; 21 | import com.pokegoapi.main.ServerResponse; 22 | 23 | /** 24 | * Listener that allows interception of 25 | */ 26 | public interface RequestInterceptor extends Listener { 27 | /** 28 | * Allows removal of individual requests before they are sent 29 | * 30 | * @param api the current api 31 | * @param request the request in question 32 | * @param envelope the envelope containing this request 33 | * @return true to remove and false to keep 34 | */ 35 | boolean shouldRemove(PokemonGo api, ServerRequest request, ServerRequestEnvelope envelope); 36 | 37 | /** 38 | * Allows modification of individual requests before they are sent 39 | * 40 | * @param api the current api 41 | * @param request the request to possibly be modified 42 | * @param envelope the envelope containing the request 43 | * @return a new request to send, or null to keep the original 44 | */ 45 | ServerRequest adaptRequest(PokemonGo api, ServerRequest request, ServerRequestEnvelope envelope); 46 | 47 | /** 48 | * Called when a response is received from the server 49 | * 50 | * @param api the current api 51 | * @param response the response from the server 52 | * @param request the request sent to get this response 53 | */ 54 | void handleResponse(PokemonGo api, ServerResponse response, ServerRequestEnvelope request); 55 | } 56 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/listener/TutorialListener.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.listener; 2 | 3 | import com.pokegoapi.api.PokemonGo; 4 | import com.pokegoapi.api.player.PlayerAvatar; 5 | import com.pokegoapi.api.pokemon.StarterPokemon; 6 | 7 | /** 8 | * Listener for all tutorial and account setup events. 9 | */ 10 | public interface TutorialListener extends Listener { 11 | /** 12 | * Called during the tutorial when you are asked to enter a name. 13 | * 14 | * @param api the current api 15 | * @param lastFailure the last name used that was already taken; null for first try. 16 | * @return a name for the current player, null to pick random 17 | */ 18 | String claimName(PokemonGo api, String lastFailure); 19 | 20 | /** 21 | * Called when the user is required to select a starter pokemon. 22 | * 23 | * @param api the current api 24 | * @return the desired starter pokemon; null to pick random 25 | */ 26 | StarterPokemon selectStarter(PokemonGo api); 27 | 28 | /** 29 | * Called when the user is required to setup an avatar. 30 | * 31 | * @param api the current api 32 | * @return the selected avatar; null to pick random 33 | */ 34 | PlayerAvatar selectAvatar(PokemonGo api); 35 | } 36 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/map/Point.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.map; 17 | 18 | import POGOProtos.Map.SpawnPointOuterClass; 19 | import com.pokegoapi.util.MapPoint; 20 | import lombok.Getter; 21 | import lombok.Setter; 22 | 23 | public class Point implements MapPoint { 24 | @Setter 25 | public double longitude; 26 | @Setter 27 | public double latitude; 28 | 29 | public Point(double latitude, double longitude) { 30 | this.latitude = latitude; 31 | this.longitude = longitude; 32 | } 33 | 34 | public Point(SpawnPointOuterClass.SpawnPoint spawnpoint) { 35 | this.latitude = spawnpoint.getLatitude(); 36 | this.longitude = spawnpoint.getLongitude(); 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | StringBuilder builder = new StringBuilder(); 42 | builder.append(this.latitude); 43 | builder.append(", "); 44 | builder.append(this.longitude); 45 | return builder.toString(); 46 | } 47 | 48 | public double getLatitude() { 49 | return this.latitude; 50 | } 51 | 52 | public double getLongitude() { 53 | return this.longitude; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/map/fort/FortDetails.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.map.fort; 17 | 18 | import POGOProtos.Enums.TeamColorOuterClass; 19 | import POGOProtos.Map.Fort.FortModifierOuterClass; 20 | import POGOProtos.Map.Fort.FortTypeOuterClass; 21 | import POGOProtos.Networking.Responses.FortDetailsResponseOuterClass; 22 | 23 | import com.google.protobuf.ProtocolStringList; 24 | 25 | import java.util.List; 26 | 27 | public class FortDetails { 28 | private FortDetailsResponseOuterClass.FortDetailsResponse proto; 29 | 30 | public FortDetails(FortDetailsResponseOuterClass.FortDetailsResponse proto) { 31 | this.proto = proto; 32 | } 33 | 34 | public String getId() { 35 | return proto.getFortId(); 36 | } 37 | 38 | public TeamColorOuterClass.TeamColor getTeam() { 39 | return proto.getTeamColor(); 40 | } 41 | 42 | public String getName() { 43 | return proto.getName(); 44 | } 45 | 46 | public ProtocolStringList getImageUrl() { 47 | return proto.getImageUrlsList(); 48 | } 49 | 50 | public int getFp() { 51 | return proto.getFp(); 52 | } 53 | 54 | public int getStamina() { 55 | return proto.getStamina(); 56 | } 57 | 58 | public int getMaxStamina() { 59 | return proto.getMaxStamina(); 60 | } 61 | 62 | public FortTypeOuterClass.FortType getFortType() { 63 | return proto.getType(); 64 | } 65 | 66 | public double getLatitude() { 67 | return proto.getLatitude(); 68 | } 69 | 70 | public double getLongitude() { 71 | return proto.getLongitude(); 72 | } 73 | 74 | public String getDescription() { 75 | return proto.getDescription(); 76 | } 77 | 78 | public List getModifier() { 79 | return proto.getModifiersList(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/map/fort/Pokestop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.map.fort; 17 | 18 | import POGOProtos.Inventory.Item.ItemIdOuterClass; 19 | import POGOProtos.Map.Fort.FortDataOuterClass; 20 | import POGOProtos.Map.Fort.FortModifierOuterClass; 21 | import com.pokegoapi.api.PokemonGo; 22 | import com.pokegoapi.exceptions.request.RequestFailedException; 23 | import java.util.List; 24 | 25 | /** 26 | * Created by mjmfighter on 7/20/2016. 27 | */ 28 | public class Pokestop extends Fort { 29 | 30 | /** 31 | * Instantiates a new Pokestop. 32 | * 33 | * @param api the api 34 | * @param fortData the fort data 35 | */ 36 | public Pokestop(PokemonGo api, FortDataOuterClass.FortData fortData) { 37 | super(api, fortData); 38 | } 39 | 40 | /** 41 | * Returns whether this pokestop has an active lure. 42 | * 43 | * @return lure status 44 | */ 45 | /* 46 | @Deprecated 47 | public boolean hasLurePokemon() { 48 | return fortData.hasLureInfo() && fortData.getLureInfo().getLureExpiresTimestampMs() > api.startTime; 49 | }*/ 50 | 51 | /** 52 | * Returns whether or not the lured pokemon is in range. 53 | * 54 | * @return true when the lured pokemon is in range of player 55 | */ 56 | public boolean inRangeForLuredPokemon() { 57 | return getDistance() <= api.settings.mapSettings.pokemonVisibilityRange; 58 | } 59 | 60 | /** 61 | * Returns whether this pokestop has an active lure when detected on map. 62 | * 63 | * @return true if this pokestop currently has a lure active 64 | */ 65 | public boolean hasLure() { 66 | try { 67 | return hasLure(false); 68 | } catch (RequestFailedException e) { 69 | return false; 70 | } 71 | } 72 | 73 | /** 74 | * Returns whether this pokestop has an active lure. 75 | * 76 | * @param updateFortDetails to make a new request and get updated lured status 77 | * @return lure status 78 | * @throws RequestFailedException if an exception occurred while sending requests 79 | */ 80 | public boolean hasLure(boolean updateFortDetails) throws RequestFailedException { 81 | if (updateFortDetails) { 82 | List modifiers = getDetails().getModifier(); 83 | for (FortModifierOuterClass.FortModifier modifier : modifiers) { 84 | if (modifier.getItemId() == ItemIdOuterClass.ItemId.ITEM_TROY_DISK) { 85 | return true; 86 | } 87 | } 88 | return false; 89 | } 90 | 91 | return fortData.getActiveFortModifierList().contains(ItemIdOuterClass.ItemId.ITEM_TROY_DISK); 92 | } 93 | 94 | @Override 95 | public int hashCode() { 96 | return getId().hashCode(); 97 | } 98 | 99 | @Override 100 | public boolean equals(Object obj) { 101 | return obj instanceof Pokestop && ((Pokestop) obj).getId().equals(getId()); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/map/fort/PokestopLootResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.map.fort; 17 | 18 | import POGOProtos.Data.PokemonDataOuterClass; 19 | import POGOProtos.Inventory.Item.ItemAwardOuterClass.ItemAward; 20 | import POGOProtos.Networking.Responses.FortSearchResponseOuterClass; 21 | import POGOProtos.Networking.Responses.FortSearchResponseOuterClass.FortSearchResponse.Result; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * Created by mjmfighter on 7/20/2016. 27 | */ 28 | public class PokestopLootResult { 29 | 30 | private FortSearchResponseOuterClass.FortSearchResponse response; 31 | 32 | public PokestopLootResult(FortSearchResponseOuterClass.FortSearchResponse response) { 33 | this.response = response; 34 | } 35 | 36 | public boolean wasSuccessful() { 37 | return response.getResult() == Result.SUCCESS || response.getResult() == Result.INVENTORY_FULL; 38 | } 39 | 40 | public Result getResult() { 41 | return response.getResult(); 42 | } 43 | 44 | public List getItemsAwarded() { 45 | return response.getItemsAwardedList(); 46 | } 47 | 48 | public int getExperience() { 49 | return response.getExperienceAwarded(); 50 | } 51 | 52 | public boolean hasEgg() { 53 | return response.hasPokemonDataEgg(); 54 | } 55 | 56 | public PokemonDataOuterClass.PokemonData getEgg() { 57 | return response.getPokemonDataEgg(); 58 | } 59 | 60 | public FortSearchResponseOuterClass.FortSearchResponse toPrimitive() { 61 | return response; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/map/fort/Raid.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.map.fort; 17 | 18 | import POGOProtos.Data.PokemonDataOuterClass.PokemonData; 19 | import POGOProtos.Data.Raid.RaidInfoOuterClass.RaidInfo; 20 | import POGOProtos.Enums.RaidLevelOuterClass.RaidLevel; 21 | import com.pokegoapi.api.PokemonGo; 22 | import com.pokegoapi.api.gym.Gym; 23 | import lombok.Getter; 24 | 25 | public class Raid { 26 | private final PokemonGo api; 27 | @Getter 28 | private final Gym gym; 29 | @Getter 30 | private final RaidInfo raidInfo; 31 | 32 | /** 33 | * Raid Constructor. 34 | * 35 | * @param api set api 36 | * @param gym set gym 37 | * @param raidInfo set raidInfo 38 | */ 39 | public Raid(PokemonGo api, Gym gym, RaidInfo raidInfo) { 40 | this.api = api; 41 | this.gym = gym; 42 | this.raidInfo = raidInfo; 43 | } 44 | 45 | public long getRaidSeed() { 46 | return raidInfo.getRaidSeed(); 47 | } 48 | 49 | public long getRaidSpawnMs() { 50 | return raidInfo.getRaidSpawnMs(); 51 | } 52 | 53 | public long getRaidBattleMs() { 54 | return raidInfo.getRaidBattleMs(); 55 | } 56 | 57 | public long getRaidEndMs() { 58 | return raidInfo.getRaidEndMs(); 59 | } 60 | 61 | public boolean hasRaidPokemon() { 62 | return raidInfo.hasRaidPokemon(); 63 | } 64 | 65 | public PokemonData getRaidPokemon() { 66 | return raidInfo.getRaidPokemon(); 67 | } 68 | 69 | public RaidLevel getRaidLevel() { 70 | return raidInfo.getRaidLevel(); 71 | } 72 | 73 | public boolean getComplete() { 74 | return raidInfo.getComplete(); 75 | } 76 | 77 | public boolean getIsExclusive() { 78 | return raidInfo.getIsExclusive(); 79 | } 80 | 81 | public String getId() { 82 | return gym.getId(); 83 | } 84 | 85 | public double getLatitude() { 86 | return gym.getLatitude(); 87 | } 88 | 89 | public double getLongitude() { 90 | return gym.getLongitude(); 91 | } 92 | 93 | @Override 94 | public int hashCode() { 95 | return getId().hashCode(); 96 | } 97 | 98 | @Override 99 | public boolean equals(Object obj) { 100 | return obj instanceof Raid && ((Raid) obj).getId().equals(getId()); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/map/pokemon/DiskEncounter.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.map.pokemon; 2 | 3 | import POGOProtos.Networking.Requests.Messages.DiskEncounterMessageOuterClass.DiskEncounterMessage; 4 | import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType; 5 | import POGOProtos.Networking.Responses.DiskEncounterResponseOuterClass.DiskEncounterResponse; 6 | import com.google.protobuf.ByteString; 7 | import com.google.protobuf.InvalidProtocolBufferException; 8 | import com.pokegoapi.api.PokemonGo; 9 | import com.pokegoapi.exceptions.request.RequestFailedException; 10 | import com.pokegoapi.main.ServerRequest; 11 | 12 | public class DiskEncounter extends Encounter { 13 | /** 14 | * Creates a DiskEncounter object 15 | * 16 | * @param api the current api 17 | * @param pokemon the pokemon of this encounter 18 | */ 19 | protected DiskEncounter(PokemonGo api, CatchablePokemon pokemon) { 20 | super(api, pokemon); 21 | } 22 | 23 | @Override 24 | public EncounterResult encounter() throws RequestFailedException { 25 | DiskEncounterMessage message = DiskEncounterMessage.newBuilder() 26 | .setEncounterId(pokemon.encounterId) 27 | .setFortId(pokemon.spawnPointId) 28 | .setPlayerLatitude(api.latitude) 29 | .setPlayerLongitude(api.longitude) 30 | .build(); 31 | 32 | ServerRequest request = new ServerRequest(RequestType.DISK_ENCOUNTER, message); 33 | ByteString responseData = api.requestHandler.sendServerRequests(request, true); 34 | 35 | try { 36 | DiskEncounterResponse response = DiskEncounterResponse.parseFrom(responseData); 37 | encounterResult = EncounterResult.from(response.getResult()); 38 | activeItem = response.getActiveItem(); 39 | captureProbabilities = response.getCaptureProbability(); 40 | encounteredPokemon = response.getPokemonData(); 41 | } catch (InvalidProtocolBufferException e) { 42 | throw new RequestFailedException(e); 43 | } 44 | 45 | return encounterResult; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/map/pokemon/EncounterResult.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.map.pokemon; 2 | 3 | import POGOProtos.Networking.Responses.DiskEncounterResponseOuterClass.DiskEncounterResponse; 4 | import POGOProtos.Networking.Responses.EncounterResponseOuterClass.EncounterResponse.Status; 5 | import POGOProtos.Networking.Responses.IncenseEncounterResponseOuterClass.IncenseEncounterResponse; 6 | import lombok.Getter; 7 | 8 | public enum EncounterResult { 9 | ERROR(0), 10 | SUCCESS(1), 11 | NOT_FOUND(2), 12 | CLOSED(3), 13 | POKEMON_FLED(4), 14 | NOT_IN_RANGE(5), 15 | ALREADY_HAPPENED(6), 16 | INVENTORY_FULL(7), 17 | UNRECOGNISED(-1); 18 | 19 | @Getter 20 | private int value; 21 | 22 | EncounterResult(int value) { 23 | this.value = value; 24 | } 25 | 26 | /** 27 | * @param status the status to convert from 28 | * @return EncounterResult from Status 29 | */ 30 | public static EncounterResult from(Status status) { 31 | switch (status) { 32 | case ENCOUNTER_ERROR: 33 | return ERROR; 34 | case ENCOUNTER_SUCCESS: 35 | return SUCCESS; 36 | case ENCOUNTER_NOT_FOUND: 37 | return NOT_FOUND; 38 | case ENCOUNTER_CLOSED: 39 | return CLOSED; 40 | case ENCOUNTER_POKEMON_FLED: 41 | return POKEMON_FLED; 42 | case ENCOUNTER_NOT_IN_RANGE: 43 | return NOT_IN_RANGE; 44 | case ENCOUNTER_ALREADY_HAPPENED: 45 | return ALREADY_HAPPENED; 46 | case POKEMON_INVENTORY_FULL: 47 | return INVENTORY_FULL; 48 | default: 49 | return UNRECOGNISED; 50 | } 51 | } 52 | 53 | /** 54 | * @param result the result to convert from 55 | * @return EncounterResult from Result 56 | */ 57 | public static EncounterResult from(DiskEncounterResponse.Result result) { 58 | switch (result) { 59 | case SUCCESS: 60 | return SUCCESS; 61 | case NOT_AVAILABLE: 62 | return NOT_FOUND; 63 | case ENCOUNTER_ALREADY_FINISHED: 64 | return CLOSED; 65 | case NOT_IN_RANGE: 66 | return NOT_IN_RANGE; 67 | case POKEMON_INVENTORY_FULL: 68 | return INVENTORY_FULL; 69 | default: 70 | return UNRECOGNISED; 71 | } 72 | } 73 | 74 | /** 75 | * @param result the result to convert from 76 | * @return EncounterResult from Result 77 | */ 78 | public static EncounterResult from(IncenseEncounterResponse.Result result) { 79 | switch (result) { 80 | case INCENSE_ENCOUNTER_SUCCESS: 81 | return SUCCESS; 82 | case POKEMON_INVENTORY_FULL: 83 | return INVENTORY_FULL; 84 | case INCENSE_ENCOUNTER_NOT_AVAILABLE: 85 | return NOT_FOUND; 86 | default: 87 | return UNRECOGNISED; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.map.pokemon; 17 | 18 | import POGOProtos.Networking.Responses.EvolvePokemonResponseOuterClass; 19 | 20 | import com.pokegoapi.api.PokemonGo; 21 | import com.pokegoapi.api.pokemon.Pokemon; 22 | 23 | public class EvolutionResult { 24 | 25 | private EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto; 26 | private Pokemon pokemon; 27 | 28 | /** 29 | * The evolution result. 30 | * 31 | * @param api PokemonGo api 32 | * @param proto Pokemon proto 33 | */ 34 | public EvolutionResult(PokemonGo api, EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto) { 35 | this.proto = proto; 36 | this.pokemon = new Pokemon(api, proto.getEvolvedPokemonData()); 37 | } 38 | 39 | public EvolvePokemonResponseOuterClass.EvolvePokemonResponse.Result getResult() { 40 | return proto.getResult(); 41 | } 42 | 43 | public Pokemon getEvolvedPokemon() { 44 | return pokemon; 45 | } 46 | 47 | public int getExpAwarded() { 48 | return proto.getExperienceAwarded(); 49 | } 50 | 51 | public int getCandyAwarded() { 52 | return proto.getCandyAwarded(); 53 | } 54 | 55 | public boolean isSuccessful() { 56 | return (getResult().equals(EvolvePokemonResponseOuterClass.EvolvePokemonResponse.Result.SUCCESS)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/map/pokemon/IncenseEncounter.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.map.pokemon; 2 | 3 | import POGOProtos.Networking.Requests.Messages.IncenseEncounterMessageOuterClass.IncenseEncounterMessage; 4 | import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType; 5 | import POGOProtos.Networking.Responses.IncenseEncounterResponseOuterClass.IncenseEncounterResponse; 6 | import com.google.protobuf.ByteString; 7 | import com.google.protobuf.InvalidProtocolBufferException; 8 | import com.pokegoapi.api.PokemonGo; 9 | import com.pokegoapi.exceptions.request.RequestFailedException; 10 | import com.pokegoapi.main.ServerRequest; 11 | 12 | public class IncenseEncounter extends Encounter { 13 | /** 14 | * Creates a DiskEncounter object 15 | * 16 | * @param api the current api 17 | * @param pokemon the pokemon of this encounter 18 | */ 19 | protected IncenseEncounter(PokemonGo api, CatchablePokemon pokemon) { 20 | super(api, pokemon); 21 | } 22 | 23 | @Override 24 | public EncounterResult encounter() throws RequestFailedException { 25 | IncenseEncounterMessage message = IncenseEncounterMessage.newBuilder() 26 | .setEncounterId(pokemon.encounterId) 27 | .setEncounterLocation(pokemon.spawnPointId) 28 | .build(); 29 | 30 | ServerRequest request = new ServerRequest(RequestType.INCENSE_ENCOUNTER, message); 31 | ByteString responseData = api.requestHandler.sendServerRequests(request, true); 32 | 33 | try { 34 | IncenseEncounterResponse response = IncenseEncounterResponse.parseFrom(responseData); 35 | encounterResult = EncounterResult.from(response.getResult()); 36 | activeItem = response.getActiveItem(); 37 | captureProbabilities = response.getCaptureProbability(); 38 | encounteredPokemon = response.getPokemonData(); 39 | } catch (InvalidProtocolBufferException e) { 40 | throw new RequestFailedException(e); 41 | } 42 | 43 | return encounterResult; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/map/pokemon/NearbyPokemon.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.map.pokemon; 17 | 18 | import POGOProtos.Enums.PokemonIdOuterClass; 19 | import POGOProtos.Map.Pokemon.NearbyPokemonOuterClass; 20 | 21 | public class NearbyPokemon { 22 | private NearbyPokemonOuterClass.NearbyPokemon proto; 23 | 24 | public NearbyPokemon(NearbyPokemonOuterClass.NearbyPokemon proto) { 25 | this.proto = proto; 26 | } 27 | 28 | public PokemonIdOuterClass.PokemonId getPokemonId() { 29 | return proto.getPokemonId(); 30 | } 31 | 32 | public float getDistanceInMeters() { 33 | return proto.getDistanceInMeters(); 34 | } 35 | 36 | public long getEncounterId() { 37 | return proto.getEncounterId(); 38 | } 39 | 40 | public String getFortId() { 41 | return proto.getFortId(); 42 | } 43 | 44 | public String getFortImageUrl() { 45 | return proto.getFortImageUrl(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/map/pokemon/ThrowProperties.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.map.pokemon; 2 | 3 | import lombok.Getter; 4 | 5 | public class ThrowProperties { 6 | @Getter 7 | public double normalizedHitPosition; 8 | @Getter 9 | public double normalizedReticleSize; 10 | @Getter 11 | public double spinModifier; 12 | private boolean hitPokemon = true; 13 | 14 | private ThrowProperties() { 15 | this.normalizedHitPosition = 1.0; 16 | this.normalizedReticleSize = 1.95 + Math.random() * 0.05; 17 | double spinType = Math.random(); 18 | if (spinType > 0.5) { 19 | this.spinModifier = 1.0; 20 | } else if (spinType > 0.8) { 21 | this.spinModifier = 0.0; 22 | } else { 23 | this.spinModifier = 0.85 + Math.random() * 0.15; 24 | } 25 | } 26 | 27 | /** 28 | * Creates a ThrowProperties object 29 | * @param normalizedHitPosition the normalized hit position of this throw 30 | * @param normalizedReticleSize the normalized reticle size of this throw 31 | * @param spinModifier the spin modifier of this throw 32 | * @param hitPokemon true if this throw hit the pokemon 33 | */ 34 | public ThrowProperties(double normalizedHitPosition, double normalizedReticleSize, double spinModifier, 35 | boolean hitPokemon) { 36 | this.normalizedHitPosition = normalizedHitPosition; 37 | this.normalizedReticleSize = normalizedReticleSize; 38 | this.spinModifier = spinModifier; 39 | this.hitPokemon = hitPokemon; 40 | } 41 | 42 | /** 43 | * @return a randomly populated ThrowProperties object 44 | */ 45 | public static ThrowProperties random() { 46 | return new ThrowProperties(); 47 | } 48 | 49 | /** 50 | * Applies a hit position to this throw 51 | * @param normalizedHitPosition the normalized hit position of this throw 52 | * @return these properties 53 | */ 54 | public ThrowProperties withHitPosition(double normalizedHitPosition) { 55 | this.normalizedHitPosition = normalizedHitPosition; 56 | return this; 57 | } 58 | 59 | /** 60 | * Applies a reticle size to this throw 61 | * @param normalizedReticleSize the normalized reticle size for this throw 62 | * @return these properties 63 | */ 64 | public ThrowProperties withReticleSize(double normalizedReticleSize) { 65 | this.normalizedReticleSize = normalizedReticleSize; 66 | return this; 67 | } 68 | 69 | /** 70 | * Applies a spin modifier to this throw 71 | * @param spinModifier the spin modifier for this throw 72 | * @return these properties 73 | */ 74 | public ThrowProperties withSpinModifier(double spinModifier) { 75 | this.spinModifier = spinModifier; 76 | return this; 77 | } 78 | 79 | /** 80 | * Sets whether this throw hit the pokemon or not 81 | * @param hitPokemon true if this throw hit the pokemon 82 | * @return these properties 83 | */ 84 | public ThrowProperties withHit(boolean hitPokemon) { 85 | this.hitPokemon = hitPokemon; 86 | return this; 87 | } 88 | 89 | /** 90 | * @return true if this throw should hit the current pokemon 91 | */ 92 | public boolean shouldHitPokemon() { 93 | return hitPokemon; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/news/News.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.news; 17 | 18 | import POGOProtos.Data.News.CurrentNewsOuterClass; 19 | import POGOProtos.Data.News.NewsArticleOuterClass.NewsArticle; 20 | import POGOProtos.Networking.Requests.Messages.MarkReadNewsArticleMessageOuterClass.MarkReadNewsArticleMessage; 21 | import POGOProtos.Networking.Requests.RequestTypeOuterClass; 22 | import POGOProtos.Networking.Responses.MarkReadNewsArticleResponseOuterClass.MarkReadNewsArticleResponse; 23 | import com.google.protobuf.InvalidProtocolBufferException; 24 | import com.pokegoapi.api.PokemonGo; 25 | import com.pokegoapi.exceptions.request.RequestFailedException; 26 | import com.pokegoapi.main.ServerRequest; 27 | import com.pokegoapi.main.ServerRequestEnvelope; 28 | import com.pokegoapi.util.Log; 29 | import lombok.Getter; 30 | 31 | import java.util.ArrayList; 32 | import java.util.List; 33 | 34 | public class News { 35 | private static final java.lang.String TAG = News.class.getSimpleName(); 36 | 37 | private final PokemonGo api; 38 | @Getter 39 | private CurrentNewsOuterClass.CurrentNews currentNews; 40 | // the Key of the Language = Key 41 | 42 | /** 43 | * Constructor 44 | * 45 | * @param api Pokemon Go Core Api 46 | */ 47 | public News(PokemonGo api) { 48 | this.api = api; 49 | } 50 | 51 | public void setCurrentNews(CurrentNewsOuterClass.CurrentNews currentNews) { 52 | this.currentNews = currentNews; 53 | } 54 | 55 | /** 56 | * Mark Unread News to read 57 | */ 58 | public void markUnreadNews() { 59 | 60 | if (currentNews == null || currentNews.getNewsArticlesCount() <= 0) { 61 | // do nothing 62 | return; 63 | } 64 | 65 | // Stored enabled and un-read article 66 | List unReadNewsList = new ArrayList<>(); 67 | for (NewsArticle newsArticle : currentNews.getNewsArticlesList()) { 68 | if (newsArticle.getEnabled() && !newsArticle.getArticleRead()) 69 | unReadNewsList.add(newsArticle.getId()); 70 | } 71 | 72 | Log.i(TAG, "markUnreadNews total Article count:" + unReadNewsList.size()); 73 | 74 | if (unReadNewsList.size() > 0) { 75 | MarkReadNewsArticleMessage msg = MarkReadNewsArticleMessage.newBuilder() 76 | .addAllNewsIds(unReadNewsList).build(); 77 | ServerRequest request = new ServerRequest(RequestTypeOuterClass.RequestType.MARK_READ_NEWS_ARTICLE, msg); 78 | ServerRequestEnvelope envelope = ServerRequestEnvelope.create(request); 79 | try { 80 | api.requestHandler.sendServerRequests(envelope); 81 | MarkReadNewsArticleResponse response = MarkReadNewsArticleResponse.parseFrom(request.getData()); 82 | if (response.getResult() == MarkReadNewsArticleResponse.Result.SUCCESS) { 83 | Log.i(TAG, "Mark News Article -> success"); 84 | } else { 85 | Log.w(TAG, "Mark News Article -> !success"); 86 | } 87 | } catch (RequestFailedException e) { 88 | e.printStackTrace(); 89 | Log.e(TAG, "RequestFailedException: cause:" + e.getCause() + " message:" + e.getMessage()); 90 | } catch (InvalidProtocolBufferException e) { 91 | e.printStackTrace(); 92 | Log.e(TAG, "InvalidProtocolBufferException: cause:" + e.getCause() + " message:" + e.getMessage()); 93 | } 94 | } else { 95 | Log.i(TAG, "no unmarked news found -> skipped"); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/player/ContactSettings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.player; 17 | 18 | import POGOProtos.Data.Player.ContactSettingsOuterClass; 19 | import lombok.Data; 20 | 21 | @Data 22 | public class ContactSettings { 23 | private ContactSettingsOuterClass.ContactSettings proto; 24 | 25 | public ContactSettings(ContactSettingsOuterClass.ContactSettings proto) { 26 | this.proto = proto; 27 | } 28 | 29 | public boolean getSendMarketingEmails() { 30 | return proto.getSendMarketingEmails(); 31 | } 32 | 33 | public boolean getSendPushNotifications() { 34 | return proto.getSendPushNotifications(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/player/DailyBonus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.player; 17 | 18 | import POGOProtos.Data.Player.DailyBonusOuterClass; 19 | import lombok.Data; 20 | 21 | @Data 22 | public class DailyBonus { 23 | private final DailyBonusOuterClass.DailyBonus proto; 24 | 25 | public DailyBonus(DailyBonusOuterClass.DailyBonus proto) { 26 | this.proto = proto; 27 | } 28 | 29 | public long getNextCollectedTimestampMs() { 30 | return proto.getNextCollectedTimestampMs(); 31 | } 32 | 33 | public long getNextDefenderBonusCollectTimestampMs() { 34 | return proto.getNextDefenderBonusCollectTimestampMs(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/player/Medal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.player; 17 | 18 | import POGOProtos.Data.PlayerBadgeOuterClass.PlayerBadge; 19 | import POGOProtos.Enums.BadgeTypeOuterClass.BadgeType; 20 | import POGOProtos.Settings.Master.BadgeSettingsOuterClass.BadgeSettings; 21 | import com.pokegoapi.api.PokemonGo; 22 | import lombok.Getter; 23 | import lombok.Setter; 24 | 25 | public class Medal { 26 | private PokemonGo api; 27 | 28 | @Getter 29 | @Setter 30 | public int rank; 31 | @Getter 32 | private BadgeType type; 33 | 34 | @Getter 35 | private final int startValue; 36 | @Getter 37 | private final double currentValue; 38 | @Getter 39 | private final int endValue; 40 | 41 | /** 42 | * Creates a Medal with a PlayerBadge proto 43 | * 44 | * @param api the current api 45 | * @param badge the proto to inititialize with 46 | */ 47 | public Medal(PokemonGo api, PlayerBadge badge) { 48 | this.api = api; 49 | this.type = badge.getBadgeType(); 50 | this.rank = badge.getRank(); 51 | this.startValue = badge.getStartValue(); 52 | this.currentValue = badge.getCurrentValue(); 53 | this.endValue = badge.getEndValue(); 54 | } 55 | 56 | /** 57 | * Gets settings for this badge type 58 | * 59 | * @return the settings 60 | */ 61 | public BadgeSettings getSettings() { 62 | return api.itemTemplates.getBadgeSettings(type); 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | return type.getNumber(); 68 | } 69 | 70 | @Override 71 | public boolean equals(Object obj) { 72 | return obj instanceof Medal && ((Medal) obj).type.equals(type); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/player/PlayerGender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.player; 17 | 18 | public enum PlayerGender { 19 | MALE, 20 | FEMALE; 21 | 22 | /** 23 | * Gets a gender from the given proto value 24 | * @param value the proto value 25 | * @return the gender for the proto value 26 | */ 27 | public static PlayerGender get(int value) { 28 | if (value == 0) { 29 | return MALE; 30 | } 31 | return FEMALE; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/player/PlayerLevelUpRewards.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.player; 2 | 3 | import POGOProtos.Inventory.Item.ItemAwardOuterClass; 4 | import POGOProtos.Inventory.Item.ItemIdOuterClass; 5 | import POGOProtos.Networking.Responses.LevelUpRewardsResponseOuterClass.LevelUpRewardsResponse; 6 | import lombok.Data; 7 | 8 | import java.util.Collections; 9 | import java.util.List; 10 | 11 | /** 12 | * A data class containing the results of a trainer level up. This includes a list of items received for this level up, 13 | * a list of items which were unlocked by this level up (for example razz berries) 14 | * and the status of these level up results. 15 | * If the rewards for this level up have been 16 | * accepted in the past the status will be ALREADY_ACCEPTED, if this level up has not yet been achieved 17 | * by the player it will be NOT_UNLOCKED_YET otherwise it will be NEW. 18 | * 19 | * @author Alex Schlosser 20 | */ 21 | @Data 22 | public class PlayerLevelUpRewards { 23 | private final Status status; 24 | private final List rewards; 25 | private final List unlockedItems; 26 | 27 | 28 | /** 29 | * Create new empty result object with the specified status. 30 | * 31 | * @param status the status of this result 32 | */ 33 | public PlayerLevelUpRewards(final Status status) { 34 | this.status = status; 35 | this.rewards = Collections.emptyList(); 36 | this.unlockedItems = Collections.emptyList(); 37 | } 38 | 39 | public enum Status { 40 | ALREADY_ACCEPTED, NEW, NOT_UNLOCKED_YET 41 | } 42 | 43 | /** 44 | * Create a new result object based on a server response 45 | * 46 | * @param response the response which contains the request results 47 | */ 48 | public PlayerLevelUpRewards(final LevelUpRewardsResponse response) { 49 | this.rewards = response.getItemsAwardedList(); 50 | this.unlockedItems = response.getItemsUnlockedList(); 51 | this.status = (rewards.isEmpty() ? Status.ALREADY_ACCEPTED : Status.NEW); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/player/PlayerLocale.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.player; 17 | 18 | import POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass; 19 | 20 | import java.util.Calendar; 21 | import java.util.Locale; 22 | 23 | /** 24 | * Created by iGio90 on 25/08/16. 25 | */ 26 | public class PlayerLocale { 27 | 28 | private GetPlayerMessageOuterClass.GetPlayerMessage.PlayerLocale playerLocale; 29 | 30 | /** 31 | * Constructor to use the default Locale 32 | */ 33 | public PlayerLocale() { 34 | GetPlayerMessageOuterClass.GetPlayerMessage.PlayerLocale.Builder builder = 35 | GetPlayerMessageOuterClass.GetPlayerMessage.PlayerLocale.newBuilder(); 36 | builder.setCountry(Locale.getDefault().getCountry()) 37 | .setLanguage(Locale.getDefault().getLanguage()) 38 | .setTimezone(Calendar.getInstance().getTimeZone().getID()); 39 | 40 | playerLocale = builder.build(); 41 | } 42 | 43 | public GetPlayerMessageOuterClass.GetPlayerMessage.PlayerLocale getPlayerLocale() { 44 | return playerLocale; 45 | } 46 | 47 | public String getCountry() { 48 | return playerLocale.getCountry(); 49 | } 50 | 51 | public String getLanguage() { 52 | return playerLocale.getLanguage(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/player/Team.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.player; 17 | 18 | import lombok.Getter; 19 | 20 | public enum Team { 21 | TEAM_NONE(0), 22 | TEAM_MYSTIC(1), 23 | TEAM_VALOR(2), 24 | TEAM_INSTINCT(3); 25 | 26 | @Getter 27 | private int value; 28 | 29 | private Team(int value) { 30 | this.value = value; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/player/TutorialState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.player; 17 | 18 | import POGOProtos.Enums.TutorialStateOuterClass; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | public class TutorialState { 24 | private final ArrayList tutorialStateList = new ArrayList<>(); 25 | 26 | public TutorialState(List tutorialStateList) { 27 | this.tutorialStateList.addAll(tutorialStateList); 28 | } 29 | 30 | public ArrayList getTutorialStates() { 31 | return tutorialStateList; 32 | } 33 | 34 | public void addTutorialState(TutorialStateOuterClass.TutorialState state) { 35 | tutorialStateList.add(state); 36 | } 37 | 38 | public void addTutorialStates(List states) { 39 | tutorialStateList.addAll(states); 40 | } 41 | } -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/pokemon/Buddy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.pokemon; 17 | 18 | import POGOProtos.Data.BuddyPokemonOuterClass.BuddyPokemon; 19 | import com.pokegoapi.api.PokemonGo; 20 | 21 | public class Buddy { 22 | private final PokemonGo api; 23 | private long id; 24 | private double lastKMAwarded; 25 | private double startKM; 26 | private Pokemon pokemon; 27 | private double buddyDistance; 28 | 29 | /** 30 | * Creates a buddy object 31 | * 32 | * @param api the current api 33 | * @param proto the buddy proto 34 | */ 35 | public Buddy(PokemonGo api, BuddyPokemon proto) { 36 | this.api = api; 37 | this.id = proto.getId(); 38 | this.lastKMAwarded = proto.getLastKmAwarded(); 39 | this.startKM = proto.getStartKmWalked(); 40 | } 41 | 42 | /** 43 | * @return the pokemon object of this buddy 44 | */ 45 | public Pokemon getPokemon() { 46 | if (pokemon == null) { 47 | pokemon = api.inventories.pokebank.getPokemonById(this.id); 48 | buddyDistance = api.itemTemplates.getPokemonSettings(pokemon.getPokemonId()).getKmBuddyDistance(); 49 | } 50 | return pokemon; 51 | } 52 | 53 | /** 54 | * @return the total distance this type of buddy pokemon needs to walk per candy 55 | */ 56 | public double getBuddyDistance() { 57 | if (pokemon == null) { 58 | getPokemon(); 59 | } 60 | return buddyDistance; 61 | } 62 | 63 | /** 64 | * @return the last walk distance when a candy was received 65 | */ 66 | public double getLastReceiveKM() { 67 | return lastKMAwarded; 68 | } 69 | 70 | /** 71 | * @return the distance when the distance started progressing 72 | */ 73 | public double getStartKM() { 74 | return startKM; 75 | } 76 | 77 | /** 78 | * @return the target distance walked for this buddy's next candy 79 | */ 80 | public double getTargetKM() { 81 | return getLastReceiveKM() + buddyDistance; 82 | } 83 | 84 | /** 85 | * @return the current buddy walk progress, from 0-buddyDistance 86 | */ 87 | public double getProgressKM() { 88 | double walked = api.playerProfile.getStats().getKmWalked(); 89 | double startedKM = Math.max(getStartKM(), getLastReceiveKM()); 90 | return walked - startedKM; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/pokemon/Evolution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.pokemon; 17 | 18 | import POGOProtos.Enums.PokemonIdOuterClass.PokemonId; 19 | import POGOProtos.Settings.Master.Pokemon.EvolutionBranchOuterClass.EvolutionBranch; 20 | import com.pokegoapi.api.settings.templates.ItemTemplates; 21 | import lombok.Getter; 22 | 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | 26 | public class Evolution { 27 | @Getter 28 | public PokemonId parent; 29 | @Getter 30 | private PokemonId pokemon; 31 | @Getter 32 | public List evolutions = new ArrayList<>(); 33 | @Getter 34 | public List evolutionBranch; 35 | 36 | /** 37 | * Constructor for this evolution class 38 | * 39 | * @param templates the item templates received from the server 40 | * @param parent the parent of this evolution 41 | * @param pokemon the pokemon being evolved 42 | */ 43 | public Evolution(ItemTemplates templates, PokemonId parent, PokemonId pokemon) { 44 | this.parent = parent; 45 | this.pokemon = pokemon; 46 | this.evolutionBranch = templates.getPokemonSettings(pokemon).getEvolutionBranchList(); 47 | for (EvolutionBranch evolutionBranch : evolutionBranch) { 48 | evolutions.add(evolutionBranch.getEvolution()); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/pokemon/HatchedEgg.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.pokemon; 17 | 18 | import POGOProtos.Data.PokemonDataOuterClass.PokemonData; 19 | import com.pokegoapi.api.PokemonGo; 20 | import lombok.Getter; 21 | import lombok.Setter; 22 | 23 | public class HatchedEgg { 24 | @Setter 25 | @Getter 26 | private Pokemon pokemon; 27 | @Setter 28 | @Getter 29 | private Long id; 30 | @Setter 31 | @Getter 32 | private int experience; 33 | @Setter 34 | @Getter 35 | private int candy; 36 | @Setter 37 | @Getter 38 | private int stardust; 39 | 40 | /** 41 | * Creates a hatched egg 42 | * 43 | * @param pokemonId the hatched pokemon id 44 | * @param experienceAwarded the experience awarded from this hatch 45 | * @param candyAwarded the candy awarded from this hatch 46 | * @param stardustAwarded the stardust awarded from this hatch 47 | * @param hatchedPokemon the pokemon hatched 48 | * @param api the current API 49 | */ 50 | public HatchedEgg(long pokemonId, int experienceAwarded, int candyAwarded, int stardustAwarded, 51 | PokemonData hatchedPokemon, PokemonGo api) { 52 | this.pokemon = new Pokemon(api, hatchedPokemon); 53 | this.id = pokemonId; 54 | this.experience = experienceAwarded; 55 | this.candy = candyAwarded; 56 | this.stardust = stardustAwarded; 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return id.intValue(); 62 | } 63 | 64 | @Override 65 | public boolean equals(Object obj) { 66 | return obj instanceof HatchedEgg && ((HatchedEgg) obj).id.equals(id); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/pokemon/MovementType.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.pokemon; 2 | 3 | 4 | public enum MovementType { 5 | PSYCHIC, 6 | FLYING, 7 | ELETRIC, 8 | NORMAL, 9 | HOVERING, 10 | JUMP, ELECTRIC; 11 | } 12 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/pokemon/PokemonClass.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.pokemon; 2 | 3 | public enum PokemonClass { 4 | NONE, 5 | VERY_COMMON, 6 | COMMON, 7 | UNCOMMON, 8 | RARE, 9 | VERY_RARE, 10 | EPIC, 11 | LEGENDARY, 12 | MYTHIC; 13 | } 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/pokemon/PokemonType.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.pokemon; 2 | 3 | 4 | public enum PokemonType { 5 | NONE, 6 | GRASS, 7 | FIRE, 8 | WATER, 9 | BUG, 10 | ELECTRIC, 11 | POISON, 12 | FAIRY, 13 | NORMAL, 14 | PSYCHIC, 15 | FIGHTING, 16 | DRAGON, 17 | FLYING, 18 | ICE, 19 | ROCK, 20 | GROUND, 21 | GHOST, 22 | STEEL, 23 | DARK; 24 | } 25 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/pokemon/StarterPokemon.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.pokemon; 2 | 3 | import POGOProtos.Enums.PokemonIdOuterClass; 4 | import lombok.Getter; 5 | 6 | import java.util.Random; 7 | 8 | public enum StarterPokemon { 9 | BULBASAUR(PokemonIdOuterClass.PokemonId.BULBASAUR), 10 | SQUIRTLE(PokemonIdOuterClass.PokemonId.SQUIRTLE), 11 | CHARMANDER(PokemonIdOuterClass.PokemonId.CHARMANDER); 12 | 13 | @Getter 14 | public PokemonIdOuterClass.PokemonId pokemon; 15 | 16 | StarterPokemon(PokemonIdOuterClass.PokemonId pokemon) { 17 | this.pokemon = pokemon; 18 | } 19 | 20 | public static StarterPokemon random() { 21 | Random random = new Random(); 22 | return StarterPokemon.values()[random.nextInt(StarterPokemon.values().length)]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/settings/FortSettings.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.settings; 2 | 3 | import lombok.Getter; 4 | 5 | /** 6 | * Created by rama on 27/07/16. 7 | */ 8 | public class FortSettings { 9 | 10 | @Getter 11 | /** 12 | * Min distance to interact with the fort 13 | * 14 | * @return distance in meters. 15 | */ 16 | public double interactionRangeInMeters; 17 | 18 | @Getter 19 | /** 20 | * NOT SURE: max number of pokemons in the fort 21 | * 22 | * @return number of pokemons. 23 | */ 24 | private int maxTotalDeployedPokemon; 25 | 26 | @Getter 27 | /** 28 | * NOT SURE: max number of players who can add pokemons to the fort 29 | * 30 | * @return number of players. 31 | */ 32 | private int maxPlayerDeployedPokemon; 33 | 34 | @Getter 35 | /** 36 | * Stamina multiplier 37 | * 38 | * @return multiplier. 39 | */ 40 | private double deployStaminaMultiplier; 41 | 42 | @Getter 43 | /** 44 | * Attack multiplier 45 | * 46 | * @return multiplier. 47 | */ 48 | private double deployAttackMultiplier; 49 | 50 | @Getter 51 | /** 52 | * NO IDEA 53 | * 54 | * @return distance in meters. 55 | */ 56 | private double farInteractionRangeMeters; 57 | 58 | /** 59 | * Update the fort settings from the network response. 60 | * 61 | * @param fortSettings the new fort settings 62 | */ 63 | public void update(POGOProtos.Settings.FortSettingsOuterClass.FortSettings fortSettings) { 64 | interactionRangeInMeters = fortSettings.getInteractionRangeMeters(); 65 | maxTotalDeployedPokemon = fortSettings.getMaxTotalDeployedPokemon(); 66 | maxPlayerDeployedPokemon = fortSettings.getMaxPlayerDeployedPokemon(); 67 | deployStaminaMultiplier = fortSettings.getDeployStaminaMultiplier(); 68 | deployAttackMultiplier = fortSettings.getDeployAttackMultiplier(); 69 | farInteractionRangeMeters = fortSettings.getFarInteractionRangeMeters(); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/settings/GpsSettings.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.settings; 2 | 3 | import POGOProtos.Settings.GpsSettingsOuterClass; 4 | import lombok.Getter; 5 | 6 | /** 7 | * Created by fabianterhorst on 16.08.16. 8 | */ 9 | 10 | public class GpsSettings { 11 | 12 | @Getter 13 | /** 14 | * 15 | * @return meters per seconds. 16 | */ 17 | private double drivingWarningSpeedMetersPerSecond; 18 | 19 | @Getter 20 | /** 21 | * 22 | * @return minutes. 23 | */ 24 | private float drivingWarningCooldownMinutes; 25 | 26 | @Getter 27 | /** 28 | * 29 | * @return seconds. 30 | */ 31 | private float drivingSpeedSampleIntervalSeconds; 32 | 33 | @Getter 34 | /** 35 | * 36 | * @return count. 37 | */ 38 | private double drivingSpeedSampleCount; 39 | 40 | /** 41 | * Update the gps settings from the network response. 42 | * 43 | * @param gpsSettings the new gps settings 44 | */ 45 | public void update(GpsSettingsOuterClass.GpsSettings gpsSettings) { 46 | drivingWarningSpeedMetersPerSecond = gpsSettings.getDrivingWarningSpeedMetersPerSecond(); 47 | drivingWarningCooldownMinutes = gpsSettings.getDrivingWarningCooldownMinutes(); 48 | drivingSpeedSampleIntervalSeconds = gpsSettings.getDrivingSpeedSampleIntervalSeconds(); 49 | drivingSpeedSampleCount = gpsSettings.getDrivingSpeedSampleCount(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/settings/InventorySettings.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.settings; 2 | 3 | import lombok.Getter; 4 | 5 | /** 6 | * Created by rama on 27/07/16. 7 | */ 8 | public class InventorySettings { 9 | @Getter 10 | private int baseBagItems; 11 | @Getter 12 | private int maxBagItems; 13 | @Getter 14 | private int baseEggs; 15 | @Getter 16 | private int basePokemon; 17 | @Getter 18 | private int maxPokemon; 19 | 20 | protected void update(POGOProtos.Settings.InventorySettingsOuterClass.InventorySettings inventorySettings) { 21 | baseBagItems = inventorySettings.getBaseBagItems(); 22 | maxBagItems = inventorySettings.getMaxBagItems(); 23 | baseEggs = inventorySettings.getBaseEggs(); 24 | maxPokemon = inventorySettings.getMaxPokemon(); 25 | basePokemon = inventorySettings.getBasePokemon(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/settings/LevelUpSettings.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.settings; 2 | 3 | import POGOProtos.Settings.InventorySettingsOuterClass; 4 | 5 | /** 6 | * Created by rama on 27/07/16. 7 | */ 8 | public class LevelUpSettings { 9 | //TODO: parse & save data 10 | protected void update(InventorySettingsOuterClass.InventorySettings mapSettings) { 11 | 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/settings/MapSettings.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.settings; 2 | 3 | import POGOProtos.Settings.MapSettingsOuterClass; 4 | import lombok.Getter; 5 | 6 | /** 7 | * Created by rama on 27/07/16. 8 | */ 9 | public class MapSettings { 10 | 11 | @Getter 12 | /** 13 | * Google api key used for display map 14 | * 15 | * @return String. 16 | */ 17 | private String googleApiKey; 18 | 19 | @Getter 20 | /** 21 | * Minimum distance between getMapObjects requests 22 | * 23 | * @return distance in meters. 24 | */ 25 | private float minMapObjectDistance; 26 | 27 | @Getter 28 | /** 29 | * Max refresh betweewn getMapObjecs requests 30 | * 31 | * @return value in milliseconds. 32 | */ 33 | public float maxRefresh; 34 | 35 | @Getter 36 | /** 37 | * Min refresh betweewn getMapObjecs requests 38 | * 39 | * @return value in milliseconds. 40 | */ 41 | public float minRefresh; 42 | 43 | @Getter 44 | /** 45 | * NOT SURE: the max distance for encounter pokemon? 46 | * 47 | * @return distance in meters. 48 | */ 49 | private double encounterRange; 50 | 51 | @Getter 52 | /** 53 | * NOT SURE: the max distance before show pokemon on map? 54 | * 55 | * @return distance in meters. 56 | */ 57 | public double pokemonVisibilityRange; 58 | 59 | @Getter 60 | /** 61 | * NO IDEA 62 | * 63 | * @return distance in meters. 64 | */ 65 | private double pokeNavRange; 66 | 67 | protected void update(MapSettingsOuterClass.MapSettings mapSettings) { 68 | googleApiKey = mapSettings.getGoogleMapsApiKey(); 69 | minMapObjectDistance = mapSettings.getGetMapObjectsMinDistanceMeters(); 70 | maxRefresh = mapSettings.getGetMapObjectsMaxRefreshSeconds() * 1000; 71 | minRefresh = mapSettings.getGetMapObjectsMinRefreshSeconds() * 1000; 72 | encounterRange = mapSettings.getEncounterRangeMeters(); 73 | pokemonVisibilityRange = mapSettings.getPokemonVisibleRange(); 74 | pokeNavRange = mapSettings.getPokeNavRangeMeters(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/settings/PokeballSelector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.settings; 17 | 18 | import com.pokegoapi.api.inventory.Pokeball; 19 | 20 | import java.util.List; 21 | 22 | public interface PokeballSelector { 23 | /** 24 | * Selects the lowest possible pokeball 25 | */ 26 | PokeballSelector LOWEST = new PokeballSelector() { 27 | @Override 28 | public Pokeball select(List pokeballs, double captureProbability) { 29 | return pokeballs.get(0); 30 | } 31 | }; 32 | /** 33 | * Selects the highest possible pokeball 34 | */ 35 | PokeballSelector HIGHEST = new PokeballSelector() { 36 | @Override 37 | public Pokeball select(List pokeballs, double captureProbability) { 38 | return pokeballs.get(pokeballs.size() - 1); 39 | } 40 | }; 41 | /** 42 | * Selects a pokeball to use based on the capture probability of the current pokemon 43 | */ 44 | PokeballSelector SMART = new PokeballSelector() { 45 | @Override 46 | public Pokeball select(List pokeballs, double captureProbability) { 47 | Pokeball desired = pokeballs.get(0); 48 | for (Pokeball pokeball : pokeballs) { 49 | if (captureProbability <= pokeball.captureProbability) { 50 | desired = pokeball; 51 | } 52 | } 53 | return desired; 54 | } 55 | }; 56 | 57 | Pokeball select(List pokeballs, double captureProbability); 58 | } -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/settings/Settings.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.settings; 2 | 3 | import POGOProtos.Networking.Responses.DownloadSettingsResponseOuterClass.DownloadSettingsResponse; 4 | import com.pokegoapi.api.PokemonGo; 5 | import lombok.Getter; 6 | 7 | /** 8 | * Created by rama on 27/07/16. 9 | */ 10 | public class Settings { 11 | 12 | private final PokemonGo api; 13 | 14 | @Getter 15 | /** 16 | * Settings for various parameters on map 17 | * 18 | * @return MapSettings instance. 19 | */ 20 | public final MapSettings mapSettings; 21 | 22 | @Getter 23 | /** 24 | * Settings for various parameters during levelup 25 | * 26 | * @return LevelUpSettings instance. 27 | */ 28 | private final LevelUpSettings levelUpSettings; 29 | 30 | @Getter 31 | /** 32 | * Settings for various parameters during levelup 33 | * 34 | * @return LevelUpSettings instance. 35 | */ 36 | public final FortSettings fortSettings; 37 | 38 | 39 | @Getter 40 | /** 41 | * Settings for various parameters during levelup 42 | * 43 | * @return LevelUpSettings instance. 44 | */ 45 | private final InventorySettings inventorySettings; 46 | 47 | @Getter 48 | /** 49 | * Settings for showing speed warnings 50 | * 51 | * @return GpsSettings instance. 52 | */ 53 | private final GpsSettings gpsSettings; 54 | @Getter 55 | /** 56 | * Settings for hash 57 | * 58 | * @return String hash. 59 | */ 60 | public String hash; 61 | 62 | /** 63 | * Settings object that hold different configuration aspect of the game. 64 | * Can be used to simulate the real app behaviour. 65 | * 66 | * @param api api instance 67 | */ 68 | public Settings(PokemonGo api) { 69 | this.api = api; 70 | this.mapSettings = new MapSettings(); 71 | this.levelUpSettings = new LevelUpSettings(); 72 | this.fortSettings = new FortSettings(); 73 | this.inventorySettings = new InventorySettings(); 74 | this.gpsSettings = new GpsSettings(); 75 | this.hash = ""; 76 | } 77 | 78 | /** 79 | * Updates settings latest data. 80 | * 81 | * @param response the settings download response 82 | */ 83 | public void updateSettings(DownloadSettingsResponse response) { 84 | if (response.getSettings().hasMapSettings()) { 85 | mapSettings.update(response.getSettings().getMapSettings()); 86 | } 87 | if (response.getSettings().hasLevelSettings()) { 88 | levelUpSettings.update(response.getSettings().getInventorySettings()); 89 | } 90 | if (response.getSettings().hasFortSettings()) { 91 | fortSettings.update(response.getSettings().getFortSettings()); 92 | } 93 | if (response.getSettings().hasInventorySettings()) { 94 | inventorySettings.update(response.getSettings().getInventorySettings()); 95 | } 96 | if (response.getSettings().hasGpsSettings()) { 97 | gpsSettings.update(response.getSettings().getGpsSettings()); 98 | } 99 | this.hash = response.getHash(); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/settings/templates/DirectTemplateProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details.` 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.settings.templates; 17 | 18 | import POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse; 19 | import POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse.ItemTemplate; 20 | 21 | import java.io.IOException; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | /** 26 | * {@link ItemTemplateProvider} that doesn't store any templates, it instead downloads them every launch 27 | */ 28 | public class DirectTemplateProvider implements ItemTemplateProvider { 29 | private Map templates = new HashMap<>(); 30 | 31 | @Override 32 | public long getUpdatedTimestamp() { 33 | return 0; 34 | } 35 | 36 | @Override 37 | public Map getTemplates() { 38 | return templates; 39 | } 40 | 41 | @Override 42 | public void updateTemplates(DownloadItemTemplatesResponse response, long time) throws IOException { 43 | for (ItemTemplate template : response.getItemTemplatesList()) { 44 | templates.put(template.getTemplateId(), template); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/settings/templates/ItemTemplateProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details.` 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.api.settings.templates; 17 | 18 | import POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse; 19 | import POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse.ItemTemplate; 20 | 21 | import java.io.IOException; 22 | import java.util.Map; 23 | 24 | public interface ItemTemplateProvider { 25 | /** 26 | * @return the last timestamp at which these templates were updated 27 | */ 28 | long getUpdatedTimestamp(); 29 | 30 | /** 31 | * @return the current templates 32 | */ 33 | Map getTemplates(); 34 | 35 | /** 36 | * Update the current templates with the given response 37 | * 38 | * @param templates new templates to merge 39 | * @param time the current timestamp 40 | * @throws IOException if the templates could not be updated 41 | */ 42 | void updateTemplates(DownloadItemTemplatesResponse templates, long time) throws IOException; 43 | } 44 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/api/settings/templates/TempFileTemplateProvider.java: -------------------------------------------------------------------------------- 1 | package com.pokegoapi.api.settings.templates; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | /** 7 | * File {@link ItemTemplateProvider} that stores templates in the temporary directory 8 | */ 9 | public class TempFileTemplateProvider extends FileTemplateProvider { 10 | /** 11 | * Creates a {@link TempFileTemplateProvider} 12 | * 13 | * @throws IOException if the templates could not be loaded 14 | */ 15 | public TempFileTemplateProvider() throws IOException { 16 | super(new File(System.getProperty("java.io.tmpdir"))); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/auth/CredentialProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.auth; 17 | 18 | import POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope.AuthInfo; 19 | import com.pokegoapi.exceptions.request.InvalidCredentialsException; 20 | import com.pokegoapi.exceptions.request.LoginFailedException; 21 | 22 | /** 23 | * Any Credential Provider can extend this. 24 | */ 25 | public abstract class CredentialProvider { 26 | 27 | public abstract String getTokenId(boolean refresh) throws LoginFailedException, InvalidCredentialsException; 28 | 29 | public abstract AuthInfo getAuthInfo(boolean refresh) throws LoginFailedException, InvalidCredentialsException; 30 | 31 | public abstract boolean isTokenIdInvalid(); 32 | 33 | public abstract void reset(); 34 | } 35 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/auth/GoogleAuthJson.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.auth; 17 | 18 | import com.squareup.moshi.Json; 19 | 20 | import lombok.Getter; 21 | import lombok.Setter; 22 | 23 | public class GoogleAuthJson { 24 | @Getter 25 | @Setter 26 | @Json(name = "device_code") 27 | String deviceCode; 28 | @Getter 29 | @Setter 30 | @Json(name = "user_code") 31 | String userCode; 32 | @Getter 33 | @Setter 34 | @Json(name = "verification_url") 35 | String verificationUrl; 36 | @Getter 37 | @Setter 38 | @Json(name = "expires_in") 39 | int expiresIn; 40 | @Getter 41 | @Setter 42 | @Json(name = "interval") 43 | int interval; 44 | } 45 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/auth/GoogleAuthTokenJson.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.auth; 17 | 18 | import com.squareup.moshi.Json; 19 | 20 | import lombok.Getter; 21 | import lombok.Setter; 22 | 23 | public class GoogleAuthTokenJson { 24 | @Getter 25 | @Setter 26 | public String error; 27 | @Getter 28 | @Setter 29 | @Json(name = "access_token") 30 | public String accessToken; 31 | @Getter 32 | @Setter 33 | @Json(name = "token_type") 34 | public String tokenType; 35 | @Getter 36 | @Setter 37 | @Json(name = "expires_in") 38 | public int expiresIn; 39 | @Getter 40 | @Setter 41 | @Json(name = "refresh_token") 42 | public String refreshToken; 43 | @Getter 44 | @Setter 45 | @Json(name = "id_token") 46 | public String idToken; 47 | } 48 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/auth/PtcAuthError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.auth; 17 | 18 | import lombok.Getter; 19 | import lombok.Setter; 20 | 21 | public class PtcAuthError { 22 | @Getter 23 | @Setter 24 | public String[] errors; 25 | } 26 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/auth/PtcAuthJson.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.auth; 17 | 18 | import lombok.Getter; 19 | import lombok.Setter; 20 | 21 | public class PtcAuthJson { 22 | 23 | @Getter 24 | @Setter 25 | public String lt; 26 | @Getter 27 | @Setter 28 | public String execution; 29 | } 30 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/AsyncPokemonGoException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions; 17 | 18 | public class AsyncPokemonGoException extends RuntimeException { 19 | 20 | public AsyncPokemonGoException(String message) { 21 | super(message); 22 | } 23 | 24 | public AsyncPokemonGoException(String message, Throwable cause) { 25 | super(message, cause); 26 | } 27 | 28 | public AsyncPokemonGoException(Throwable cause) { 29 | super(cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/EncounterFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions; 17 | 18 | public class EncounterFailedException extends Exception { 19 | public EncounterFailedException() { 20 | super(); 21 | } 22 | 23 | public EncounterFailedException(String reason) { 24 | super(reason); 25 | } 26 | 27 | public EncounterFailedException(Throwable exception) { 28 | super(exception); 29 | } 30 | 31 | public EncounterFailedException(String reason, Throwable exception) { 32 | super(reason, exception); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/InsufficientLevelException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions; 17 | 18 | public class InsufficientLevelException extends RuntimeException { 19 | public InsufficientLevelException() { 20 | super(); 21 | } 22 | 23 | public InsufficientLevelException(String reason) { 24 | super(reason); 25 | } 26 | 27 | public InsufficientLevelException(Throwable exception) { 28 | super(exception); 29 | } 30 | 31 | public InsufficientLevelException(String reason, Throwable exception) { 32 | super(reason, exception); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/InvalidCurrencyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions; 17 | 18 | public class InvalidCurrencyException extends Exception { 19 | public InvalidCurrencyException() { 20 | super(); 21 | } 22 | 23 | public InvalidCurrencyException(String reason) { 24 | super(reason); 25 | } 26 | 27 | public InvalidCurrencyException(Throwable exception) { 28 | super(exception); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/NoSuchItemException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions; 17 | 18 | public class NoSuchItemException extends Exception { 19 | public NoSuchItemException() { 20 | super(); 21 | } 22 | 23 | public NoSuchItemException(String reason) { 24 | super(reason); 25 | } 26 | 27 | public NoSuchItemException(Throwable exception) { 28 | super(exception); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/request/BadRequestException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions.request; 17 | 18 | public class BadRequestException extends RequestFailedException { 19 | public BadRequestException() { 20 | super(); 21 | } 22 | 23 | public BadRequestException(String reason) { 24 | super(reason); 25 | } 26 | 27 | public BadRequestException(Throwable exception) { 28 | super(exception); 29 | } 30 | 31 | public BadRequestException(String reason, Throwable exception) { 32 | super(reason, exception); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/request/BannedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions.request; 17 | 18 | public class BannedException extends RequestFailedException { 19 | public BannedException() { 20 | super(); 21 | } 22 | 23 | public BannedException(String reason) { 24 | super(reason); 25 | } 26 | 27 | public BannedException(Throwable exception) { 28 | super(exception); 29 | } 30 | 31 | public BannedException(String reason, Throwable exception) { 32 | super(reason, exception); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/request/CaptchaActiveException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions.request; 17 | 18 | import lombok.Getter; 19 | 20 | public class CaptchaActiveException extends RequestFailedException { 21 | @Getter 22 | private String challengeUrl; 23 | 24 | public CaptchaActiveException(String message, String challengeUrl) { 25 | super(message); 26 | this.challengeUrl = challengeUrl; 27 | } 28 | 29 | public CaptchaActiveException(String challengeUrl) { 30 | this("Cannot send message while captcha is active", challengeUrl); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/request/HashException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions.request; 17 | 18 | public class HashException extends RequestFailedException { 19 | 20 | public HashException() { 21 | super(); 22 | } 23 | 24 | public HashException(String reason) { 25 | super(reason); 26 | } 27 | 28 | public HashException(Throwable exception) { 29 | super(exception); 30 | } 31 | 32 | public HashException(String reason, Throwable exception) { 33 | super(reason, exception); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/request/HashLimitExceededException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions.request; 17 | 18 | /** 19 | * Hash Limit Exceeded Exception 20 | */ 21 | public class HashLimitExceededException extends HashException { 22 | 23 | public HashLimitExceededException() { 24 | super(); 25 | } 26 | 27 | public HashLimitExceededException(String reason) { 28 | super(reason); 29 | } 30 | 31 | public HashLimitExceededException(Throwable exception) { 32 | super(exception); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/request/HashUnauthorizedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions.request; 17 | 18 | /** 19 | * Exception thrown when the hashing service returns an unauthorized status code 20 | */ 21 | public class HashUnauthorizedException extends HashException { 22 | 23 | public HashUnauthorizedException() { 24 | super(); 25 | } 26 | 27 | public HashUnauthorizedException(String reason) { 28 | super(reason); 29 | } 30 | 31 | public HashUnauthorizedException(Throwable exception) { 32 | super(exception); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/request/InvalidCredentialsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions.request; 17 | 18 | public class InvalidCredentialsException extends RequestFailedException { 19 | public InvalidCredentialsException() { 20 | super(); 21 | } 22 | 23 | public InvalidCredentialsException(String reason) { 24 | super(reason); 25 | } 26 | 27 | public InvalidCredentialsException(Throwable exception) { 28 | super(exception); 29 | } 30 | 31 | public InvalidCredentialsException(String reason, Throwable exception) { 32 | super(reason, exception); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/request/LoginFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions.request; 17 | 18 | public class LoginFailedException extends RequestFailedException { 19 | public LoginFailedException() { 20 | super(); 21 | } 22 | 23 | public LoginFailedException(String reason) { 24 | super(reason); 25 | } 26 | 27 | public LoginFailedException(Throwable exception) { 28 | super(exception); 29 | } 30 | 31 | public LoginFailedException(String reason, Throwable exception) { 32 | super(reason, exception); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/exceptions/request/RequestFailedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.exceptions.request; 17 | 18 | public class RequestFailedException extends Exception { 19 | public RequestFailedException() { 20 | super(); 21 | } 22 | 23 | public RequestFailedException(String reason) { 24 | super(reason); 25 | } 26 | 27 | public RequestFailedException(Throwable exception) { 28 | super(exception); 29 | } 30 | 31 | public RequestFailedException(String reason, Throwable exception) { 32 | super(reason, exception); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/google/common/geometry/MutableInteger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | package com.pokegoapi.google.common.geometry; 16 | 17 | /** 18 | * Like an Integer, but mutable :) 19 | *

20 | * Sometimes it is just really convenient to be able to pass a MutableInteger 21 | * as a parameter to a function, or for synchronization purposes (so that you 22 | * can guard access to an int value without creating a separate Object just to 23 | * synchronize on). 24 | *

25 | * NOT thread-safe 26 | */ 27 | public class MutableInteger { 28 | 29 | private int value; 30 | private Integer cachedIntegerValue = null; 31 | 32 | public MutableInteger(final int i) { 33 | value = i; 34 | } 35 | 36 | public int intValue() { 37 | return value; 38 | } 39 | 40 | public Integer integerValue() { 41 | if (cachedIntegerValue == null) { 42 | cachedIntegerValue = intValue(); 43 | } 44 | return cachedIntegerValue; 45 | } 46 | 47 | @Override 48 | public boolean equals(final Object o) { 49 | return o instanceof MutableInteger && ((MutableInteger) o).value == this.value; 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | return integerValue().hashCode(); 55 | } 56 | 57 | public void setValue(final int value) { 58 | this.value = value; 59 | cachedIntegerValue = null; 60 | } 61 | 62 | public void increment() { 63 | add(1); 64 | } 65 | 66 | public void add(final int amount) { 67 | setValue(value + amount); 68 | } 69 | 70 | public void decrement() { 71 | subtract(1); 72 | } 73 | 74 | public void subtract(final int amount) { 75 | add(amount * -1); 76 | } 77 | 78 | @Override 79 | public String toString() { 80 | return String.valueOf(value); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/google/common/geometry/R2Vector.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | package com.pokegoapi.google.common.geometry; 16 | 17 | /** 18 | * R2Vector represents a vector in the two-dimensional space. It defines the 19 | * basic geometrical operations for 2D vectors, e.g. cross product, addition, 20 | * norm, comparison etc. 21 | */ 22 | public final strictfp class R2Vector { 23 | private final double x; 24 | private final double y; 25 | 26 | public R2Vector() { 27 | this(0, 0); 28 | } 29 | 30 | public R2Vector(double x, double y) { 31 | this.x = x; 32 | this.y = y; 33 | } 34 | 35 | public R2Vector(double[] coord) { 36 | if (coord.length != 2) { 37 | throw new IllegalStateException("Points must have exactly 2 coordinates"); 38 | } 39 | x = coord[0]; 40 | y = coord[1]; 41 | } 42 | 43 | public double x() { 44 | return x; 45 | } 46 | 47 | public double y() { 48 | return y; 49 | } 50 | 51 | public double get(int index) { 52 | if (index > 1) { 53 | throw new ArrayIndexOutOfBoundsException(index); 54 | } 55 | return index == 0 ? this.x : this.y; 56 | } 57 | 58 | public static R2Vector add(final R2Vector p1, final R2Vector p2) { 59 | return new R2Vector(p1.x + p2.x, p1.y + p2.y); 60 | } 61 | 62 | public static R2Vector mul(final R2Vector p, double m) { 63 | return new R2Vector(m * p.x, m * p.y); 64 | } 65 | 66 | public double norm2() { 67 | return (x * x) + (y * y); 68 | } 69 | 70 | public static double dotProd(final R2Vector p1, final R2Vector p2) { 71 | return (p1.x * p2.x) + (p1.y * p2.y); 72 | } 73 | 74 | public double dotProd(R2Vector that) { 75 | return dotProd(this, that); 76 | } 77 | 78 | public double crossProd(final R2Vector that) { 79 | return this.x * that.y - this.y * that.x; 80 | } 81 | 82 | public boolean lessThan(R2Vector vb) { 83 | if (x < vb.x) { 84 | return true; 85 | } 86 | if (vb.x < x) { 87 | return false; 88 | } 89 | if (y < vb.y) { 90 | return true; 91 | } 92 | return false; 93 | } 94 | 95 | @Override 96 | public boolean equals(Object that) { 97 | if (!(that instanceof R2Vector)) { 98 | return false; 99 | } 100 | R2Vector thatPoint = (R2Vector) that; 101 | return this.x == thatPoint.x && this.y == thatPoint.y; 102 | } 103 | 104 | /** 105 | * Calcualates hashcode based on stored coordinates. Since we want +0.0 and 106 | * -0.0 to be treated the same, we ignore the sign of the coordinates. 107 | */ 108 | @Override 109 | public int hashCode() { 110 | long value = 17; 111 | value += 37 * value + Double.doubleToLongBits(Math.abs(x)); 112 | value += 37 * value + Double.doubleToLongBits(Math.abs(y)); 113 | return (int) (value ^ (value >>> 32)); 114 | } 115 | 116 | @Override 117 | public String toString() { 118 | return "(" + x + ", " + y + ")"; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/google/common/geometry/S2AreaCentroid.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.google.common.geometry; 17 | 18 | 19 | /** 20 | * The area of an interior, i.e. the region on the left side of an odd 21 | * number of loops and optionally a centroid. 22 | * The area is between 0 and 4*Pi. If it has a centroid, it is 23 | * the true centroid of the interiord multiplied by the area of the shape. 24 | * Note that the centroid may not be contained by the shape. 25 | * 26 | * @author dbentley@google.com (Daniel Bentley) 27 | */ 28 | public final class S2AreaCentroid { 29 | 30 | private final double area; 31 | private final S2Point centroid; 32 | 33 | public S2AreaCentroid(double area, S2Point centroid) { 34 | this.area = area; 35 | this.centroid = centroid; 36 | } 37 | 38 | public double getArea() { 39 | return area; 40 | } 41 | 42 | public S2Point getCentroid() { 43 | return centroid; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/google/common/geometry/S2Edge.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.google.common.geometry; 17 | 18 | /** 19 | * An abstract directed edge from one S2Point to another S2Point. 20 | * 21 | * @author kirilll@google.com (Kirill Levin) 22 | */ 23 | public final class S2Edge { 24 | 25 | private final S2Point start; 26 | private final S2Point end; 27 | 28 | public S2Edge(S2Point start, S2Point end) { 29 | this.start = start; 30 | this.end = end; 31 | } 32 | 33 | public S2Point getStart() { 34 | return start; 35 | } 36 | 37 | public S2Point getEnd() { 38 | return end; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return String.format("Edge: (%s -> %s)\n or [%s -> %s]", 44 | start.toDegreesString(), end.toDegreesString(), start, end); 45 | } 46 | 47 | @Override 48 | public int hashCode() { 49 | return getStart().hashCode() - getEnd().hashCode(); 50 | } 51 | 52 | @Override 53 | public boolean equals(Object o) { 54 | if (o == null || !(o instanceof S2Edge)) { 55 | return false; 56 | } 57 | S2Edge other = (S2Edge) o; 58 | return getStart().equals(other.getStart()) && getEnd().equals(other.getEnd()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/google/common/geometry/S2Region.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | package com.pokegoapi.google.common.geometry; 16 | 17 | /** 18 | * An S2Region represents a two-dimensional region over the unit sphere. It is 19 | * an abstract interface with various concrete subtypes. 20 | *

21 | * The main purpose of this interface is to allow complex regions to be 22 | * approximated as simpler regions. So rather than having a wide variety of 23 | * virtual methods that are implemented by all subtypes, the interface is 24 | * restricted to methods that are useful for computing approximations. 25 | */ 26 | public interface S2Region { 27 | 28 | /** 29 | * Return a bounding spherical cap. 30 | */ 31 | public abstract S2Cap getCapBound(); 32 | 33 | 34 | /** 35 | * Return a bounding latitude-longitude rectangle. 36 | */ 37 | public abstract S2LatLngRect getRectBound(); 38 | 39 | /** 40 | * If this method returns true, the region completely contains the given cell. 41 | * Otherwise, either the region does not contain the cell or the containment 42 | * relationship could not be determined. 43 | */ 44 | public abstract boolean contains(S2Cell cell); 45 | 46 | /** 47 | * If this method returns false, the region does not intersect the given cell. 48 | * Otherwise, either region intersects the cell, or the intersection 49 | * relationship could not be determined. 50 | */ 51 | public abstract boolean mayIntersect(S2Cell cell); 52 | } 53 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/google/common/geometry/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.google.common.geometry; 17 | 18 | import java.util.Arrays; 19 | 20 | public class Utils { 21 | // had nullable annotation 22 | public static int hashCode(Object... objects) { 23 | return Arrays.hashCode(objects); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/main/Heartbeat.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.main; 17 | 18 | import com.pokegoapi.api.PokemonGo; 19 | import com.pokegoapi.api.listener.HeartbeatListener; 20 | import com.pokegoapi.api.map.Map; 21 | import com.pokegoapi.api.settings.MapSettings; 22 | import lombok.Getter; 23 | 24 | import java.util.List; 25 | 26 | public class Heartbeat { 27 | @Getter 28 | private PokemonGo api; 29 | 30 | private long nextMapUpdate = Long.MIN_VALUE; 31 | private long minMapRefresh; 32 | private long maxMapRefresh; 33 | private boolean updatingMap; 34 | 35 | private boolean active; 36 | 37 | private final Object lock = new Object(); 38 | 39 | /** 40 | * Create a new Heartbeat object for the given API 41 | * 42 | * @param api the api for this heartbeat 43 | */ 44 | public Heartbeat(PokemonGo api) { 45 | this.api = api; 46 | } 47 | 48 | /** 49 | * Begins this heartbeat 50 | */ 51 | public void start() { 52 | if (!active) { 53 | active = true; 54 | beat(); 55 | Thread heartbeatThread = new Thread(new Runnable() { 56 | @Override 57 | public void run() { 58 | while (active) { 59 | try { 60 | Thread.sleep(10); 61 | } catch (InterruptedException e) { 62 | break; 63 | } 64 | beat(); 65 | } 66 | } 67 | }); 68 | heartbeatThread.setDaemon(true); 69 | heartbeatThread.setName("Heartbeat thread"); 70 | heartbeatThread.start(); 71 | } 72 | } 73 | 74 | /** 75 | * Performs a single heartbeat 76 | */ 77 | public void beat() { 78 | MapSettings mapSettings = api.settings.mapSettings; 79 | minMapRefresh = (long) mapSettings.minRefresh; 80 | maxMapRefresh = (long) mapSettings.maxRefresh; 81 | 82 | List listeners = api.getListeners(HeartbeatListener.class); 83 | long time = api.currentTimeMillis(); 84 | boolean updatingMap; 85 | synchronized (lock) { 86 | updatingMap = this.updatingMap; 87 | } 88 | if (time >= nextMapUpdate && !updatingMap) { 89 | synchronized (lock) { 90 | this.updatingMap = true; 91 | } 92 | Map map = api.getMap(); 93 | try { 94 | if (map.update()) { 95 | nextMapUpdate = time + minMapRefresh; 96 | } 97 | for (HeartbeatListener listener : listeners) { 98 | listener.onMapUpdate(api, map.mapObjects); 99 | } 100 | } catch (Exception exception) { 101 | for (HeartbeatListener listener : listeners) { 102 | listener.onMapUpdateException(api, exception); 103 | } 104 | } 105 | synchronized (lock) { 106 | this.updatingMap = false; 107 | } 108 | } 109 | } 110 | 111 | /** 112 | * @return if the heartbeat is currently active 113 | */ 114 | public boolean active() { 115 | return active; 116 | } 117 | 118 | /** 119 | * Exits this heartbeat 120 | */ 121 | public void exit() { 122 | active = false; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/main/RequestIdGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.main; 17 | 18 | public class RequestIdGenerator { 19 | private static final long MULTIPLIER = 16807; 20 | private static final long MODULUS = 0x7FFFFFFF; 21 | 22 | private long rpcIdHigh = 1; 23 | private long rpcId = 2; 24 | 25 | /** 26 | * Generates next request id and increments count 27 | * @return the next request id 28 | */ 29 | public long next() { 30 | rpcIdHigh = MULTIPLIER * rpcIdHigh % MODULUS; 31 | return rpcId++ | (rpcIdHigh << 32); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/main/ResultOrException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.main; 17 | 18 | import com.google.protobuf.ByteString; 19 | 20 | import lombok.Getter; 21 | 22 | public class ResultOrException { 23 | @Getter 24 | private final ByteString result; 25 | @Getter 26 | private final Exception exception; 27 | 28 | private ResultOrException(ByteString result, Exception exception) { 29 | this.result = result; 30 | this.exception = exception; 31 | } 32 | 33 | public static ResultOrException getError(Exception exception) { 34 | return new ResultOrException(null, exception); 35 | } 36 | 37 | public static ResultOrException getResult(ByteString result) { 38 | return new ResultOrException(result, null); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/main/ServerPlatformRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.main; 17 | 18 | import POGOProtos.Networking.Platform.PlatformRequestTypeOuterClass.PlatformRequestType; 19 | import com.google.protobuf.ByteString; 20 | import com.google.protobuf.InvalidProtocolBufferException; 21 | import lombok.Getter; 22 | 23 | public class ServerPlatformRequest { 24 | @Getter 25 | public final PlatformRequestType type; 26 | @Getter 27 | public final ByteString request; 28 | 29 | private final Object responseLock = new Object(); 30 | 31 | private ByteString response; 32 | 33 | /** 34 | * Creates a ServerPlatformRequest 35 | * @param type the type of request 36 | * @param request the request data 37 | */ 38 | public ServerPlatformRequest(PlatformRequestType type, ByteString request) { 39 | this.type = type; 40 | this.request = request; 41 | } 42 | 43 | /** 44 | * Handles the response for this request 45 | * 46 | * @param response the response to handle 47 | */ 48 | public void handleResponse(ByteString response) { 49 | synchronized (responseLock) { 50 | this.response = response; 51 | this.responseLock.notifyAll(); 52 | } 53 | } 54 | 55 | /** 56 | * Gets the response data for this request, if received 57 | * 58 | * @return the response data for this request, if received 59 | * @throws InvalidProtocolBufferException if the response data is null 60 | */ 61 | public ByteString getData() throws InvalidProtocolBufferException { 62 | synchronized (responseLock) { 63 | if (response != null) { 64 | return response; 65 | } 66 | throw new InvalidProtocolBufferException("Response data cannot be null"); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/main/ServerRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.main; 17 | 18 | import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType; 19 | import com.google.protobuf.ByteString; 20 | import com.google.protobuf.InvalidProtocolBufferException; 21 | import com.google.protobuf.Message; 22 | import lombok.Getter; 23 | 24 | public class ServerRequest { 25 | @Getter 26 | public final RequestType type; 27 | @Getter 28 | public final Message request; 29 | 30 | private final Object responseLock = new Object(); 31 | 32 | private ByteString response; 33 | 34 | /** 35 | * Creates a ServerRequest 36 | * @param type the type of request 37 | * @param request the request data 38 | */ 39 | public ServerRequest(RequestType type, Message request) { 40 | this.type = type; 41 | this.request = request; 42 | } 43 | 44 | /** 45 | * Handles the response for this request 46 | * 47 | * @param response the response to handle 48 | */ 49 | public void handleResponse(ByteString response) { 50 | synchronized (responseLock) { 51 | this.response = response; 52 | this.responseLock.notifyAll(); 53 | } 54 | } 55 | 56 | /** 57 | * Gets the response data for this request, if received 58 | * 59 | * @return the response data for this request, if received 60 | * @throws InvalidProtocolBufferException if the response data is null 61 | */ 62 | public ByteString getData() throws InvalidProtocolBufferException { 63 | synchronized (responseLock) { 64 | if (response != null) { 65 | return response; 66 | } 67 | throw new InvalidProtocolBufferException("Response data cannot be null"); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/main/ServerResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.main; 17 | 18 | import POGOProtos.Networking.Platform.PlatformRequestTypeOuterClass.PlatformRequestType; 19 | import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType; 20 | import com.google.protobuf.ByteString; 21 | import lombok.Getter; 22 | import lombok.Setter; 23 | 24 | import java.util.EnumMap; 25 | 26 | public class ServerResponse { 27 | private final EnumMap responses = new EnumMap<>(RequestType.class); 28 | private final EnumMap platformResponses = new EnumMap<>(PlatformRequestType.class); 29 | @Getter 30 | @Setter 31 | public Exception exception; 32 | 33 | /** 34 | * Creates a blank {@link ServerResponse} 35 | */ 36 | public ServerResponse() { 37 | } 38 | 39 | /** 40 | * Creates a {@link ServerResponse} with an exception 41 | * 42 | * @param exception the exception in this response 43 | */ 44 | public ServerResponse(Exception exception) { 45 | this.exception = exception; 46 | } 47 | 48 | /** 49 | * Adds a response to this envelope 50 | * 51 | * @param type the type of request 52 | * @param data the response data for this request 53 | */ 54 | public void addResponse(RequestType type, ByteString data) { 55 | responses.put(type, data); 56 | } 57 | 58 | /** 59 | * Adds a response to this envelope 60 | * 61 | * @param type the type of request 62 | * @param data the response data for this request 63 | */ 64 | public void addResponse(PlatformRequestType type, ByteString data) { 65 | platformResponses.put(type, data); 66 | } 67 | 68 | /** 69 | * Gets the response data for this request type 70 | * 71 | * @param type the type to check 72 | * @return response data for the given type, null if none available 73 | */ 74 | public ByteString get(RequestType type) { 75 | return responses.get(type); 76 | } 77 | 78 | /** 79 | * Gets the response data for this request type 80 | * 81 | * @param type the type to check 82 | * @return response data for the given type, null if none available 83 | */ 84 | public ByteString get(PlatformRequestType type) { 85 | return platformResponses.get(type); 86 | } 87 | 88 | /** 89 | * Checks if this response contains the given request type 90 | * 91 | * @param type the request type to check for 92 | * @return true if this response contains the given request type 93 | */ 94 | public boolean has(RequestType type) { 95 | return responses.containsKey(type); 96 | } 97 | 98 | /** 99 | * Checks if this response contains the given platform request type 100 | * 101 | * @param type the platform request type to check for 102 | * @return true if this response contains the given platform request type 103 | */ 104 | public boolean has(PlatformRequestType type) { 105 | return platformResponses.containsKey(type); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/main/Utils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.main; 17 | 18 | import java.io.ByteArrayOutputStream; 19 | import java.io.File; 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | 23 | public class Utils { 24 | private static final File TEMP_DIR = new File(System.getProperty("java.io.tmpdir"), "pokego-java"); 25 | 26 | static { 27 | TEMP_DIR.mkdir(); 28 | } 29 | 30 | /** 31 | * Converts input streams to byte arrays. 32 | * 33 | * @param input the input 34 | * @param size the size 35 | * @return the byte [ ] 36 | * @throws IOException the io exception 37 | */ 38 | public static byte[] inputStreamToByteArray(InputStream input, int size) throws IOException { 39 | byte[] buffer = new byte[size]; 40 | int bytesRead; 41 | ByteArrayOutputStream output = new ByteArrayOutputStream(); 42 | while ((bytesRead = input.read(buffer)) != -1) { 43 | output.write(buffer, 0, bytesRead); 44 | } 45 | return output.toByteArray(); 46 | } 47 | 48 | /** 49 | * Appends the given requests to the given array 50 | * 51 | * @param requests the base array 52 | * @param append the requests to append 53 | * @return a new array with the appended requests 54 | */ 55 | public static ServerRequest[] appendRequests(ServerRequest[] requests, ServerRequest... append) { 56 | ServerRequest[] newRequests = new ServerRequest[requests.length + append.length]; 57 | System.arraycopy(requests, 0, newRequests, 0, requests.length); 58 | System.arraycopy(append, 0, newRequests, requests.length, append.length); 59 | return newRequests; 60 | } 61 | 62 | /** 63 | * Creates a temp file at the given location 64 | * 65 | * @param name the name of the file 66 | * @return the temp file 67 | * @throws IOException if there is a problem while creating the file 68 | */ 69 | public static File createTempFile(String name) throws IOException { 70 | final File temp = Utils.getTempFile(name); 71 | if (!temp.getParentFile().exists()) { 72 | temp.getParentFile().mkdirs(); 73 | } 74 | if (!(temp.exists()) && !(temp.createNewFile())) { 75 | throw new IOException("Could not create temp file: " + temp.getAbsolutePath()); 76 | } 77 | return temp; 78 | } 79 | 80 | /** 81 | * Gets the temp file at a given location without creating it 82 | * 83 | * @param name the name of this file 84 | * @return the requested temp file 85 | */ 86 | public static File getTempFile(String name) { 87 | return new File(TEMP_DIR, name); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/AsyncHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util; 17 | 18 | import com.pokegoapi.exceptions.AsyncPokemonGoException; 19 | import com.pokegoapi.exceptions.request.RequestFailedException; 20 | import rx.Observable; 21 | 22 | public class AsyncHelper { 23 | /** 24 | * Convert an observable to the actual result, recovering the actual exception and throwing that 25 | * 26 | * @param observable Observable to handle 27 | * @param Result type 28 | * @return Result of the observable 29 | * @throws RequestFailedException if an exception occurred while sending requests 30 | */ 31 | public static T toBlocking(Observable observable) throws RequestFailedException { 32 | try { 33 | return observable.toBlocking().first(); 34 | } catch (RuntimeException e) { 35 | if (e.getCause() instanceof RequestFailedException) { 36 | throw new RequestFailedException(e.getMessage(), e.getCause()); 37 | } 38 | throw new AsyncPokemonGoException("Unknown exception occurred. ", e); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/BaseLogger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util; 17 | 18 | import com.pokegoapi.util.Log.Level; 19 | 20 | import static com.pokegoapi.util.Log.Level.DEBUG; 21 | import static com.pokegoapi.util.Log.Level.INFO; 22 | import static com.pokegoapi.util.Log.Level.VERBOSE; 23 | import static com.pokegoapi.util.Log.Level.WARN; 24 | import static com.pokegoapi.util.Log.Level.ERROR; 25 | import static com.pokegoapi.util.Log.Level.ASSERT; 26 | 27 | 28 | /** 29 | * Created by Will on 7/20/16. 30 | */ 31 | @SuppressWarnings("checkstyle:methodname") 32 | public abstract class BaseLogger implements Logger { 33 | 34 | @Override 35 | public void v(String tag, String msg) { 36 | log(VERBOSE, tag, msg, null); 37 | } 38 | 39 | @Override 40 | public void v(String tag, String msg, Throwable tr) { 41 | log(VERBOSE, tag, msg, tr); 42 | } 43 | 44 | @Override 45 | public void d(String tag, String msg) { 46 | log(DEBUG, tag, msg, null); 47 | } 48 | 49 | @Override 50 | public void d(String tag, String msg, Throwable tr) { 51 | log(DEBUG, tag, msg, tr); 52 | } 53 | 54 | @Override 55 | public void i(String tag, String msg) { 56 | log(INFO, tag, msg, null); 57 | } 58 | 59 | @Override 60 | public void i(String tag, String msg, Throwable tr) { 61 | log(INFO, tag, msg, tr); 62 | } 63 | 64 | @Override 65 | public void w(String tag, String msg) { 66 | log(WARN, tag, msg, null); 67 | } 68 | 69 | @Override 70 | public void w(String tag, String msg, Throwable tr) { 71 | log(WARN, tag, msg, tr); 72 | } 73 | 74 | @Override 75 | public void w(String tag, Throwable tr) { 76 | log(WARN, tag, null, tr); 77 | } 78 | 79 | @Override 80 | public void e(String tag, String msg) { 81 | log(ERROR, tag, msg, null); 82 | } 83 | 84 | @Override 85 | public void e(String tag, String msg, Throwable tr) { 86 | log(ERROR, tag, msg, tr); 87 | } 88 | 89 | @Override 90 | public void wtf(String tag, String msg) { 91 | log(ASSERT, tag, msg, null); 92 | } 93 | 94 | @Override 95 | public void wtf(String tag, Throwable tr) { 96 | log(ASSERT, tag, null, tr); 97 | } 98 | 99 | @Override 100 | public void wtf(String tag, String msg, Throwable tr) { 101 | log(ASSERT, tag, msg, tr); 102 | } 103 | 104 | public abstract void log(Level level, String tag, String msg, Throwable tr); 105 | } 106 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/CaptchaSolveHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util; 17 | 18 | import java.io.IOException; 19 | import java.net.URL; 20 | import java.net.URLConnection; 21 | import java.net.URLStreamHandler; 22 | import java.net.URLStreamHandlerFactory; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | import java.util.Queue; 26 | import java.util.concurrent.LinkedBlockingDeque; 27 | import java.util.regex.Pattern; 28 | 29 | public class CaptchaSolveHelper { 30 | public static final String USER_AGENT = "Niantic App"; 31 | 32 | private static final List LISTENERS = new ArrayList<>(); 33 | private static final Queue QUEUED_ADDITION = new LinkedBlockingDeque<>(); 34 | private static final Queue QUEUED_REMOVAL = new LinkedBlockingDeque<>(); 35 | private static boolean processing; 36 | 37 | static { 38 | URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { 39 | @Override 40 | public URLStreamHandler createURLStreamHandler(String protocol) { 41 | if (protocol.equals("unity")) { 42 | return new URLStreamHandler() { 43 | @Override 44 | protected URLConnection openConnection(URL url) throws IOException { 45 | return new URLConnection(url) { 46 | @Override 47 | public void connect() throws IOException { 48 | String token = url.toString().split(Pattern.quote(":"))[1]; 49 | processing = true; 50 | for (Listener listener : LISTENERS) { 51 | listener.onTokenReceived(token); 52 | } 53 | processing = false; 54 | while (QUEUED_ADDITION.size() > 0) { 55 | CaptchaSolveHelper.registerListener(QUEUED_ADDITION.poll()); 56 | } 57 | while (QUEUED_REMOVAL.size() > 0) { 58 | CaptchaSolveHelper.removeListener(QUEUED_REMOVAL.poll()); 59 | } 60 | } 61 | }; 62 | } 63 | }; 64 | } 65 | return null; 66 | } 67 | }); 68 | } 69 | 70 | /** 71 | * Registers the given captcha token listener. 72 | * 73 | * @param listener the listener to register 74 | */ 75 | public static void registerListener(Listener listener) { 76 | if (processing) { 77 | QUEUED_ADDITION.add(listener); 78 | } else { 79 | LISTENERS.add(listener); 80 | } 81 | } 82 | 83 | /** 84 | * Removes the given captcha token listener. 85 | * 86 | * @param listener the listener to remove 87 | */ 88 | public static void removeListener(Listener listener) { 89 | if (processing) { 90 | QUEUED_REMOVAL.add(listener); 91 | } else { 92 | LISTENERS.remove(listener); 93 | } 94 | } 95 | 96 | public interface Listener { 97 | void onTokenReceived(String token); 98 | } 99 | } -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/ClientInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util; 17 | 18 | import okhttp3.Interceptor; 19 | import okhttp3.Request; 20 | import okhttp3.Response; 21 | 22 | import java.io.IOException; 23 | 24 | /** 25 | * Created by iGio90 on 29/08/16. 26 | */ 27 | 28 | public class ClientInterceptor implements Interceptor { 29 | 30 | @Override 31 | public Response intercept(Interceptor.Chain chain) throws IOException { 32 | Request originalRequest = chain.request(); 33 | Request requestWithUserAgent = originalRequest.newBuilder() 34 | .header("User-Agent", "Niantic App") 35 | .header("Accept-Encoding", "identity, gzip") 36 | .build(); 37 | 38 | return chain.proceed(requestWithUserAgent); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/Logger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util; 17 | 18 | /** 19 | * Created by Will on 7/20/16. 20 | */ 21 | @SuppressWarnings("checkstyle:methodname") 22 | public interface Logger { 23 | 24 | void v(String tag, String msg); 25 | 26 | void v(String tag, String msg, Throwable tr); 27 | 28 | void d(String tag, String msg); 29 | 30 | void d(String tag, String msg, Throwable tr); 31 | 32 | void i(String tag, String msg); 33 | 34 | void i(String tag, String msg, Throwable tr); 35 | 36 | void w(String tag, String msg); 37 | 38 | void w(String tag, String msg, Throwable tr); 39 | 40 | void w(String tag, Throwable tr); 41 | 42 | void e(String tag, String msg); 43 | 44 | void e(String tag, String msg, Throwable tr); 45 | 46 | void wtf(String tag, String msg); 47 | 48 | void wtf(String tag, Throwable tr); 49 | 50 | void wtf(String tag, String msg, Throwable tr); 51 | } 52 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/MapPoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util; 17 | 18 | /** 19 | * @author Olaf Braun - Software Development 20 | * @version 1.0 21 | */ 22 | public interface MapPoint { 23 | /** 24 | * Gets latitude. 25 | * 26 | * @return the latitude 27 | */ 28 | double getLatitude(); 29 | 30 | /** 31 | * Gets longitude. 32 | * 33 | * @return the longitude 34 | */ 35 | double getLongitude(); 36 | } 37 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/MapUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util; 17 | 18 | import com.pokegoapi.api.PokemonGo; 19 | import com.pokegoapi.api.map.Point; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.Random; 24 | import java.util.TreeMap; 25 | 26 | /** 27 | * @author Olaf Braun - Software Development 28 | * @version 1.0 29 | */ 30 | public class MapUtil { 31 | /** 32 | * Random step to a coordinate object 33 | * 34 | * @param point the coordinate 35 | * @return the coordinate 36 | */ 37 | public static Point randomStep(Point point) { 38 | point.longitude = (point.getLongitude() + randomStep()); 39 | point.latitude = (point.getLatitude() + randomStep()); 40 | 41 | return point; 42 | } 43 | 44 | /** 45 | * Random step double. 46 | * 47 | * @return the double 48 | */ 49 | public static double randomStep() { 50 | Random random = new Random(); 51 | return random.nextDouble() / 100000.0; 52 | } 53 | 54 | /** 55 | * Dist between coordinates 56 | * 57 | * @param start the start coordinate 58 | * @param end the end coordinate 59 | * @return the double 60 | */ 61 | public static double distFrom(Point start, Point end) { 62 | return distFrom(start.getLatitude(), start.getLongitude(), end.getLatitude(), end.getLongitude()); 63 | } 64 | 65 | /** 66 | * Dist between coordinates 67 | * 68 | * @param lat1 the start latitude coordinate 69 | * @param lng1 the start longitude coordinate 70 | * @param lat2 the end latitude coordinate 71 | * @param lng2 the end longitude coordinate 72 | * @return the double 73 | */ 74 | public static double distFrom(double lat1, double lng1, double lat2, double lng2) { 75 | double earthRadius = 6371000; 76 | double lat = Math.toRadians(lat2 - lat1); 77 | double lng = Math.toRadians(lng2 - lng1); 78 | double haversine = Math.sin(lat / 2) * Math.sin(lat / 2) 79 | + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) 80 | * Math.sin(lng / 2) * Math.sin(lng / 2); 81 | 82 | 83 | return earthRadius * (2 * Math.atan2(Math.sqrt(haversine), Math.sqrt(1 - haversine))); 84 | } 85 | 86 | /** 87 | * Sort items map by distance 88 | * 89 | * @param items the items 90 | * @param api the api 91 | * @return the map 92 | */ 93 | public Map sortItems(List items, PokemonGo api) { 94 | Map result = new TreeMap<>(); 95 | for (K point : items) { 96 | result.put(distFrom(api.latitude, api.longitude, point.getLatitude(), point.getLongitude()), 97 | point); 98 | } 99 | return result; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/PokeNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util; 17 | 18 | import java.util.Locale; 19 | import java.util.MissingResourceException; 20 | 21 | 22 | /** 23 | * @deprecated Replaced by {@link PokeDictionary} 24 | */ 25 | @Deprecated 26 | public class PokeNames { 27 | /** 28 | * Returns the Name for a Pokedex ID including known translations. 29 | * 30 | * @param pokedex Pokemon index number 31 | * @param locale target name locale 32 | * @return the Pokemon name in locale 33 | * @throws MissingResourceException if can not find a matched Pokemon name for the given pokedex 34 | * @deprecated Replaced by {@link PokeDictionary#getDisplayName(int, Locale)} 35 | */ 36 | @Deprecated 37 | public static String getDisplayName(int pokedex, Locale locale) throws MissingResourceException { 38 | return PokeDictionary.getDisplayName(pokedex, locale); 39 | } 40 | 41 | /** 42 | * Returns translated Pokemon name from ENGLISH locale. 43 | * 44 | * @param engName pokemon ENGLISH name 45 | * @param newLocale the locale you want translate to 46 | * @return translated pokemon name 47 | * @throws MissingResourceException if can not find a matched Pokemon name for the given pokedex 48 | * @deprecated Replaced by {@link PokeDictionary#translateName(String, Locale)} 49 | */ 50 | @Deprecated 51 | public static String translateName(String engName, Locale newLocale) throws MissingResourceException { 52 | return PokeDictionary.translateName(engName, newLocale); 53 | } 54 | 55 | /** 56 | * Returns the Pokemon index from the Pokemon name list. 57 | * 58 | * @param pokeName pokemon name in locale 59 | * @param locale the locale on this name 60 | * @return pokedex 61 | * @throws MissingResourceException if can not find a matched Pokemon name for the given pokedex 62 | * @deprecated Replaced by {@link PokeDictionary#getPokedexFromName(String, Locale)} 63 | */ 64 | @Deprecated 65 | public static int getPokedexFromName(String pokeName, Locale locale) throws MissingResourceException { 66 | return PokeDictionary.getPokedexFromName(pokeName, locale); 67 | } 68 | 69 | /** 70 | * Returns the Pokemon index from the Pokemon name list in ENGLISH. 71 | * 72 | * @param pokeName the Pokemon ENGLISH name 73 | * @return pokedex 74 | * @throws MissingResourceException if can not find a matched Pokemon name for the given pokedex 75 | * @deprecated Replaced by {@link PokeDictionary#getPokedexFromName(String)} 76 | */ 77 | @Deprecated 78 | public static int getPokedexFromName(String pokeName) throws MissingResourceException { 79 | return PokeDictionary.getPokedexFromName(pokeName); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/SystemTimeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util; 17 | 18 | public class SystemTimeImpl implements Time { 19 | @Override 20 | public long currentTimeMillis() { 21 | return System.currentTimeMillis(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/Time.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util; 17 | 18 | public interface Time { 19 | /** 20 | * Returns the current time in milliseconds. 21 | * 22 | * @return the time 23 | */ 24 | long currentTimeMillis(); 25 | } 26 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/UInt128.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util; 17 | 18 | public class UInt128 { 19 | long low; 20 | long high; 21 | 22 | UInt128(long low, long high) { 23 | this.low = low; 24 | this.high = high; 25 | } 26 | 27 | UInt128(UInt128 value) { 28 | this.low = value.low; 29 | this.high = value.high; 30 | } 31 | 32 | UInt128 add(UInt128 value) { 33 | boolean sx = this.low < 0; 34 | boolean sy = value.low < 0; 35 | this.low += value.low; 36 | this.high += value.high; 37 | // intuitively I believe there should be something more beautiful than this, 38 | // maybe: if (this.lo < value.lo) then carry... 39 | // Please let me know, if you find out 40 | if (sx && sy || (this.low > 0 && (sx || sy))) { 41 | this.high++; 42 | } 43 | return this; 44 | } 45 | 46 | /** 47 | * @param shift Number of bits to shift (0..31) 48 | */ 49 | UInt128 clearHighBits(int shift) { 50 | this.high <<= shift; 51 | this.high >>>= shift; 52 | return this; 53 | } 54 | 55 | static UInt128 multiply(long first, long second) { 56 | long secondLow = second & 0xFFFFFFFFL; 57 | long secondHigh = second >>> 32; 58 | long firstLow = first & 0xFFFFFFFFL; 59 | long firstHigh = first >>> 32; 60 | 61 | // The upper 64 bits of the output is a combination of several factors 62 | long high = secondHigh * firstHigh; 63 | 64 | long p01 = firstLow * secondHigh; 65 | long p10 = firstHigh * secondLow; 66 | long p00 = firstLow * secondLow; 67 | 68 | // Add the high parts directly in. 69 | high += (p01 >>> 32); 70 | high += (p10 >>> 32); 71 | 72 | // Account for the possible carry from the low parts. 73 | long p2 = (p00 >>> 32) + (p01 & 0xFFFFFFFFL) + (p10 & 0xFFFFFFFFL); 74 | high += (p2 >>> 32); 75 | 76 | return new UInt128(first * second, high); 77 | } 78 | 79 | void multiply(long value) { 80 | UInt128 result = UInt128.multiply(value, this.high).add(new UInt128(this.low, 0)); 81 | this.high = result.high; 82 | this.low = result.low; 83 | } 84 | } -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/hash/Hash.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util.hash; 17 | 18 | import lombok.Getter; 19 | 20 | import java.util.List; 21 | 22 | public class Hash { 23 | @Getter 24 | public final int locationAuthHash; 25 | @Getter 26 | public final int locationHash; 27 | @Getter 28 | public final List requestHashes; 29 | 30 | /** 31 | * Creates a hash object 32 | * 33 | * @param locationAuthHash the hash of the location and auth ticket 34 | * @param locationHash the hash of the location 35 | * @param requestHashes the hash of each request 36 | */ 37 | public Hash(int locationAuthHash, int locationHash, List requestHashes) { 38 | this.locationAuthHash = locationAuthHash; 39 | this.locationHash = locationHash; 40 | this.requestHashes = requestHashes; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/hash/HashProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util.hash; 17 | 18 | import com.pokegoapi.exceptions.request.HashException; 19 | 20 | public interface HashProvider { 21 | /** 22 | * Provides a hash for the given input 23 | * 24 | * @param timestamp timestamp to hash 25 | * @param latitude latitude to hash 26 | * @param longitude longitude to hash 27 | * @param altitude altitude to hash 28 | * @param authTicket auth ticket to hash 29 | * @param sessionData session data to hash 30 | * @param requests request data to hash 31 | * @return the hash for the given input 32 | * @throws HashException if an exception occurs while hashing the given inputs 33 | */ 34 | Hash provide(long timestamp, double latitude, double longitude, double altitude, 35 | byte[] authTicket, byte[] sessionData, byte[][] requests) 36 | throws HashException; 37 | 38 | /** 39 | * @return the version this hash supports, for example 4500 = 0.45.0 and 5300 = 0.53.0 40 | */ 41 | int getHashVersion(); 42 | 43 | /** 44 | * @return the unknown 25 value used with this hash 45 | */ 46 | long getUNK25(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /library/src/main/java/com/pokegoapi/util/hash/legacy/LegacyHashProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.util.hash.legacy; 17 | 18 | import com.pokegoapi.exceptions.request.HashException; 19 | import com.pokegoapi.util.hash.Hash; 20 | import com.pokegoapi.util.hash.HashProvider; 21 | 22 | /** 23 | * 0.45.0 local hash provider, no key required 24 | * 25 | * @deprecated Niantic have disabled use of invalid hashes, 26 | * {@link com.pokegoapi.util.hash.pokehash.PokeHashProvider} must be used now 27 | */ 28 | @Deprecated 29 | public class LegacyHashProvider implements HashProvider { 30 | @Override 31 | public Hash provide(long timestamp, double latitude, double longitude, double altitude, byte[] authTicket, 32 | byte[] sessionData, byte[][] requests) throws HashException { 33 | throw new HashException(this.getClass().getName() + " is no longer supported"); 34 | } 35 | 36 | @Override 37 | public int getHashVersion() { 38 | return 4500; 39 | } 40 | 41 | @Override 42 | public long getUNK25() { 43 | return -816976800928766045L; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /library/src/main/resources/item_names.properties: -------------------------------------------------------------------------------- 1 | 0=Unknown 2 | 1=Pok\u00E9 Ball 3 | 2=Great Ball 4 | 3=Ultra Ball 5 | 4=Master Ball 6 | 101=Potion 7 | 102=Super Potion 8 | 103=Hyper Potion 9 | 104=Max Potion 10 | 201=Revive 11 | 202=Max Revive 12 | 301=Lucky Egg 13 | 401=Incense 14 | 402=Spicy Incense 15 | 403=Cool Incense 16 | 404=Floral Incense 17 | 501=Lure Module 18 | 602=X Attack 19 | 603=X Defense 20 | 604=X Miracle 21 | 701=Razz Berry 22 | 702=Bluk Berry 23 | 703=Nanab Berry 24 | 704=Wepear Berry 25 | 705=Pinap Berry 26 | 801=Camera 27 | 901=Egg Incubator \u221E 28 | 902=Egg Incubator 29 | 1001=Pok\u00E9mon Storage Upgrade 30 | 1002=Bag Upgrade 31 | 1101=Sun Stone 32 | 1102=Kings Rock 33 | 1103=Metal Coat 34 | 1104=Dragon Scale 35 | 1105=Upgrade 36 | -------------------------------------------------------------------------------- /library/src/main/resources/item_names_de.properties: -------------------------------------------------------------------------------- 1 | 0=Unbekannt 2 | 1=Pok\u00E9ball 3 | 2=Superball 4 | 3=Hyperball 5 | 4=Meisterball 6 | 101=Trank 7 | 102=Supertrank 8 | 103=Hypertrank 9 | 104=Top-Trank 10 | 201=Beleber 11 | 202=Top-Beleber 12 | 301=Gl\u00FCcks-Ei 13 | 401=Rauch 14 | 402=Scharfrauch 15 | 403=K\u00FChlrauch 16 | 404=Blumenrauch 17 | 501=Lockmodul 18 | 602=X-Angriff 19 | 603=X-Abwehr 20 | 604=X-Wunder 21 | 701=Himmihbeere 22 | 702=Morbbeere 23 | 703=Nanabbeere 24 | 704=Nirbebeere 25 | 705=Sananabeere 26 | 801=Kamera 27 | 901=Ei-Brutmaschine \u221E 28 | 902=Ei-Brutmaschine 29 | 1001=Pok\u00E9mon-Aufbewahrung-Plus 30 | 1002=Beutel-Plus -------------------------------------------------------------------------------- /library/src/main/resources/item_names_en.properties: -------------------------------------------------------------------------------- 1 | 0=Unknown 2 | 1=Pok\u00E9 Ball 3 | 2=Great Ball 4 | 3=Ultra Ball 5 | 4=Master Ball 6 | 101=Potion 7 | 102=Super Potion 8 | 103=Hyper Potion 9 | 104=Max Potion 10 | 201=Revive 11 | 202=Max Revive 12 | 301=Lucky Egg 13 | 401=Incense 14 | 402=Spicy Incense 15 | 403=Cool Incense 16 | 404=Floral Incense 17 | 501=Lure Module 18 | 602=X Attack 19 | 603=X Defense 20 | 604=X Miracle 21 | 701=Razz Berry 22 | 702=Bluk Berry 23 | 703=Nanab Berry 24 | 704=Wepear Berry 25 | 705=Pinap Berry 26 | 801=Camera 27 | 901=Egg Incubator \u221E 28 | 902=Egg Incubator 29 | 1001=Pok\u00E9mon Storage Upgrade 30 | 1002=Bag Upgrade -------------------------------------------------------------------------------- /library/src/main/resources/item_names_es.properties: -------------------------------------------------------------------------------- 1 | 0=Desconocido 2 | 1=Pok\u00E9 Ball 3 | 2=Super Ball 4 | 3=Ultra Ball 5 | 4=Master Ball 6 | 101=Poci\u00F3n 7 | 102=Superpoci\u00F3n 8 | 103=Hiperpoci\u00F3n 9 | 104=Poci\u00F3n M\u00E1xima 10 | 201=Revivir 11 | 202=Revivir M\u00E1ximo 12 | 301=Huevo Suerte 13 | 401=Incienso 14 | 402=Incienso Picante 15 | 403=Incienso Fresco 16 | 404=Incienso Floral 17 | 501=M\u00F3dulo Cebo 18 | 602=Ataque X 19 | 603=Defensa X 20 | 604=Milagro X 21 | 701=Baya Frambu 22 | 702=Baya Oram 23 | 703=Baya Latano 24 | 704=Baya Peragu 25 | 705=Baya Pinia 26 | 801=C\u00E1mara 27 | 901=Incubadora \u221E 28 | 902=Incubadora 29 | 1001=Aumento De Espacio (Pok\u00E9mon) 30 | 1002=Aumento De Espacio (Objetos) -------------------------------------------------------------------------------- /library/src/main/resources/item_names_fr.properties: -------------------------------------------------------------------------------- 1 | 0=Inconnu 2 | 1=Pok\u00E9 Ball 3 | 2=Super Ball 4 | 3=Hyper Ball 5 | 4=Master Ball 6 | 101=Potion 7 | 102=Super Potion 8 | 103=Hyper Potion 9 | 104=Potion Max 10 | 201=Rappel 11 | 202=Rappel Max 12 | 301=\u0152uf Chance 13 | 401=Encens 14 | 402=Encens Épicé 15 | 403=Encens Frais 16 | 404=Encens Floral 17 | 501=Module Leurre 18 | 602=Attaque + 19 | 603=D\u00E9fense + 20 | 604=Miracle + 21 | 701=Baie Framby 22 | 702=Baie Remu 23 | 703=Baie Nanab 24 | 704=Baie Repoi 25 | 705=Baie Nanana 26 | 801=Appareil photo 27 | 901=Incubateur \u221E 28 | 902=Incubateur 29 | 1001=Extension Du Stockage De Pok\u00E9mon 30 | 1002=Agrandir Le Sac 31 | 1101=Pierre Soleil 32 | 1102=Roche Royale 33 | 1103=Peau Métal 34 | 1104=Ecaille Draco 35 | 1105=Améliorator 36 | -------------------------------------------------------------------------------- /library/src/main/resources/item_names_it.properties: -------------------------------------------------------------------------------- 1 | 0=Sconosciuto 2 | 1=Pok\u00E9 Ball 3 | 2=Mega Ball 4 | 3=Ultra Ball 5 | 4=Master Ball 6 | 101=Pozione 7 | 102=Superpozione 8 | 103=Iperpozione 9 | 104=Pozione Max 10 | 201=Revitalizzante 11 | 202=Revitalizz. Max 12 | 301=Fortunuovo 13 | 401=Aroma 14 | 402=Aroma Piccante 15 | 403=Aroma Fresco 16 | 404=Aroma Floreale 17 | 501=Modulo esca 18 | 602=Attacco X 19 | 603=Difesa X 20 | 604=Miracolo X 21 | 701=Baccalampon 22 | 702=Baccamora 23 | 703=Baccabana 24 | 704=Baccapera 25 | 705=Baccananas 26 | 801=Fotocamera 27 | 901=Incubatrice Uova \u221E 28 | 902=Incubatrice Uova 29 | 1001=Ampliamento Spazio Pok\u00E9mon 30 | 1002=Ampliamento Spazio Borsa 31 | 1101=Pietrasolare 32 | 1102=Roccia di Re 33 | 1103=Metalcoperta 34 | 1104=Squama Drago 35 | 1105=Upgrade 36 | -------------------------------------------------------------------------------- /library/src/main/resources/item_names_ja.properties: -------------------------------------------------------------------------------- 1 | 1=\u30E2\u30F3\u30B9\u30BF\u30FC\u30DC\u30FC\u30EB 2 | 2=\u30B9\u30FC\u30D1\u30FC\u30DC\u30FC\u30EB 3 | 3=\u30CF\u30A4\u30D1\u30FC\u30DC\u30FC\u30EB 4 | 4=\u30DE\u30B9\u30BF\u30FC\u30DC\u30FC\u30EB 5 | 101=\u30AD\u30BA\u3050\u3059\u308A 6 | 102=\u3044\u3044\u30AD\u30BA\u3050\u3059\u308A 7 | 103=\u3059\u3054\u3044\u30AD\u30BA\u3050\u3059\u308A 8 | 104=\u307E\u3093\u305F\u3093\u306E\u304F\u3059\u308A 9 | 201=\u3052\u3093\u304D\u306E\u304B\u3051\u3089 10 | 202=\u3052\u3093\u304D\u306E\u304B\u305F\u307E\u308A 11 | 301=\u3057\u3042\u308F\u305B\u30BF\u30DE\u30B4 12 | 602=\u30D7\u30E9\u30B9\u30D1\u30EF\u30FC 13 | 603=\u30C7\u30A3\u30D5\u30A7\u30F3\u30C0\u30FC 14 | 701=\u30BA\u30EA\u306E\u307F 15 | 702=\u30D6\u30EA\u30FC\u306E\u307F 16 | 703=\u30CA\u30CA\u306E\u307F 17 | 704=\u30BB\u30B7\u30CA\u306E\u307F 18 | 705=\u30D1\u30A4\u30EB\u306E\u307F -------------------------------------------------------------------------------- /library/src/main/resources/item_names_ko.properties: -------------------------------------------------------------------------------- 1 | 1=\uBAAC\uC2A4\uD130\uBCFC 2 | 2=\uC218\uD37C\uBCFC 3 | 3=\uD558\uC774\uD37C\uBCFC 4 | 4=\uB9C8\uC2A4\uD130\uBCFC 5 | 101=\uC0C1\uCC98\uC57D 6 | 102=\uC88B\uC740\uC0C1\uCC98\uC57D 7 | 103=\uACE0\uAE09\uC0C1\uCC98\uC57D 8 | 104=\uD480\uD68C\uBCF5\uC57D 9 | 201=\uAE30\uB825\uC758\uC870\uAC01 10 | 202=\uAE30\uB825\uC758\uB369\uC5B4\uB9AC 11 | 301=\uD589\uBCF5\uC758\uC54C 12 | 602=\uD50C\uB7EC\uC2A4\uD30C\uC6CC 13 | 603=\uB514\uD39C\uB4DC\uC5C5 14 | 701=\uB77C\uC988\uC5F4\uB9E4 15 | 702=\uBE14\uB9AC\uC5F4\uB9E4 16 | 703=\uB098\uB098\uC5F4\uB9E4 17 | 704=\uC11C\uBC30\uC5F4\uB9E4 18 | 705=\uD30C\uC778\uC5F4\uB9E4 -------------------------------------------------------------------------------- /library/src/resources/.gitignore: -------------------------------------------------------------------------------- 1 | compile.bat 2 | protoc.exe -------------------------------------------------------------------------------- /project_code_style.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 10 | 11 | 12 | 14 | 15 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin:'application' 2 | 3 | mainClassName = "com.pokegoapi.examples.CatchPokemonAtAreaExample" 4 | 5 | archivesBaseName = archivesBaseName + '-sample' 6 | 7 | dependencies { 8 | compile project(':library') 9 | } 10 | 11 | task runSample << { 12 | if (sample == "1") { 13 | mainClassName = "com.pokegoapi.examples.CatchPokemonAtAreaExample" 14 | } else if (sample == "2") { 15 | mainClassName = "com.pokegoapi.examples.DisplayPokenameExample" 16 | } else if (sample == "3") { 17 | mainClassName = "com.pokegoapi.examples.FightGymExample" 18 | } else if (sample == "4") { 19 | mainClassName = "com.pokegoapi.examples.GoogleUserInteractionExample" 20 | } else if (sample == "5") { 21 | mainClassName = "com.pokegoapi.examples.TransferOnePidgeyExample" 22 | } else if (sample == "6") { 23 | mainClassName = "com.pokegoapi.examples.UseIncenseExample" 24 | } else if (sample == "7") { 25 | mainClassName = "com.pokegoapi.examples.TranslatePokenameExample" 26 | } 27 | run.execute() 28 | } -------------------------------------------------------------------------------- /sample/src/main/java/com/pokegoapi/examples/CheckEvolutionExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.examples; 17 | 18 | import POGOProtos.Enums.PokemonIdOuterClass.PokemonId; 19 | import com.pokegoapi.api.PokemonGo; 20 | import com.pokegoapi.api.pokemon.Evolutions; 21 | import com.pokegoapi.auth.PtcCredentialProvider; 22 | import com.pokegoapi.exceptions.request.RequestFailedException; 23 | import com.pokegoapi.util.Log; 24 | import com.pokegoapi.util.hash.HashProvider; 25 | import okhttp3.OkHttpClient; 26 | 27 | import java.util.List; 28 | 29 | public class CheckEvolutionExample { 30 | 31 | /** 32 | * Displays pokemon evolutions 33 | * 34 | * @param args Not used 35 | */ 36 | public static void main(String[] args) { 37 | OkHttpClient http = new OkHttpClient(); 38 | final PokemonGo api = new PokemonGo(http); 39 | try { 40 | //Login and set location 41 | HashProvider hasher = ExampleConstants.getHashProvider(); 42 | api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE); 43 | api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher); 44 | 45 | //Get the evolution meta from the item templates received from the game server 46 | Evolutions evolutionMeta = api.itemTemplates.evolutions; 47 | 48 | System.out.println("Evolutions: "); 49 | for (PokemonId pokemon : PokemonId.values()) { 50 | List evolutions = evolutionMeta.getEvolutions(pokemon); 51 | if (evolutions.size() > 0) { 52 | System.out.println(pokemon + " -> " + evolutions); 53 | } 54 | } 55 | System.out.println(); 56 | System.out.println("Most basic: "); 57 | for (PokemonId pokemon : PokemonId.values()) { 58 | List basic = evolutionMeta.getBasic(pokemon); 59 | if (basic.size() > 0) { 60 | //Check this is not the most basic pokemon 61 | if (!(basic.size() == 1 && basic.contains(pokemon))) { 62 | System.out.println(pokemon + " -> " + basic); 63 | } 64 | } 65 | } 66 | System.out.println(); 67 | System.out.println("Highest: "); 68 | for (PokemonId pokemon : PokemonId.values()) { 69 | List highest = evolutionMeta.getHighest(pokemon); 70 | if (highest.size() > 0) { 71 | //Check this is not the highest pokemon 72 | if (!(highest.size() == 1 && highest.contains(pokemon))) { 73 | System.out.println(pokemon + " -> " + highest); 74 | } 75 | } 76 | } 77 | } catch (RequestFailedException e) { 78 | // failed to login, invalid credentials, auth issue or server issue. 79 | Log.e("Main", "Failed to login, captcha or server issue: ", e); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /sample/src/main/java/com/pokegoapi/examples/DisplayPokenameExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.examples; 17 | 18 | import com.pokegoapi.util.Log; 19 | import com.pokegoapi.util.PokeDictionary; 20 | 21 | import java.util.Locale; 22 | import java.util.MissingResourceException; 23 | 24 | import static com.pokegoapi.util.PokeDictionary.supportedLocales; 25 | 26 | public class DisplayPokenameExample { 27 | 28 | /** 29 | * Displays All 151 Pokemon Names for all Supported Locales 30 | * 31 | * @param args Not used 32 | */ 33 | public static void main(String[] args) { 34 | for (int i = 1; i < 152; i++) { 35 | //Showcase for Supported Languages 36 | for (Locale l : supportedLocales) { 37 | try { 38 | System.out.println(String.format( 39 | l, 40 | "%s: Pokedex #%d is %s\n %s", 41 | l.getDisplayName(l), 42 | i, 43 | PokeDictionary.getDisplayName(i, l), 44 | PokeDictionary.getDisplayDescription(i, l))); 45 | } catch (MissingResourceException e) { 46 | Log.e("Main", "Unable to find Pokemon name with given Pokedex: " + i, e); 47 | } 48 | } 49 | //Showcase for Fallback Behaviour 50 | try { 51 | System.out.println(String.format( 52 | "%s: Pokedex# %d is %s\n %s", 53 | "Fallback", 54 | i, 55 | PokeDictionary.getDisplayName(i, new Locale("xx")), 56 | PokeDictionary.getDisplayDescription(i, new Locale("xx")))); 57 | } catch (MissingResourceException e) { 58 | Log.e("Main", "Unable to find Pokemon name with given Pokedex: ", e); 59 | } 60 | System.out.println(); 61 | } 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /sample/src/main/java/com/pokegoapi/examples/ExampleConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.examples; 17 | 18 | import com.pokegoapi.util.hash.HashProvider; 19 | import com.pokegoapi.util.hash.pokehash.PokeHashKey; 20 | import com.pokegoapi.util.hash.pokehash.PokeHashProvider; 21 | 22 | /** 23 | * Created by court on 19/07/2016. 24 | */ 25 | public class ExampleConstants { 26 | 27 | public static final String LOGIN = ""; 28 | public static final String PASSWORD = ""; 29 | public static final double LATITUDE = -32.058087; 30 | public static final double LONGITUDE = 115.744325; 31 | public static final double ALTITUDE = Math.random() * 15.0; 32 | public static final String POKEHASH_KEY = ""; 33 | 34 | /** 35 | * Creates the appropriate hash provider, based on if the POKEHASH_KEY property is set or not 36 | * @return a hash provider 37 | */ 38 | public static HashProvider getHashProvider() { 39 | if (POKEHASH_KEY != null && POKEHASH_KEY.length() > 0) { 40 | return new PokeHashProvider(PokeHashKey.from(POKEHASH_KEY), true); 41 | } 42 | throw new IllegalStateException("Cannot start example without hash key"); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sample/src/main/java/com/pokegoapi/examples/GoogleUserInteractionExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.examples; 17 | 18 | 19 | import com.pokegoapi.auth.GoogleUserCredentialProvider; 20 | import com.pokegoapi.exceptions.request.RequestFailedException; 21 | import okhttp3.OkHttpClient; 22 | 23 | import java.util.Scanner; 24 | 25 | public class GoogleUserInteractionExample { 26 | 27 | /** 28 | * Example on how to login with Google by asking a token from the user 29 | * @param args stuff 30 | */ 31 | public static void main(String[] args) { 32 | OkHttpClient http = new OkHttpClient(); 33 | try { 34 | // instanciate a provider, it will give an url 35 | GoogleUserCredentialProvider provider = new GoogleUserCredentialProvider(http); 36 | 37 | // in this url, you will get a code for the google account that is logged 38 | System.out.println("Please go to " + provider.LOGIN_URL); 39 | System.out.println("Enter authorisation code:"); 40 | 41 | // Ask the user to enter it in the standard input 42 | Scanner sc = new Scanner(System.in); 43 | String access = sc.nextLine(); 44 | 45 | // we should be able to login with this token 46 | provider.login(access); 47 | System.out.println("Refresh token:" + provider.refreshToken); 48 | 49 | } catch (RequestFailedException e) { 50 | e.printStackTrace(); 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sample/src/main/java/com/pokegoapi/examples/TransferOnePidgeyExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.examples; 17 | 18 | import POGOProtos.Enums.PokemonIdOuterClass; 19 | import POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass; 20 | import com.pokegoapi.api.PokemonGo; 21 | import com.pokegoapi.api.pokemon.Pokemon; 22 | import com.pokegoapi.auth.PtcCredentialProvider; 23 | import com.pokegoapi.exceptions.request.RequestFailedException; 24 | import com.pokegoapi.util.Log; 25 | import com.pokegoapi.util.hash.HashProvider; 26 | import okhttp3.OkHttpClient; 27 | 28 | import java.util.List; 29 | 30 | public class TransferOnePidgeyExample { 31 | /** 32 | * Transfers one pidgey from the player's inventory. 33 | */ 34 | public static void main(String[] args) { 35 | OkHttpClient http = new OkHttpClient(); 36 | 37 | PokemonGo api = new PokemonGo(http); 38 | try { 39 | HashProvider hasher = ExampleConstants.getHashProvider(); 40 | api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher); 41 | api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE); 42 | 43 | List pidgeys = 44 | api.inventories.pokebank.getPokemonByPokemonId(PokemonIdOuterClass.PokemonId.PIDGEY); 45 | 46 | if (pidgeys.size() > 0) { 47 | Pokemon pest = pidgeys.get(0); 48 | // print the pokemon data 49 | pest.debug(); 50 | ReleasePokemonResponseOuterClass.ReleasePokemonResponse.Result result = pest.transferPokemon(); 51 | 52 | Log.i("Main", "Transfered Pidgey result:" + result); 53 | } else { 54 | Log.i("Main", "You have no pidgeys :O"); 55 | } 56 | } catch (RequestFailedException e) { 57 | // failed to login, invalid credentials, auth issue or server issue. 58 | Log.e("Main", "Failed to login. Invalid credentials, captcha or server issue: ", e); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /sample/src/main/java/com/pokegoapi/examples/TranslatePokenameExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | package com.pokegoapi.examples; 17 | 18 | import com.pokegoapi.util.Log; 19 | import com.pokegoapi.util.PokeDictionary; 20 | 21 | import java.util.Locale; 22 | import java.util.MissingResourceException; 23 | 24 | /** 25 | * Created by Angelo on 18.08.2016. 26 | */ 27 | public class TranslatePokenameExample { 28 | /** 29 | * Displays All 151 Pokemon Names for all Supported Locales 30 | * 31 | * @param args Not used 32 | */ 33 | public static void main(String[] args) { 34 | // Translate English Pokemon name to Simplified Chinese 35 | // Note: You can use PokeDictionary.getDisplayName(int pokedexId, Locale locale) 36 | // instead, if you already know the Pokedex Id. 37 | // See DisplayPokenameExample for an example. 38 | Locale chs = new Locale("zh", "CN"); 39 | for (int i = 1; i < 152; i++) { 40 | try { 41 | System.out.println(String.format( 42 | chs, 43 | "Pokedex# %d is %s in %s", 44 | i, 45 | PokeDictionary.translateName(PokeDictionary.getDisplayName(i, Locale.ENGLISH), chs), 46 | chs.getDisplayName(chs))); 47 | } catch (MissingResourceException e) { 48 | Log.e("Main", "Unable to find Pokemon name with given Pokedex: ", e); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sample/src/main/java/com/pokegoapi/examples/UseIncenseExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is free software: you can redistribute it and/or modify 3 | * it under the terms of the GNU General Public License as published by 4 | * the Free Software Foundation, either version 3 of the License, or 5 | * (at your option) any later version. 6 | * 7 | * This program is distributed in the hope that it will be useful, 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 | * GNU General Public License for more details. 11 | * 12 | * You should have received a copy of the GNU General Public License 13 | * along with this program. If not, see . 14 | */ 15 | 16 | /* 17 | * This program is free software: you can redistribute it and/or modify 18 | * it under the terms of the GNU General Public License as published by 19 | * the Free Software Foundation, either version 3 of the License, or 20 | * (at your option) any later version. 21 | * 22 | * This program is distributed in the hope that it will be useful, 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 25 | * GNU General Public License for more details. 26 | * 27 | * You should have received a copy of the GNU General Public License 28 | * along with this program. If not, see . 29 | */ 30 | 31 | package com.pokegoapi.examples; 32 | 33 | 34 | import com.pokegoapi.api.PokemonGo; 35 | import com.pokegoapi.auth.PtcCredentialProvider; 36 | import com.pokegoapi.exceptions.request.RequestFailedException; 37 | import com.pokegoapi.util.Log; 38 | import com.pokegoapi.util.SystemTimeImpl; 39 | import com.pokegoapi.util.hash.HashProvider; 40 | import okhttp3.OkHttpClient; 41 | 42 | public class UseIncenseExample { 43 | /** 44 | * Catches a pokemon at an area. 45 | */ 46 | public static void main(String[] args) { 47 | OkHttpClient http = new OkHttpClient(); 48 | 49 | PokemonGo api = new PokemonGo(http, new SystemTimeImpl()); 50 | 51 | try { 52 | HashProvider hasher = ExampleConstants.getHashProvider(); 53 | api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher); 54 | api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE); 55 | api.inventories.itemBag.useIncense(); 56 | } catch (RequestFailedException e) { 57 | // failed to login, invalid credentials, auth issue or server issue. 58 | Log.e("Main", "Failed to login, captcha or server issue: ", e); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':library', ':sample' --------------------------------------------------------------------------------