1.8.8 Check if player has permission in the PreLogin event?

Discussion in 'Spigot Plugin Development' started by Hibbix, May 19, 2020.

  1. Hi, is it possible to check if a player has a certain permission in the PlayerPreLogin event? I'm using LuckPerms, but I'd prefer not to have another dependency. I want to make it so that if they have permission, they get accepted, but if they don't, they get denied entry.
  2. Get the player from the event when the event is fired, and then do if (Player#hasPermission(“some.permission.node”))

    EDIT: Note that PlayerPreLoginEvent is deprecated and you need to use AsyncPlayerPreLoginEvent.
  3. How do I get the player? I can't do event.getPlayer()
  4. You can do event.getUniqueId(). Then you can do Bukkit.getPlayer(uuid)
  5. But isn't the player technically offline because they haven't logged in yet?
  6. PlayerJoinEvent?

    Sent from my iPhone using Tapatalk
  7. I'd rather block it earlier, because then all my other events fire.
  8. Probably, it’s been awhile since I’ve used that event. Couldn’t you do PlayerJoinEvent, check perm and then kick them?

    EDIT: Just read your other post. Look into PlayerLoginEvent. If I remember right it’s fired after PreLogin, but Before Join. I have to head to work, so I can’t look to see if it’ll do what you need
    #8 Justin393, May 19, 2020
    Last edited: May 19, 2020
  10. Ok, thank you!
    I'll try it out.