9
0
mirror of https://gitlab.com/SamB440/rpgregions-2.git synced 2025-12-30 12:19:16 +00:00

Fix regenerating entities for schematics

This commit is contained in:
SamB440
2020-10-13 14:17:08 +01:00
parent c4d49daf20
commit 8625118060

View File

@@ -23,6 +23,7 @@ import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion;
import net.islandearth.rpgregions.regenerate.Regenerate;
import net.islandearth.rpgregions.regenerate.entity.RegeneratingEntity;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
@@ -51,7 +52,7 @@ public class RegenUtils {
}
World world = BukkitAdapter.adapt(region.getWorld());
EditSession session = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, Integer.MAX_VALUE);
EditSession session = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
try {
if (regenerate.getSchematicName() != null && regenerate.getOrigin() != null) {
@@ -67,6 +68,7 @@ public class RegenUtils {
.build();
Operations.complete(operation);
editSession.flushSession();
generateRandomEntities(protectedRegion, region);
return true;
}
} catch (IOException | WorldEditException e) {
@@ -103,8 +105,10 @@ public class RegenUtils {
for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) {
for (RegeneratingEntity regeneratingEntity : regenerate.getRegeneratingEntities()) {
Block block = configuredRegion.getWorld().getBlockAt(x, y, z);
Block blockUnder = configuredRegion.getWorld().getBlockAt(x, y - 1, z);
if (regeneratingEntity.getValidSpawnSurfaces().contains(blockUnder.getType())) {
Block blockUnder = block.getLocation().subtract(0, 1, 0).getBlock();
Block blockAbove = block.getLocation().add(0, 1, 0).getBlock();
if (regeneratingEntity.getValidSpawnSurfaces().contains(blockUnder.getType())
&& blockAbove.getType() == Material.AIR) {
int entityCount = 0;
for (Entity entity : block.getChunk().getEntities()) {
if (regeneratingEntity.isMythicEntity()