If you only need the name for Players that have been on your Server at least once:
public Optional<String> getNameForUuid(UUID uuid){
UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
Optional<User> oUser = uss.get(uuid);
if (oUser.isPresent()){
// the name with which that player has been online the last time
String name = oUser.get().getName();
return Optional.of(name);
} else {
// a player with that uuid has never been on your server
return Optional.empty();
}
}
If you also need names for players that have never been on your server:
But please don’t use the last method on the main Thread! This method asks mojang’s servers for the name and that request can take a while. So run it asynchronously or do something else then get() on the CompletableFuture