Find an entity from a lead

Discussion in 'Plugin Development' started by EvilWitchdoctor, Aug 5, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    EvilWitchdoctor

    Quick question: It is possible to find the entity leashed from a LeashHitch?
    In other words, I have a leash entity but am not seeing a method to find the entity attached to the leash.
    If all else fails, I can use getNearbyEntities() and see which one has the LeashHitch as its leashHolder()... although I'm not even sure if that works yet :)
     
  2. Offline

    Luke_Lax

  3. Offline

    EvilWitchdoctor

    Yes, that is the event I am using :) but I am not looking to see who clicked the leashHitch, I am trying to find the entity on the other end of the leash

    Well I worked out a roundabout way of doing it. The following code works perfectly, I just wish there was a simpler solution ;)
    Please feel free to still reply if you have any better or more efficient ideas

    Code:java
    1. if(event.getRightClicked() instanceof LeashHitch){
    2. LeashHitch leash = (LeashHitch) event.getRightClicked();
    3.  
    4. for(Entity entity : leash.getNearbyEntities(15, 15, 15)){
    5. if(entity instanceof Horse){
    6. Horse horse = (Horse) entity;
    7. if(horse.isLeashed() && horse.getLeashHolder().getUniqueId().equals(leash.getUniqueId())){
    8. if(isPrivateHorse(horse) && isOwner(player, horse) == false){
    9. event.setCancelled(true);
    10. player.sendMessage("§cYou do not have permission to unleash this horse.");
    11. }
    12. }
    13. }
    14. }
    15. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page