Remove pets in case they die.

This technically can't happen because all pet damage is cancelled, but we never know, and we best be sure to clean up.
This commit is contained in:
Andreas Troelsen 2019-08-05 16:04:44 +02:00
parent cb8983b162
commit ab031e3e63
2 changed files with 15 additions and 0 deletions

View File

@ -494,6 +494,9 @@ public class ArenaListener
if (event instanceof PlayerDeathEvent) {
onPlayerDeath((PlayerDeathEvent) event, (Player) event.getEntity());
}
else if (monsters.hasPet(event.getEntity())) {
monsters.removePet(event.getEntity());
}
else if (monsters.removeMonster(event.getEntity())) {
onMonsterDeath(event);
}

View File

@ -131,6 +131,18 @@ public class MonsterManager
return petToPlayer.containsKey(e);
}
public void removePet(Entity pet) {
pet.remove();
Player owner = petToPlayer.remove(pet);
if (owner != null) {
Set<Entity> pets = playerToPets.get(owner);
if (pets != null) {
pets.remove(pet);
}
}
}
public Player getOwner(Entity pet) {
return petToPlayer.get(pet);
}