diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/listeners/during/BossDamageListener.java b/plugin-modules/Core/src/com/songoda/epicbosses/listeners/during/BossDamageListener.java index 21e2789..b38ee58 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/listeners/during/BossDamageListener.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/listeners/during/BossDamageListener.java @@ -1,9 +1,12 @@ package com.songoda.epicbosses.listeners.during; +import com.songoda.core.utils.TextUtils; import com.songoda.epicbosses.EpicBosses; +import com.songoda.epicbosses.entity.BossEntity; import com.songoda.epicbosses.events.BossDamageEvent; import com.songoda.epicbosses.holder.ActiveBossHolder; import com.songoda.epicbosses.managers.BossEntityManager; +import com.songoda.epicbosses.managers.files.BossesFileManager; import com.songoda.epicbosses.utils.ServerUtils; import org.bukkit.entity.*; import org.bukkit.event.EventHandler; @@ -19,9 +22,11 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; public class BossDamageListener implements Listener { private BossEntityManager bossEntityManager; + private BossesFileManager bossesFileManager; public BossDamageListener(EpicBosses plugin) { this.bossEntityManager = plugin.getBossEntityManager(); + this.bossesFileManager = plugin.getBossesFileManager(); } @EventHandler(priority = EventPriority.MONITOR) @@ -36,7 +41,18 @@ public class BossDamageListener implements Listener { double damage = event.getDamage(); Player player = null; - if (activeBossHolder == null) return; + if (activeBossHolder == null) { + // Check to see if this was a boss and respawn it if so. + String convert = TextUtils.convertFromInvisibleString(livingEntity.getCustomName()); + if (convert.startsWith("BOSS:")) { + String name = convert.split(":")[1]; + + BossEntity bossEntity = bossesFileManager.getBossEntity(name); + bossEntityManager.createActiveBossHolder(bossEntity, livingEntity.getLocation(), name, null); + livingEntity.remove(); + } + return; + } if (entityDamaging instanceof Player) { player = (Player) entityDamaging; diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/mechanics/boss/NameMechanic.java b/plugin-modules/Core/src/com/songoda/epicbosses/mechanics/boss/NameMechanic.java index cd334f5..384f906 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/mechanics/boss/NameMechanic.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/mechanics/boss/NameMechanic.java @@ -1,5 +1,6 @@ package com.songoda.epicbosses.mechanics.boss; +import com.songoda.core.utils.TextUtils; import com.songoda.epicbosses.EpicBosses; import com.songoda.epicbosses.entity.BossEntity; import com.songoda.epicbosses.entity.elements.EntityStatsElement; @@ -16,8 +17,6 @@ import org.bukkit.entity.LivingEntity; */ public class NameMechanic implements IBossMechanic { - private EpicBosses plugin = EpicBosses.getInstance(); - @Override public boolean applyMechanic(BossEntity bossEntity, ActiveBossHolder activeBossHolder) { if (activeBossHolder.getLivingEntityMap().getOrDefault(1, null) == null) return false; @@ -30,7 +29,7 @@ public class NameMechanic implements IBossMechanic { if (livingEntity == null || customName == null) continue; String formattedName = StringUtils.get().translateColor(customName); - livingEntity.setCustomName(formattedName); + livingEntity.setCustomName(TextUtils.convertToInvisibleString("BOSS:" + activeBossHolder.getName() + ":") + formattedName); livingEntity.setCustomNameVisible(true); }