Having trouble getting player UUIDs

OKAYYYYYY, I’m having loads of trouble getting a player’s UUID. I’m trying to get it so I can use their UUID’s instead of their name when they right click a sign to get a item.

// Dungeon Points Code
	public void addDungeonPoint(UUID uuid, String dungeonpointname) {

		List<String> currentstringlist = getConfig().getStringList(uuid);
		getConfig().set(uuid, currentstringlist);
		File file = new File("plugins/ZeldaWorld/config.yml");
		try {
		} catch (IOException e) {
			this.logger.severe("Error saving ZeldaWorld file!");

I’m not sure what you are asking for, but if you’re asking for a way to get a players UUID when he right clicks on a sign, this code will (most likely) do it: (i didn’t test it though)

    public void onInteract(PlayerInteractBlockEvent e) 
            Location block = e.getBlock();
            if(block.equals(BlockTypes.STANDING_SIGN) ||
                UUID uuid = e.getUser().getUniqueId();

Player implements the Identifiable Interface which allows you to just call getUniqueId() on them to get the UUID.

Also: Non-descriptive Title, unrelated Code… 2/10 would not answer again. Seriously, try to make your title somewhat descriptive in case someone happens to have the same problem. He / she will have a lot less trouble to find your post and phlinther1s answer then.


Once you have a Player object, just call getUniqueId() on the player to get the UUID

To get the player object, it may come from a variety of sources, most commonly a PlayerEvent
Call the method getEntity on the event to get the entity (A player in this case)

So, simply

public void handleSomePlayerEvent(SomePlayerEvent event) {
    Player player = event.getEntity();
    UUID uuid = player.getUniqueId();

you have event.getPlayer().getUniqueId()

try event.getEntity().getUniqueId()

Wait, which code is that? Is it even Sponge code? There is no event.getAction() when using PlayerInteractEvent and the annotation @EventHanlder doesn’t exist. In Sponge, @Subscribe is used instead of that. I never used the Bukkit API, but is this Bukkit code? This of course won’t work at all.

So you told us you get an error, but which one?

1 Like

Use UUID.fromString(String str).

One reason for an error here might be that you have your event

public boolean onBlockClick(PlayerInteractEvent event) {
     .... isPlayerHaveDungeonPoint(event.getPlayer.getUniqueId, someString) .... 
    // this is just an example call

and your method isPlayerHaveDungeonPoint requires 2 Strings, but event.getPlayer.getUniqueId doesn’t give you a String, but an UUID

My suggestion to solve your problem: Instead of trying to convert the players name into his UUID you should hand over the player object to your method, let me give you an example:

 // use the Player object in your methods

 public boolean onBlockClick(PlayerInteractEvent event) {
         // call your methods like this
         // mind that event.getPlayer() doesn't exist, use event.getUser()
         .... getPlayerDungeonPointsNumber(event.getUser) ....

public int getPlayerDungeonPointsNumber(Player player)
    // now you can easily get whatever you want, the name and the UUID of the player
    String username = player.getName();
    UUID uuid = player.getUniqueId();
public void addDungeonPoint(Player player, String dungeonpointname)
public boolean isPlayerHaveDungeonPoint(Player player, String dungeonpointname)

I hope your problem is solved now.

Oh well I see. Use this to get the players UUID from his name:

String playername;

// the Player object
Player p = game.getServer().getPlayer(playername).get(); 

UUID uuid = p.getUniqueId;

(NOTE: this doesn’t check if the player with the given name exists, you should check this before actually getting the player object)

you can get the game variable from an event: event.getGame()

I’ll be honest, I have no idea why you are posting Bukkit code and asking for help.

Either follow the multiple answers people have given you for the SpongeAPI, or post a new code example with SpongeAPI code that you are having troubles with.


Maybe it’s because it’s community isn’t really taking any interests in any of my post… or because bukkit forums is a little messed up at the moment, or because it’s hard to find people on there who would be willing to help you out. Or maybe a little bit of all. Sorry, am I too late to the party?

In all honesty, it’s a little hard to find help. This was my only option to seeing if someone could actually help me out here. Don’t get me wrong, I’ve been trying to fix this too. But to no luck. I thought someone here who actually used to code in Bukkit API could help, seeing as sponge was created almost entirely because the staff at bukkit didn’t like what mojang was doing. So I thought, people from bukkit would go here instead… turns out I’m sorta wrong huh? Sorry, I’ll take my work, and your guises suggestions when sponge ACTUALLY comes out with a stable build, and finished API.

It’s not so much that, but it’s confusing everyone what you are asking.

  1. Do you want help porting a plugin from bukkit to sponge?

Yes people will be happy to help, just make it clear.

or 2. Want help coding a Bukkit plugin?

People are probably NOT going to help, as this is the wrong place.

or 3. Want help coding a SpongeAPI plugin?

1 Like

So you want to say that you got no help, I see… I tried to help you as much as I could although it was very hard to understand what you actually wanted to know. However, my last post should solve your problem, at least if you were using the Sponge API. I thought you wanted to port your plugin, but you were actually looking for help with the Bukkit API in the Sponge forums? Well, in this case I wasted my time when trying to figure out what you are looking for. You didn’t even mention that you are looking for help with Bukkit code.