mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-02-01 11:41:20 +01:00
remove entities in loaded chunks (need to store others for future load)
This commit is contained in:
parent
7d4fb871bc
commit
1e1f058973
@ -15,6 +15,7 @@ import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
@ -87,17 +88,39 @@ public class ActiveBossHolder implements IActiveHolder {
|
||||
this.activeMinionHolderMap.values().forEach(ActiveMinionHolder::killAll);
|
||||
}
|
||||
|
||||
public int count() {
|
||||
return livingEntityMap.size() + activeMinionHolderMap.values().stream()
|
||||
.map(e -> e.count())
|
||||
.reduce((e1, e2) -> e1 + e2)
|
||||
.orElse(0);
|
||||
}
|
||||
|
||||
public boolean killAllSubBosses(World world) {
|
||||
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(e -> {
|
||||
// Entity entity = ServerUtils.get().getEntity(e);
|
||||
// if (entity != null)
|
||||
// entity.remove();
|
||||
// });
|
||||
// this.livingEntityMap.clear();
|
||||
|
||||
// grab list of all valid entities by UUID that can be removed
|
||||
Map<Integer, Entity> toRemove = this.livingEntityMap.entrySet().stream()
|
||||
.collect(Collectors.toMap(e -> e.getKey(), e -> ServerUtils.get().getEntity(e.getValue())))
|
||||
.entrySet().stream()
|
||||
.filter(e -> e.getValue() != null && e.getValue().getWorld().isChunkLoaded(
|
||||
e.getValue().getLocation().getBlockX() >> 4,
|
||||
e.getValue().getLocation().getBlockZ() >> 4))
|
||||
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
|
||||
|
||||
// remove everything we can
|
||||
toRemove.entrySet().stream().forEach(e -> {
|
||||
e.getValue().remove();
|
||||
livingEntityMap.remove(e.getKey());
|
||||
});
|
||||
|
||||
this.livingEntityMap.clear();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,8 @@ import org.bukkit.entity.LivingEntity;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
@ -60,14 +62,33 @@ public class ActiveMinionHolder implements IActiveHolder {
|
||||
return (LivingEntity) ServerUtils.get().getEntity(target);
|
||||
}
|
||||
|
||||
public int count() {
|
||||
return livingEntityMap.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void killAll() {
|
||||
for (UUID livingEntity : this.livingEntityMap.values()) {
|
||||
LivingEntity target = (LivingEntity) ServerUtils.get().getEntity(livingEntity);
|
||||
if (target != null)
|
||||
target.remove();
|
||||
}
|
||||
this.livingEntityMap.clear();
|
||||
// for (UUID livingEntity : this.livingEntityMap.values()) {
|
||||
// LivingEntity target = (LivingEntity) ServerUtils.get().getEntity(livingEntity);
|
||||
// if (target != null)
|
||||
// target.remove();
|
||||
// }
|
||||
// this.livingEntityMap.clear();
|
||||
|
||||
// grab list of all valid entities by UUID that can be removed
|
||||
Map<Integer, Entity> toRemove = this.livingEntityMap.entrySet().stream()
|
||||
.collect(Collectors.toMap(e -> e.getKey(), e -> ServerUtils.get().getEntity(e.getValue())))
|
||||
.entrySet().stream()
|
||||
.filter(e -> e.getValue() != null && e.getValue().getWorld().isChunkLoaded(
|
||||
e.getValue().getLocation().getBlockX() >> 4,
|
||||
e.getValue().getLocation().getBlockZ() >> 4))
|
||||
.collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue()));
|
||||
|
||||
// remove everything we can
|
||||
toRemove.entrySet().stream().forEach(e -> {
|
||||
e.getValue().remove();
|
||||
livingEntityMap.remove(e.getKey());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,14 +17,12 @@ import com.songoda.epicbosses.managers.files.DropTableFileManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
import com.songoda.epicbosses.managers.files.MinionsFileManager;
|
||||
import com.songoda.epicbosses.skills.Skill;
|
||||
import com.songoda.epicbosses.skills.custom.Minions;
|
||||
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;
|
||||
@ -110,10 +108,12 @@ public class BossEntityManager {
|
||||
for(ActiveBossHolder activeBossHolder : getActiveBossHolders()) {
|
||||
if(activeBossHolder.killAllSubBosses(world)) {
|
||||
activeBossHolder.killAllMinions(world);
|
||||
activeBossHolder.setDead(true);
|
||||
amountOfBosses++;
|
||||
|
||||
ACTIVE_BOSS_HOLDERS.remove(activeBossHolder);
|
||||
if(activeBossHolder.count() == 0) {
|
||||
activeBossHolder.setDead(true);
|
||||
ACTIVE_BOSS_HOLDERS.remove(activeBossHolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,9 +127,11 @@ public class BossEntityManager {
|
||||
if(activeBossHolder.getBossEntity().equals(bossEntity)) {
|
||||
activeBossHolder.killAll();
|
||||
activeBossHolder.killAllMinions();
|
||||
activeBossHolder.setDead(true);
|
||||
|
||||
ACTIVE_BOSS_HOLDERS.remove(activeBossHolder);
|
||||
if(activeBossHolder.count() == 0) {
|
||||
activeBossHolder.setDead(true);
|
||||
ACTIVE_BOSS_HOLDERS.remove(activeBossHolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public class AutoSpawnsPanel extends MainListPanelHandler {
|
||||
}
|
||||
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
List<String> entities = ObjectUtils.getValue(autoSpawn.getEntities(), new ArrayList<>());
|
||||
List<String> entities = (List<String>) ObjectUtils.getValue(autoSpawn.getEntities(), new ArrayList<>());
|
||||
AutoSpawnSettings settings = autoSpawn.getAutoSpawnSettings();
|
||||
String entitiesSize = entities.size()+"";
|
||||
String maxAlive = ""+ObjectUtils.getValue(settings.getMaxAliveAtOnce(), 1);
|
||||
|
@ -83,7 +83,7 @@ public class AutoSpawnEntitiesEditorPanel extends VariablePanelHandler<AutoSpawn
|
||||
}
|
||||
|
||||
private void loadPage(Panel panel, int page, Map<String, BossEntity> currentEntities, List<String> entryList, AutoSpawn autoSpawn) {
|
||||
List<String> current = ObjectUtils.getValue(autoSpawn.getEntities(), new ArrayList<>());
|
||||
List<String> current = (List<String>) ObjectUtils.getValue(autoSpawn.getEntities(), new ArrayList<>());
|
||||
|
||||
panel.loadPage(page, (slot, realisticSlot) -> {
|
||||
if(slot >= entryList.size()) {
|
||||
|
Loading…
Reference in New Issue
Block a user