Bukkit.getOfflinePlayer() sometimes does not work

Discussion in 'Spigot Plugin Development' started by MicleBrick, May 30, 2018.

  1. When supplied a valid username for a player who has not logged on for a long time, Bukkit.getOfflinePlayer() sometimes does not work properly. I checked on NameMC to make sure their name hasn't changed or anything like that.

    offlinePlayer.hasPlayedBefore() || offlinePlayer.isOnline() || offlinePlayer.getUniqueId() != null returns false for these players.
     
  2. Regarding the statement returning false, that's impossible, because getUniqueId is never null. That will always return true, thus your statement would return true. So something else is missing that is vital information. Be mindful that the server's world file must have that player's playerdata (created when the server is joined) for there to be valid OfflinePlayer data. If it's a new world and the player has yet to join since the new world, #hasPlayedBefore will return false.
     
    • Like Like x 1
    • Agree Agree x 1
  3. did you checked out if your args are fromated as it?
     
  4. Use Bukkit#getServer()#getOfflinePlayer();

    I've had the same problem, this Method should work
     
    • Funny Funny x 1
  5. MiniDigger

    Supporter

    jokes on you, Bukkit.getOfflinePlayer(..) calls getServer().getOfflinePlayer(..) :D
    (just like any other method in the bukkit class btw)
     
    • Funny Funny x 4
  6. I've always had that return null for people it can't find. I checked, their UUID is still in the playerdata folder (there's no new world).
     
  7. The reason it doesnt work for really old users is because this method does not check the world files. Instead it's checking the cached users file, located at the root of the server directory. Sadly, this cache does have an expire date per entry, so old entries are lost in time. I had made my own usercache system in the past that doesnt ever expire for this reason, but all plugins I made that required it as a dependency didnt go across well to server admins. They hated and didnt understand the extra dependency.
     
    • Like Like x 1
  8. Ah. So, should I disable the user cache by setting the user cache limit to 0 in spigot.yml?