diff --git a/src/engine/workthreads/DestroyCityThread.java b/src/engine/workthreads/DestroyCityThread.java index 9c5b2050..9813fd62 100644 --- a/src/engine/workthreads/DestroyCityThread.java +++ b/src/engine/workthreads/DestroyCityThread.java @@ -31,6 +31,7 @@ import engine.objects.Zone; import org.pmw.tinylog.Logger; import java.util.ArrayList; +import java.util.EnumSet; public class DestroyCityThread implements Runnable { @@ -50,6 +51,7 @@ public class DestroyCityThread implements Runnable { Guild formerGuild; Vector3fImmutable localCoords; ArrayList subGuildList; + ArrayList transferSet; // Member variable assignment @@ -70,21 +72,19 @@ public class DestroyCityThread implements Runnable { GuildManager.updateAllGuildBinds(formerGuild, null); } - // By losing the tree, the former owners lose all of their subguilds. - - if (!formerGuild.getSubGuildList().isEmpty()) { + if (formerGuild.getSubGuildList().isEmpty() == false) { subGuildList = new ArrayList<>(); - subGuildList.addAll(formerGuild.getSubGuildList()); + for (Guild subGuild : formerGuild.getSubGuildList()) { + subGuildList.add(subGuild); + } for (Guild subGuild : subGuildList) { formerGuild.removeSubGuild(subGuild); } } - Building tol = null; - // Build list of buildings within this parent zone for (Building cityBuilding : cityZone.zoneBuildingSet) { @@ -100,13 +100,6 @@ public class DestroyCityThread implements Runnable { if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.BANESTONE)) continue; - // TOL is processed after all other structures in the city zone - - if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.TOL)) { - tol = cityBuilding; - continue; - } - // All buildings are moved to a location relative // to their new parent zone @@ -127,39 +120,31 @@ public class DestroyCityThread implements Runnable { // Remove warehouse entry if one exists. - if (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE) { + if (cityBuilding.getBlueprint().getBuildingGroup().equals(mbEnums.BuildingGroup.WAREHOUSE)) { DbManager.WarehouseQueries.DELETE_WAREHOUSE(city.warehouse); city.warehouse = null; } - // Destroy all remaining city assets + // Destroy all remaining auto-protected city assets + + EnumSet assetsToDestroy = EnumSet.of(mbEnums.BuildingGroup.TOL, mbEnums.BuildingGroup.BARRACK, + mbEnums.BuildingGroup.SPIRE, mbEnums.BuildingGroup.SHRINE, mbEnums.BuildingGroup.WAREHOUSE); - if ((cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.BARRACK) - || (cityBuilding.getBlueprint().isWallPiece()) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SHRINE) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.TOL) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.SPIRE) - || (cityBuilding.getBlueprint().getBuildingGroup() == mbEnums.BuildingGroup.WAREHOUSE)) { + if (assetsToDestroy.contains(cityBuilding.getBlueprint().getBuildingGroup())) { if (cityBuilding.getRank() != -1) BuildingManager.setRank(cityBuilding, -1); } } - // Destroy the tol - - if (tol != null) - BuildingManager.setRank(tol, -1); - if (city.realm != null) city.realm.removeCity(city.getObjectUUID()); // It's now safe to delete the city zone from the database // which will cause a cascade delete of everything else - if (DbManager.ZoneQueries.DELETE_ZONE(cityZone) == false) { - Logger.error("DestroyCityThread", "Database error when deleting city zone: " + cityZone.getObjectUUID()); + Logger.error("DestroyCityThread", "Error when deleting city zone: " + cityZone.getObjectUUID()); return; }