Solved Bukkit#getPlayerExact returns null if player's GameProfile is changed.

Discussion in 'Spigot Plugin Development' started by NotNV6, Feb 25, 2020.

  1. Okay, so I'm trying to change the player's GameProfile for reasons, but Bukkit#getPlayerExact breaks by doing so. Things such as Bukkit#getPlayer still return the player, but Bukkit#getPlayerExact returns null. Does anyone have any reason/solution for this?

    Thanks,

    NotNV6.
     
  2. How exactly are you changing the GameProfile; are you altering the name?
    edit: are you using reflection?
     
  3. Yes, I'm using reflections to change the GameProfile.
     
  4. But are you changing the name?
    I suppose you are directly accessing the variables and don't invoke any setters (mainly because there probably aren't any), correct?
     
  5. MiniDigger

    Supporter

    I"am changing the thing that is used to identify the player and now I can't get the player anymore, pls help!"

    If you want any real help, tell us what you are doing with the Gameprofile and why, with code.
     
    • Funny Funny x 1
    • Winner Winner x 1
  6. I'm completely changing the GameProfile of the player to a new one, I'm setting the field of the GameProfile inside of the EntityPlayer class.

    ^ changing the fields with reflections
     
    #6 NotNV6, Feb 25, 2020
    Last edited: Feb 25, 2020
  7. As I mentioned before, Bukkit.getPlayer does work properly and Bukkit.getPlayerExact does not. CraftPlayer#getName returns the name of the new GameProfile which it should - but Bukkit.getPlayerExact doesn't return the player if searching by the same name.
     
  8. SteelPhoenix

    Moderator

    #getPlayerExact() finds a user based on a cached name value in the NMS's DedicatedPlayerList
     
  9. CraftServer#getPlayerExact() checks if the passed parameter (the name) equals player.getName().

    Edit: It seems like the spigot api I use as dependency from maven has a different #getPlayerExact() method than my spigot. (I'll try changing the cached name)
     
  10. Thanks, this helped. It works properly now.