1.15.2 Testing whether a "Player" is a fake or real player?

Discussion in 'Spigot Plugin Development' started by fujiboy4, Apr 23, 2021.

  1. Hello all, I am working on testing if a player is a fake or a real player. By fake, I mean an NPC using Citizens or other-like plugins. I want to be able to distinguish the difference between them so when my plugin kicks the players from the server it doesn't also kick the NPCs. So far, I've done some research and found something involving metadata from 2016, although, I do not know if this works now. Something to the effect of:
    Code (Text):
    player.getMetaData("NPC");
    If anyone has any suggestions for this and/or testing player behavior to determine if it's an NPC or not, please let me know. Thanks!

    This also is not exclusive to 1.15.2, that's the API I have downloaded (haven't programmed Minecraft plugins in a while), but if there is a solution for newer versions I can quickly download those as well.
     
  2. Hello, you can use Bukkit#getPlayer(), this will return null if the player is undefined for a given name
     
  3. I've just checked the Citizens wiki, and this should work. For Citizens NPCs at least.

    boolean isCitizensNPC = entity.hasMetadata("NPC");
     
    • Agree Agree x 1