PaperLib icon indicating copy to clipboard operation
PaperLib copied to clipboard

Added support for getOfflinePlayer(String) with optional cache

Open TheBusyBiscuit opened this issue 3 years ago • 1 comments

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 avatar Jan 04 '21 13:01 TheBusyBiscuit

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.

TheBusyBiscuit avatar Jan 04 '21 14:01 TheBusyBiscuit