[SPIGOT-862] OfflinePlayer#hasPlayedBefore is not accurate. Created: 04/May/15  Updated: 21/May/15  Resolved: 21/May/15

Status: Closed
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: jjm_223 Assignee: Unassigned
Resolution: Invalid Votes: 0
Labels: 1.8.3, bug, bukkit
Environment:
  • Java version 1.8.0_31
  • Spigot version git-Spigot-870264a-0a645a2 (MC: 1.8.3) (Implementing API version 1.8.3-R0.1-SNAPSHOT)

Attachments: Java Source File HasPlayedBefore.java     PNG File Testing.png    

 Description   

In the attached image, it shows two logins and a command ran upon entry both times. The first time, as shown, the plugin returns that the player has not played before. The second time, done after reconnecting, shows that the player has played before.

This is a major issue in some cases, as many plugins use this to decide whether or not to save a file. An example is shown in a plugin called "EasyChests." It does not save a new player's chest, as hasPlayedBefore() returns false on them.



 Comments   
Comment by jjm_223 [ 21/May/15 ]

Well in my case I was working on a voting listener. I used the method thinking it would say if an offline player has ever been on the server. My goal was to filter out usernames that were entered wrong, so essentials didn't create useless player files when the non-existent people were awarded money.

Now that I am aware of what the method does, I've realized it is working correctly.

Comment by Joshua Küpper [ 21/May/15 ]

I'd guess the thing he was talking about is that hasPlayedBefore() should return true, from the moment on, the player connects from the first time the player connects and not from the first time a player disconnects. To clarify it even more, here's a sequence of events:

? - Player xy hasn't played before.
! - Player xy joins the server for the first time.
? - Player xy hasn't played before. <---- That's the thing the OP wants to be changed.
! - Player xy quits the server for the first time.
? - Player xy has played before.

My personal opinion on this:
I'd like this to be unchanged, since as OP stated you're able to couple the current result with isOnline() and with the mechanic how it currently is you can see if a player is currently playing for the first time, which would be really harder if it would be different.

Comment by md_5 [ 21/May/15 ]

What result are you looking for?

hasPlayedBefore() will return false only once, the first time the player logs in.

Is that different from what you are seeing?

Comment by jjm_223 [ 21/May/15 ]

Well, okay.

Now that I think about it, that makes sense. I suppose I can just couple that with isOnline to get the result I'm looking for.

Thanks for your time. It's a shame that my first report is invalid.

Comment by md_5 [ 21/May/15 ]

Yes, that is what the method is meant to do.

Comment by jjm_223 [ 21/May/15 ]

New players, as in players that recently joined the server for the first time, are not considered to have played before by the method.

My screenshot shows this. When I join for the first time, it states I haven't played before. If I reconnect, it is accurate.

Comment by md_5 [ 21/May/15 ]

I don't understand, perhaps explain better. In your screenshot it looks like no issue.

Generated at Mon Apr 07 22:29:24 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.