1.16.5 How to check if entity is leashed

Discussion in 'Spigot Plugin Development' started by PmzHeroV2, Jun 27, 2021.

  1. i want to check if org.bukkit.entity.Entity is leashed or no
     
  2. You can use #isLeashed, but it's not for all the entities. It's rather for some of its subclasses. For example, Horse#isLeashed is a method. Meanwhile, Player#isLeashed is not.
     
  3. You will have to listen to the leash and unleash event and do a list, where you store all entitys in and than check if the entity is in the list

    EDIT: As ZBLL said, I tested and the isLeashed() method is in LivingEntity Class, so everything that is implemented from a LivingEntity you can check if it is leashed
     
  4. LivingEntity has a method is Leashed
     
  5. Other entities can‘t be leashed anyways.

    Just do this:

    Code (Java):
    public boolean isLeashed(Entity entity) {
      if(entity instanceof LivingEntity) return ((LivingEntity) entity).isLeashed();
      return false;
    }
     
    • Like Like x 1