Forcing the pet defend the player

Discussion in 'Plugin Development' started by Zenok, Jan 15, 2014.

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

    Zenok

    How I can set up a pet to attack a mob?

    I'm storing the pet in a HashMap, and when the player is attacked by the pet should attack the mob, but no

    Code:java
    1. public void onEntityDamage(EntityDamageByEntityEvent event) {
    2.  
    3. if(!(event.getDamager() instanceof Player)){
    4. Player player = (Player) event.getEntity();
    5. LivingEntity damager = (LivingEntity) event.getDamager();
    6.  
    7. if(Pets.containsKey(player.getName())) {
    8.  
    9. Entity playerPet = Pets.get(player.getName());
    10. //IF PLAYER IS THE PET OWNER CANCEL EVENT
    11. if(playerPet.getUniqueId().hashCode() == damager.getUniqueId().hashCode()) {
    12. event.setCancelled(true);
    13. } else {
    14. //DEFEND PLAYER
    15. Creature pet = (Creature) playerPet;
    16. pet.setTarget(damager);
    17. }
    18. }
    19. }
    20. }


    What is wrong?
     
  2. Offline

    Scullyking

    This library makes it easy to do what your doing, plus a hell of a load more, with any mob.
     
Thread Status:
Not open for further replies.

Share This Page