1.8.8 OfflinePlayer#getName Throwing NPE

Discussion in 'Spigot Plugin Development' started by Demeng, Mar 21, 2020.

Thread Status:
Not open for further replies.
  1. Hello,

    Does anyone know why this line is throwing an NPE?
    Code (Text):
    for (OfflinePlayer p : Bukkit.getServer().getOfflinePlayers()) offlinePlayers.add(p.getName().toLowerCase());
  2. nah. if someone sends a join request and times out before a certain part of the join process or just quits joining, their uuid is stored but not the name, for one example. am sure there are other examples.
  3. Ah. So what are some methods I can, for example, prevent people from banning a non-existent player through a /ban <name> command?
  4. you can go about what youre doing. however, if they dont have a name, theyve never been in the server, so just skip the offlineplayers with null names
    • Like Like x 1
  5. You should simply store their UUID.
    • Agree Agree x 1
  6. That doesn’t help me in this scenario :p
  7. Not sure why that isn't working. Just tested it on my onDisable and worked perfectly fine. What is it you're trying to do?
  8. But the problem should be solved with this suggestion:
  9. Could just do a simple check to see if they've played before?
  10. while i can see where you're goign with this, that still doesnt work. hes making a command that /ban [username] that he wants to extend to players that are offline. uuids are useless in the sense of looking up the offlineplayer if he only knows the username. nullchecking the name or using #hasPlayedBefore would essentially achieve the same effect, but #hasPlayedBefore would make more sense to use.

    /e honestly what i'd do is ditch the collection in general and use Server#getOfflinePlayer and if the object is null, just return a msg saying that user does not exist.
Thread Status:
Not open for further replies.