Solved How can a Player be "not valid?"

  • After careful consideration and due to limited usage, we’ve made the decision to discontinue the PaperMC forums. Moving forward, we recommend using Hangar for plugin uploads, and for all other community discussions and support, please join us on Discord.

Pare06

New member
Feb 16, 2024
2
0
1
When a player disconnects and then reconnects to my server, calling player.isValid() returns false, and it makes some things not work, like player.setScoreboard() (not showing any scoreboard) and player.teleport() (which returns false). How can isValid() return false? The documentation says that it "returns false if the entity has died, been despawned for some other reason, or has not been added to the world" - but it can't be dead or despawned, as the player can still move around and break/place blocks, and "not been added to the world" doesn't make sense to me either, since the player can interact with it... is there some other reason why isValid can return false?
 
Version Output
[16:38:46 INFO]: Checking version, please wait...
[16:38:47 INFO]: This server is running Paper version git-Paper-424 (MC: 1.20.4) (Implementing API version 1.20.4-R0.1-SNAPSHOT) (Git: 37df121)
You are running the latest version
Previous version: git-Paper-516 (MC: 1.19.4)

electronicboy

Administrator
Staff member
Dec 11, 2021
321
18
68
28
are you still holding onto the old player reference? if so, that is why. Your reference is holding onto an entity which is dead and no longer valid, you would need to get the new player instance.