mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-01-03 13:57:36 +01:00
Added code to respawn unloaded bosses.
This commit is contained in:
parent
aa61bffbdb
commit
6b707436ef
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user