Hi.
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?
Thanks
Hi.
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?
Thanks
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);
if(!user.isPresent()){
//User not found
return;
}
Instant lastplayed = user.get().get(Keys.LAST_DATE_PLAYED).get();
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?
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 UltimateCore.java:227 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.