Remove all players from boss bars when clearing the MonsterManager.

When the arena ends, the MonsterManager is cleared, which means that all references to health bars are lost. Before this, we remove all players from any boss bars to make sure that the boss bars don't stick to players upon dying.

Fixes #473
This commit is contained in:
Andreas Troelsen
2018-06-25 10:30:14 +02:00
parent 9d0cd8f967
commit 650e7bbd44
@@ -1,5 +1,6 @@
package com.garbagemule.MobArena; package com.garbagemule.MobArena;
import com.garbagemule.MobArena.healthbar.HealthBar;
import com.garbagemule.MobArena.waves.MABoss; import com.garbagemule.MobArena.waves.MABoss;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
@@ -12,6 +13,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
public class MonsterManager public class MonsterManager
@@ -43,6 +45,11 @@ public class MonsterManager
} }
public void clear() { public void clear() {
bosses.values().stream()
.map(MABoss::getHealthBar)
.filter(Objects::nonNull)
.forEach(HealthBar::removeAll);
removeAll(monsters); removeAll(monsters);
removeAll(sheep); removeAll(sheep);
removeAll(golems); removeAll(golems);