Skip to content

OfflinePlayer#getPlayer causes weird behaviour if player was originally online but have re-logged since #12107

@LichtHund

Description

@LichtHund

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions