Checking if new player

Okay in version 2.0 of SpongeAPI, there was a way to figure out if it’s the first time for a player to join the server through:


The hasJoinedBefore() method was removed in 2.1 snapshot of SpongeAPI . Now, there are only two methods for JoinData class and they are getFirstPlayed() and getLastPlayed(). I think it’ll be too much of a hassle to figure out if a player has joined the server for the first time by figuring out the date in getFirstPlayed() method.

Any suggestions that I should do?


Perhaps a sponge developer could provide insight to this?

I 2 am interested :smile:

You could just check if their first join time was in the last two minutes.

Like OP said, it would make more sense to have a method that determines this logic for you. Doing date and time math isn’t a fun thing to do (personally) and could be avoided entirely if there was a method provided by sponge.

Bukkit had this, why doesn’t sponge?

Any devs willing to speak on this design choice?

I believe you just check for the presents/absents of JoinData

User user;
if (user.getData(JoinData.class).isPresent()) {
    // User has joined before
} else {
    // User never joined
1 Like

But wouldn’t that data be created before the plugin could check it?

Just a thought

If a User has NEVER logged into the server before, there wouldn’t be a JoinData to be created. Only if you call getOrCreate(JoinData.class) would it be created always for any User or Player.

I see @gabizou , I guess i was just curious as to how Sponge handled Player Data, this clarifies things. :smile:

@gabizou so if I’m trying to detect if a player has ever been on the server before when they join, JoinData will always be present if they have joined before or do I have to use getOrCreate(JoinData.class) to create it?

I think this is the best way to tell if it’s the first time for player to join the server by:

if(player.getJoinData().getLastPlayed() == null)

That’s the only way to tell if it’s new player on PlayerJoinEvent

afaik null is returned nowhere from the API, so this will probably not work.

Is there any solution to this?


We are in the process of rolling out the second revision to the Data API. I’ll see that this gets resolved.

As a temp solution, store new player uuid’s in a file for parsing later on. Just a thought.

You can save player data in a file (config file for example) when connected and check in the file if this UUID is writed, if it is, the player isn’t a new player.


I’m actually looking for a solution to this too. What’s the new solution with the 3.1.0 API?

EDIT: a thread was opened before and problem was solved. In other news I’m going to practice my organizational skills.

Looks like you’ve opened a new thread, just going to link it here