Hi i use this code to spawn wolves but when the target is dead the wolves attacks other players! Or when i set tarmetwolf to true then the wolves are friendly but the don't follow my commands! Whats wrong i dont know. Code: Wolf w = (Wolf) player.getWorld().spawnCreature(loc, ct); w.setTarget(owner); w.setAngry(true); if(tarmetwolf){ w.setAngry(false); w.setTamed(true); } w.setSitting(false);
You can simply check if the target is alive if(owner.getHealth() >0) w.setTarget(owner); For not following commands you need to tell the wolf who the owner is by using setOwner
Code:java public void onEntityDeath(EntityDeathEvent event) { if (event.getEntity() instanceof Player) { Player victim = (Player) event.getEntity(); Wolf killer = null; if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent nEvent = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause(); if (nEvent.getDamager() instanceof Wolf) { killer = (Wolf) nEvent.getDamager(); } } //do stuff }}