[Solved] Player/User/GameProfile questions

Hello :slight_smile: My first post here! I was pretty heavy into private bukkit development, and I’m really glad to hear that I can get back to creating server plugins for minecraft now that sponge is pretty much good to go now!

Anyways, I have a question regarding the three classes above. Bukkit’s Player object implemented OfflinePlayer, and the api had the ability to differentiate whether you wanted to grab a player that wasn’t necessarily online (by getting an OfflinePlayer object, checking isOnline(), and then casting to Player).

I see that for sponge, User is implemented by Player, and I’m assuming that this is the same dealio in Sponge, however I cannot seem to find out how to get a User object. Ideally, i would love to be able to grab them by current username, but I can deal with just the UUID. I understand that it is possible to grab a GameProfile from the game profile manager, however I’m not sure what to do with that after getting it, or even if that’s relevant. It seems all that I can do with a game profile is grab the UUID and the username…

Anyways, My problem is this. How can i grab the User object (which I’m assuming, hopefully correctly, represents an online or offline player) with at the very least just the UUID, and hopefully with the username.

Thanks! :smile:

Take a look at the UserStorageService
You can obtain an instance through the service manager

Optional<UserStorageService> optStorage = Sponge.getServiceManager().provide(UserStorageService.class);
1 Like

Thanks a ton! :slight_smile: I was actually just tinkering around with this when you replied. I have two questions, if you dont mind me asking.

Firstly, When is the user storage service contractually obligated to be available for full use in the server lifecycle?

Secondly, I seem to be having an issue with my tinkering. When trying to grab a user by the UUID (and making sure the map has the UUID in playerdata folder) the server cannot find the user data.

public void onLoadComplete(GameLoadCompleteEvent event) {
	Optional<ProviderRegistration<UserStorageService>> optprov = Sponge.getServiceManager().getRegistration(UserStorageService.class);
	logger.info("Is optprov present? " + optprov.isPresent());
	if(optprov.isPresent()) {
		ProviderRegistration<UserStorageService> provreg = optprov.get();
		UserStorageService uss = provreg.getProvider();
		logger.info("Obtained user storage service");
		//This throws a null pointer exception in getFromStoredData(uniqueID) in the UserDiscoverer
		//originating from the SaveHandler pulling up no user profiles, even though it does exist.
		Optional<User> usr = uss.get(UUID.fromString("5bbb155c-c564-4b7c-970d-5116506172f5"));
		logger.info("Is user Blossom_Forth present? " + usr.isPresent());
		if(usr.isPresent()) {
			logger.info("Username found!" + usr.get().getName());

Does this make sense to you?

Again, thanks for the reply :smiley:

I don’t think it’s actually defined anywhere but I can tell you that it will only work when the server has started to load (after the initialization phase), this is because it has to fetch data from the world storage and worlds are not available in the init phase.

I think that answers your second question too because you’re using it in the GameLoadCompleteEvent event which is before worlds load, try GameStartingServerEvent.

1 Like

Brilliant! Thanks a ton :heart_eyes:

1 Like