Rewrite boss/minion tracking to use UUID instead
This commit is contained in:
parent
4d9186613d
commit
147fa86c3e
|
@ -1,13 +1,16 @@
|
|||
package com.songoda.epicbosses.holder;
|
||||
|
||||
import com.songoda.epicbosses.listeners.IBossDeathHandler;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import com.songoda.epicbosses.targeting.TargetHandler;
|
||||
import com.songoda.epicbosses.entity.BossEntity;
|
||||
import com.songoda.epicbosses.exception.AlreadySetException;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -24,7 +27,7 @@ public class ActiveBossHolder implements IActiveHolder {
|
|||
@Getter private final String name;
|
||||
|
||||
@Getter private Map<Integer, ActiveMinionHolder> activeMinionHolderMap = new HashMap<>();
|
||||
@Getter private Map<Integer, LivingEntity> livingEntityMap = new HashMap<>();
|
||||
@Getter private Map<Integer, UUID> livingEntityMap = new HashMap<>();
|
||||
@Getter private List<IBossDeathHandler> postBossDeathHandlers = new ArrayList<>();
|
||||
@Getter private Map<UUID, Double> mapOfDamagingUsers = new HashMap<>();
|
||||
|
||||
|
@ -38,25 +41,29 @@ public class ActiveBossHolder implements IActiveHolder {
|
|||
}
|
||||
|
||||
public void setLivingEntity(int position, LivingEntity livingEntity) {
|
||||
if(getLivingEntityMap().containsKey(position)) {
|
||||
if (this.livingEntityMap.containsKey(position)) {
|
||||
throw new AlreadySetException("Tried to set a new LivingEntity while it's already set.");
|
||||
} else {
|
||||
this.livingEntityMap.put(position, livingEntity);
|
||||
this.livingEntityMap.put(position, livingEntity.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void killAll() {
|
||||
killAllMinions();
|
||||
killAllSubBosses(null);
|
||||
this.killAllMinions();
|
||||
this.killAllSubBosses(null);
|
||||
}
|
||||
|
||||
public LivingEntity getLivingEntity() {
|
||||
for(LivingEntity livingEntity : getLivingEntityMap().values()) {
|
||||
if(livingEntity != null) return livingEntity;
|
||||
}
|
||||
return this.getLivingEntity(1);
|
||||
}
|
||||
|
||||
return null;
|
||||
@Override
|
||||
public LivingEntity getLivingEntity(int position) {
|
||||
UUID target = this.livingEntityMap.get(position);
|
||||
if (target == null)
|
||||
return null;
|
||||
return (LivingEntity) ServerUtils.get().getEntity(target);
|
||||
}
|
||||
|
||||
public boolean hasAttacked(UUID uuid) {
|
||||
|
@ -68,15 +75,22 @@ public class ActiveBossHolder implements IActiveHolder {
|
|||
}
|
||||
|
||||
public void killAllMinions(World world) {
|
||||
if(world != null && !getLocation().getWorld().equals(world)) return;
|
||||
if (world != null && !this.location.getWorld().equals(world))
|
||||
return;
|
||||
|
||||
this.activeMinionHolderMap.values().forEach(ActiveMinionHolder::killAll);
|
||||
}
|
||||
|
||||
public boolean killAllSubBosses(World world) {
|
||||
if(world != null && !getLocation().getWorld().equals(world)) return false;
|
||||
if (world != null && !this.location.getWorld().equals(world))
|
||||
return false;
|
||||
|
||||
this.livingEntityMap.values().forEach(e -> {
|
||||
Entity entity = ServerUtils.get().getEntity(e);
|
||||
if (entity != null)
|
||||
entity.remove();
|
||||
});
|
||||
|
||||
this.livingEntityMap.values().forEach(LivingEntity::remove);
|
||||
this.livingEntityMap.clear();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,10 @@ package com.songoda.epicbosses.holder;
|
|||
|
||||
import com.songoda.epicbosses.entity.MinionEntity;
|
||||
import com.songoda.epicbosses.targeting.TargetHandler;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
|
@ -20,7 +22,7 @@ public class ActiveMinionHolder implements IActiveHolder {
|
|||
|
||||
@Getter @Setter private TargetHandler<ActiveMinionHolder> targetHandler = null;
|
||||
|
||||
@Getter private Map<Integer, LivingEntity> livingEntityMap = new HashMap<>();
|
||||
@Getter private Map<Integer, UUID> livingEntityMap = new HashMap<>();
|
||||
@Getter private ActiveBossHolder activeBossHolder;
|
||||
@Getter private final MinionEntity minionEntity;
|
||||
@Getter private final Location location;
|
||||
|
@ -35,22 +37,36 @@ public class ActiveMinionHolder implements IActiveHolder {
|
|||
|
||||
@Override
|
||||
public Map<UUID, Double> getMapOfDamagingUsers() {
|
||||
return getActiveBossHolder().getMapOfDamagingUsers();
|
||||
return this.activeBossHolder.getMapOfDamagingUsers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLivingEntity(int position, LivingEntity livingEntity) {
|
||||
if(getLivingEntityMap().containsKey(position)) {
|
||||
this.livingEntityMap.get(position).remove();
|
||||
if(this.livingEntityMap.containsKey(position)) {
|
||||
LivingEntity target = (LivingEntity) ServerUtils.get().getEntity(this.livingEntityMap.get(position));
|
||||
if (target != null)
|
||||
target.remove();
|
||||
this.livingEntityMap.remove(position);
|
||||
}
|
||||
|
||||
this.livingEntityMap.put(position, livingEntity);
|
||||
this.livingEntityMap.put(position, livingEntity.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity getLivingEntity(int position) {
|
||||
UUID target = this.livingEntityMap.get(position);
|
||||
if (target == null)
|
||||
return null;
|
||||
return (LivingEntity) ServerUtils.get().getEntity(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void killAll() {
|
||||
this.livingEntityMap.values().forEach(LivingEntity::remove);
|
||||
for (UUID livingEntity : this.livingEntityMap.values()) {
|
||||
LivingEntity target = (LivingEntity) ServerUtils.get().getEntity(livingEntity);
|
||||
if (target != null)
|
||||
target.remove();
|
||||
}
|
||||
this.livingEntityMap.clear();
|
||||
}
|
||||
|
||||
|
@ -58,7 +74,8 @@ public class ActiveMinionHolder implements IActiveHolder {
|
|||
public boolean isDead() {
|
||||
if(this.livingEntityMap.isEmpty()) return true;
|
||||
|
||||
for(LivingEntity livingEntity : this.livingEntityMap.values()) {
|
||||
for(UUID uuid : this.livingEntityMap.values()) {
|
||||
LivingEntity livingEntity = (LivingEntity) ServerUtils.get().getEntity(uuid);
|
||||
if(livingEntity == null || livingEntity.isDead()) return true;
|
||||
}
|
||||
|
||||
|
@ -67,7 +84,7 @@ public class ActiveMinionHolder implements IActiveHolder {
|
|||
|
||||
@Override
|
||||
public boolean hasAttacked(UUID uuid) {
|
||||
return getActiveBossHolder().hasAttacked(uuid);
|
||||
return this.activeBossHolder.hasAttacked(uuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,7 +18,9 @@ public interface IActiveHolder {
|
|||
|
||||
String getName();
|
||||
|
||||
Map<Integer, LivingEntity> getLivingEntityMap();
|
||||
Map<Integer, UUID> getLivingEntityMap();
|
||||
|
||||
LivingEntity getLivingEntity(int position);
|
||||
|
||||
Map<UUID, Double> getMapOfDamagingUsers();
|
||||
|
||||
|
|
|
@ -22,7 +22,9 @@ import com.songoda.epicbosses.skills.elements.CustomMinionSkillElement;
|
|||
import com.songoda.epicbosses.utils.BossesGson;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.RandomUtils;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Item;
|
||||
|
@ -313,8 +315,8 @@ public class BossEntityManager {
|
|||
List<ActiveBossHolder> currentList = getActiveBossHolders();
|
||||
|
||||
for(ActiveBossHolder activeBossHolder : currentList) {
|
||||
for(Map.Entry<Integer, LivingEntity> entry : activeBossHolder.getLivingEntityMap().entrySet()) {
|
||||
if(entry.getValue().getUniqueId().equals(livingEntity.getUniqueId())) return activeBossHolder;
|
||||
for(Map.Entry<Integer, UUID> entry : activeBossHolder.getLivingEntityMap().entrySet()) {
|
||||
if(entry.getValue().equals(livingEntity.getUniqueId())) return activeBossHolder;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -322,16 +324,20 @@ public class BossEntityManager {
|
|||
}
|
||||
|
||||
public void removeActiveBossHolder(ActiveBossHolder activeBossHolder) {
|
||||
for(Map.Entry<Integer, LivingEntity> entry : activeBossHolder.getLivingEntityMap().entrySet()) {
|
||||
if(!entry.getValue().isDead()) entry.getValue().remove();
|
||||
for(Map.Entry<Integer, UUID> entry : activeBossHolder.getLivingEntityMap().entrySet()) {
|
||||
LivingEntity livingEntity = (LivingEntity) ServerUtils.get().getEntity(entry.getValue());
|
||||
if (livingEntity != null && !livingEntity.isDead())
|
||||
livingEntity.remove();
|
||||
}
|
||||
|
||||
ACTIVE_BOSS_HOLDERS.remove(activeBossHolder);
|
||||
}
|
||||
|
||||
public boolean isAllEntitiesDead(ActiveBossHolder activeBossHolder) {
|
||||
for(Map.Entry<Integer, LivingEntity> entry : activeBossHolder.getLivingEntityMap().entrySet()) {
|
||||
if(!entry.getValue().isDead()) return false;
|
||||
for(Map.Entry<Integer, UUID> entry : activeBossHolder.getLivingEntityMap().entrySet()) {
|
||||
LivingEntity livingEntity = (LivingEntity) ServerUtils.get().getEntity(entry.getValue());
|
||||
if (livingEntity != null && !livingEntity.isDead())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -156,7 +156,11 @@ public class BossSkillManager implements ILoadable {
|
|||
if(mode.equalsIgnoreCase("ONE")) {
|
||||
return Arrays.asList(damager);
|
||||
} else if(mode.equalsIgnoreCase("BOSS")) {
|
||||
targetedList.addAll(activeBossHolder.getLivingEntityMap().values());
|
||||
for (UUID uuid : activeBossHolder.getLivingEntityMap().values()) {
|
||||
LivingEntity livingEntity = (LivingEntity) ServerUtils.get().getEntity(uuid);
|
||||
if (livingEntity != null)
|
||||
targetedList.add(livingEntity);
|
||||
}
|
||||
} else {
|
||||
for(Player player : Bukkit.getOnlinePlayers()) {
|
||||
if(!player.getWorld().equals(center.getWorld())) continue;
|
||||
|
|
|
@ -38,7 +38,7 @@ public class EntityTypeMechanic implements IBossMechanic {
|
|||
|
||||
if(position > 1) {
|
||||
int lowerPosition = position - 1;
|
||||
LivingEntity lowerLivingEntity = activeBossHolder.getLivingEntityMap().getOrDefault(lowerPosition, null);
|
||||
LivingEntity lowerLivingEntity = activeBossHolder.getLivingEntity(lowerPosition);
|
||||
|
||||
if(lowerLivingEntity == null) {
|
||||
Debug.FAILED_ATTEMPT_TO_STACK_BOSSES.debug(BossAPI.getBossEntityName(bossEntity));
|
||||
|
|
|
@ -31,7 +31,7 @@ public class EquipmentMechanic implements IBossMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : bossEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ public class HealthMechanic implements IBossMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : bossEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
double maxHealth = mainStatsElement.getHealth();
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
|
|
@ -24,7 +24,7 @@ public class NameMechanic implements IBossMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : bossEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
String customName = mainStatsElement.getDisplayName();
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
|
|
@ -31,7 +31,7 @@ public class PotionMechanic implements IBossMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : bossEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
List<PotionEffectHolder> potionElements = entityStatsElement.getPotions();
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
|
|
@ -28,7 +28,7 @@ public class SettingsMechanic implements IBossMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : bossEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class WeaponMechanic implements IBossMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : bossEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
||||
|
|
|
@ -35,11 +35,11 @@ public class EntityTypeMechanic implements IMinionMechanic {
|
|||
if(livingEntity == null) return false;
|
||||
if(!activeMinionHolder.getLivingEntityMap().isEmpty()) activeMinionHolder.killAll();
|
||||
|
||||
activeMinionHolder.getLivingEntityMap().put(position, livingEntity);
|
||||
activeMinionHolder.getLivingEntityMap().put(position, livingEntity.getUniqueId());
|
||||
|
||||
if(position > 1) {
|
||||
int lowerPosition = position - 1;
|
||||
LivingEntity lowerLivingEntity = activeMinionHolder.getLivingEntityMap().getOrDefault(lowerPosition, null);
|
||||
LivingEntity lowerLivingEntity = activeMinionHolder.getLivingEntity(lowerPosition);
|
||||
|
||||
if(lowerLivingEntity == null) {
|
||||
Debug.FAILED_ATTEMPT_TO_STACK_BOSSES.debug(BossAPI.getMinionEntityName(minionEntity));
|
||||
|
|
|
@ -31,7 +31,7 @@ public class EquipmentMechanic implements IMinionMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : minionEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeBossHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ public class HealthMechanic implements IMinionMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : minionEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeMinionHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeMinionHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
double maxHealth = mainStatsElement.getHealth();
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
|
|
@ -24,7 +24,7 @@ public class NameMechanic implements IMinionMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : minionEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeMinionHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeMinionHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
String customName = mainStatsElement.getDisplayName();
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class PotionMechanic implements IMinionMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : minionEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeMinionHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeMinionHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
List<PotionEffectHolder> potionElements = entityStatsElement.getPotions();
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
|
|
@ -28,7 +28,7 @@ public class SettingsMechanic implements IMinionMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : minionEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeMinionHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeMinionHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class WeaponMechanic implements IMinionMechanic {
|
|||
|
||||
for(EntityStatsElement entityStatsElement : minionEntity.getEntityStats()) {
|
||||
MainStatsElement mainStatsElement = entityStatsElement.getMainStats();
|
||||
LivingEntity livingEntity = activeMinionHolder.getLivingEntityMap().getOrDefault(mainStatsElement.getPosition(), null);
|
||||
LivingEntity livingEntity = activeMinionHolder.getLivingEntity(mainStatsElement.getPosition());
|
||||
|
||||
if(livingEntity == null) return false;
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.songoda.epicbosses.panel.droptables.rewards.interfaces.IDropTableRewa
|
|||
import com.songoda.epicbosses.utils.NumberUtils;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import com.songoda.epicbosses.utils.itemstack.ItemStackUtils;
|
||||
import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import com.songoda.epicbosses.utils.panel.Panel;
|
||||
import com.songoda.epicbosses.utils.panel.base.handlers.SubVariablePanelHandler;
|
||||
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
|
||||
|
@ -94,7 +95,13 @@ public abstract class DropTableRewardsListEditorPanel<SubVariable> extends SubVa
|
|||
replaceMap.put("{itemName}", name);
|
||||
replaceMap.put("{chance}", NumberUtils.get().formatDouble(chance));
|
||||
|
||||
ItemStack itemStack = this.itemsFileManager.getItemStackConverter().from(this.itemsFileManager.getItemStackHolder(name));
|
||||
ItemStackHolder itemStackHolder = this.itemsFileManager.getItemStackHolder(name);
|
||||
if (itemStackHolder == null) {
|
||||
ServerUtils.get().logDebug("Tried to load null itemstack for droptable rewards list panel: [" + name + ", " + chance + "]");
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack itemStack = this.itemsFileManager.getItemStackConverter().from(itemStackHolder);
|
||||
|
||||
if(itemStack == null || itemStack.getType() == Material.AIR) return;
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.songoda.epicbosses.holder.IActiveHolder;
|
|||
import com.songoda.epicbosses.managers.BossTargetManager;
|
||||
import com.songoda.epicbosses.utils.ServerUtils;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Creature;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -12,6 +13,7 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
|
@ -37,7 +39,8 @@ public abstract class TargetHandler<Holder extends IActiveHolder> implements ITa
|
|||
}
|
||||
|
||||
protected LivingEntity getBossEntity() {
|
||||
for(LivingEntity livingEntity : getHolder().getLivingEntityMap().values()) {
|
||||
for(UUID uuid : getHolder().getLivingEntityMap().values()) {
|
||||
LivingEntity livingEntity = (LivingEntity) ServerUtils.get().getEntity(uuid);
|
||||
if(livingEntity != null && !livingEntity.isDead()) return livingEntity;
|
||||
}
|
||||
|
||||
|
@ -73,7 +76,8 @@ public abstract class TargetHandler<Holder extends IActiveHolder> implements ITa
|
|||
}
|
||||
|
||||
private void updateBoss(LivingEntity newTarget) {
|
||||
getHolder().getLivingEntityMap().values().forEach(livingEntity -> {
|
||||
getHolder().getLivingEntityMap().values().forEach(uuid -> {
|
||||
LivingEntity livingEntity = (LivingEntity) ServerUtils.get().getEntity(uuid);
|
||||
if(livingEntity != null && !livingEntity.isDead()) {
|
||||
((Creature) livingEntity).setTarget(newTarget);
|
||||
}
|
||||
|
|
|
@ -2,11 +2,15 @@ package com.songoda.epicbosses.utils;
|
|||
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
|
@ -84,6 +88,14 @@ public class ServerUtils {
|
|||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||
}
|
||||
|
||||
public Entity getEntity(UUID uuid) {
|
||||
for (World world : Bukkit.getWorlds())
|
||||
for (Entity entity : world.getEntities())
|
||||
if (entity.getUniqueId().equals(uuid))
|
||||
return entity;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ServerUtils get() {
|
||||
return serverUtils;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue