PaperMC / PaperLib

Plugin Library for interfacing with Paper Specific API's with graceful fallback that maintains Spigot Compatibility, such as Async Chunk Loading.
MIT License
269 stars 31 forks source link

Added support for getOfflinePlayer(String) with optional cache #35

Open TheBusyBiscuit opened 3 years ago

TheBusyBiscuit commented 3 years ago

https://github.com/PaperMC/Paper/pull/4687 has introduced the ability to get an OfflinePlayer by their name without making a web request.

To properly utilise this feature in a Spigot-compatible environment, we currently need to rely on an isPaper and a version check to even see whether one is able to optimize for that. I think this is a perfect opportunity for a PaperLib implementation.

This is just a basic implementation which was done in a similar manner to how the BlockStateSnapshot is handled. The boolean makeWebRequest determines whether a web request is allowed. In environments that do not support Bukkit.getOfflinePlayerIfCached(), this boolean is just ignored. Similar to how BlockStateSnapshot will ignore the useSnapshot boolean if unsupported.

Of course, the Bukkit.getOfflinePlayerIfCached() method will not be available in every single 1.16.4-compatible build of Paper I presume, but I am gonna assume the typical "old versions are not supported anyway" situation here for now. Lemme know if there is anything that should be changed or documented.

TheBusyBiscuit commented 3 years ago

Thanks for the input!

you're missing the helper method in the PaperLib class (and its javadocs)

Whoops, I somehow completely forgot about that, thanks for spotting it. I agree with the name changes for the classes as they seem more reflective of the internal logic here, also implemented the reflection-check you suggested for the method. Probably much better than simply relying on people to update their software.