Get an instance of Player through a UUID

I was currently developing a command used to transport a user to a specific world and I would like to know how to get an instance of Player through a username String?

Well first off getting through a username string is different than a UUID, but nevertheless this is easily done by looking through related functions:

String UsernameString = "Notch";
String uuid = "MY-UUID-THING-THING";
gameInstace.getServer().getPlayer(UsernameString);
gameInstance.getServer().getPlayer(UUID.fromString(uuid));
4 Likes

If you are doing it from a command the easiest way is to have a Player argument on the CommandSpec, then Sponge will take care of it for you and you don’t need to stuff around with strings or UUID’s.