Setting PlayerProfile breaks getPlayerExact()? (1.15)

Hi,

I’m assuming I’m doing something wrong here. I’m trying to set the player tag via PlayerProfile but when I do it breaks any calls to Server.getPlayerExact(). Here’s an example:

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (sender instanceof Player) {
        Player player = (Player) sender;
        switch (label) {
        case "login":
            String oldName = player.getName();
            String newName = args[0];
            PlayerProfile profile = player.getPlayerProfile();
            profile.setName(newName);
            player.setPlayerProfile(profile);
            log.info("Renamed player [" + oldName + "] to [" + newName + "]");
            // fall-through
        case "logininfo":
            log.info("player.getName(): " + player.getName());
            log.info("player.getPlayerProfile().getName(): " + player.getPlayerProfile().getName());
            log.info("Bukkit.getServer().getPlayerExact(player.getName()): "
                    + Bukkit.getServer().getPlayerExact(player.getName()));
            break;
        }
    }
    return true;
}

That results in these log messages:

[22:51:52 INFO]: marwatk issued server command: /login foobar
[22:51:52 INFO]: Renamed player [marwatk] to [foobar]
[22:51:52 INFO]: player.getName(): foobar
[22:51:52 INFO]: player.getPlayerProfile().getName(): foobar
[22:51:52 INFO]: Bukkit.getServer().getPlayerExact(player.getName()): null

Digging in it seems that getPlayerExact() calls playerList.getPlayer() which just iterates over players checking entityplayer.getName() against the input. EntityPlayer gets its getName() from EntityHuman which calls GameProfile.getName(). That’s where the trail ends, and I’m guessing the GameProfile or the player instance isn’t the same object as the set in the PlayerProfile, but I would have assumed setting the PlayerProfile would set the appropriate fields in the GameProfile. Is that not correct? What am I missing?

Thanks for any insight!

This does not work. You’re updating the PlayerProfile name without removing the old mapEntry and add the new one.

Thanks for the response! Is reflection the only way to do that? It doesn’t seem there’s a Paper api to alter the playerList.