Get Last Played Instance of Offline Player


As the title suggests, is this possible? The lastPlayed method (returning an Instant) can only be called on a Player object.

Am I missing data provided by another service?


I think a “player” object is just a player’s name. Did you try that?

Try this

UUID uuid = null;//Some uuid
UserStorageService service = Sponge.getServiceManager().provide(UserStorageService.class).get();
Optional<User> user = service.get(uuid);
    //User not found
Instant lastplayed = user.get().get(Keys.LAST_DATE_PLAYED).get();
1 Like

I’m testing now but this looks to be the solution!

Many thanks

EDIT: Actually, I get a “no value present” exception on a user that has definitely joined before.

Any ideas?

1 Like

Shouldn’t happen. Did you maybe delete the cache? If you have multiple accounts try using that instead.

I can confirm that code does not work.
Getting this error:

(Where is this line “Optional user = service.get(uuid);”)

Sponge’s UserStorageService only works properly once the server has started. Try on GameStartedServerEvent or later.

This happens after that event.

Any other ideas?

Bump @simon816

Is this fixed in 6.0.0, I’m using 5.1.0

It should work just fine. Try firing it from some dummy command?

Just a thought but did you actually put a value in the uuid variable or just copy paste this line

UUID uuid = null;//Some uuid


Oh I know why this isn’t working. Currently, the data API is not hooked up to offline players, so this data will only be available when players are online.