HypixelDev / PublicAPI

Official Java implementation of the Hypixel Public API.
https://api.hypixel.net
MIT License
533 stars 152 forks source link

Reworked pets to deprecate enums & use pet endpoint #557

Closed roro1506HD closed 1 year ago

roro1506HD commented 2 years ago

Reworked pets API to use the endpoint added by @ConnorLinfoot (https://github.com/HypixelDev/PublicAPI/pull/495#issuecomment-991637161) and to keep a backwards compatibility for people to be able to change before it gets removed.

The only breaking change is the return type of PetStat#getAllPets which now returns a Map<IPetType, Pet> instead of Map<PetType, Pet>.

The right way of getting pets of a player is to get the pet repository first (HypixelAPI#getPetRepository()) then use that repository in the Player's Player#getPetStats(IPetRepository) method. Providing a null repository or not providing one at all (for backwards compatibility, see BackwardsCompatibilityPetRepositoryImpl), will use the old PetType and Rarity enums instead. Unknown pets and null values are expected through the pets api when using the deprecated enums.

For the repositories, even though there are several specific getters (by name, by rarity.. etc), pets are only stored in a single collection. I have made the choice of sacrificing some computing time when using those getters to save some RAM as these methods are not expected to be used widely.

For a complete example, see GetPetsExample in the examples modules.

The javadoc hasn't been done, I expect to have feedbacks on the rework before losing my head doing the javadocs

roro1506HD commented 1 year ago

Latest commit introduces the javadoc for almost every api component (the implementations doesn't have javadocs as they would be the same as the interfaces).

It also renames the new PetStats#getAllPets to PetStats#listAllPets and brings back the old PetStats#getAllPets to fully maintain backwards compatibility.

Lastly it introduces a new method (IPetRepository#hasPlayerUnlocked) which can be used to check if a player has unlocked a certain pet type. This method is implemented in the AbstractPetRepositoryImpl class.

Looking forward to seeing your feedback for this commit!