Expected behavior
OfflinePlayer#getPlayer should return a valid Player instance at the moment it is called.
Observed/Actual behavior
OfflinePlayer#getPlayer created when the player was online and has since logged out and logged back in will return an outdated Player instance.
Steps/models to reproduce
Bukkit.getOfflinePlayer when the player is online.
- Player logs out and logs back in.
OfflinePlayer#getPlayer and try something like Player#openInventory.
Plugin and Datapack List
None.
Paper version
1.21.4-147-main@3bd69f2
Other
I'll start off by saying that I am not sure if this is intentional or not, so if it is then apologies.
Because Bukkit.getOfflinePlayer returns the Player instance itself when the player is online and Player#getPlayer returns this it can be an unexpected behavior. This makes it so if you are expecting an OfflinePlayer but want to do something extra if they are online, like sending a message, but they have since logged out and back again it'll simply not work making Bukkit.getPlayer(offlinePlayer.getUniqueId()) always the most reliable way of doing it.
Expected behavior
OfflinePlayer#getPlayershould return a validPlayerinstance at the moment it is called.Observed/Actual behavior
OfflinePlayer#getPlayercreated when the player was online and has since logged out and logged back in will return an outdatedPlayerinstance.Steps/models to reproduce
Bukkit.getOfflinePlayerwhen the player is online.OfflinePlayer#getPlayerand try something likePlayer#openInventory.Plugin and Datapack List
None.
Paper version
1.21.4-147-main@3bd69f2
Other
I'll start off by saying that I am not sure if this is intentional or not, so if it is then apologies.
Because
Bukkit.getOfflinePlayerreturns the Player instance itself when the player is online andPlayer#getPlayerreturnsthisit can be an unexpected behavior. This makes it so if you are expecting an OfflinePlayer but want to do something extra if they are online, like sending a message, but they have since logged out and back again it'll simply not work makingBukkit.getPlayer(offlinePlayer.getUniqueId())always the most reliable way of doing it.