Search in sources :

Example 1 with BuildingTownHall

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall in project minecolonies by Minecolonies.

the class BuildingManager method removeBuilding.

@Override
public void removeBuilding(@NotNull final IBuilding building, final Set<ServerPlayerEntity> subscribers) {
    if (buildings.containsKey(building.getID())) {
        final ImmutableMap.Builder<BlockPos, IBuilding> builder = new ImmutableMap.Builder<>();
        for (final IBuilding tbuilding : buildings.values()) {
            if (tbuilding != building) {
                builder.put(tbuilding.getID(), tbuilding);
            }
        }
        buildings = builder.build();
        for (final ServerPlayerEntity player : subscribers) {
            Network.getNetwork().sendToPlayer(new ColonyViewRemoveBuildingMessage(colony, building.getID()), player);
        }
        Log.getLogger().info(String.format("Colony %d - removed AbstractBuilding %s of type %s", colony.getID(), building.getID(), building.getSchematicName()));
    }
    if (building instanceof BuildingTownHall) {
        townHall = null;
    } else if (building instanceof BuildingWareHouse) {
        wareHouses.remove(building);
    } else if (building instanceof BuildingMysticalSite) {
        mysticalSites.remove(building);
    }
    // Allow Citizens to fix up any data that wasn't fixed up by the AbstractBuilding's own onDestroyed
    for (@NotNull final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
        citizen.onRemoveBuilding(building);
        building.cancelAllRequestsOfCitizen(citizen);
    }
    colony.getRequestManager().onProviderRemovedFromColony(building);
    colony.getRequestManager().onRequesterRemovedFromColony(building.getRequester());
    colony.getCitizenManager().calculateMaxCitizens();
}
Also used : BuildingMysticalSite(com.minecolonies.coremod.colony.buildings.BuildingMysticalSite) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ColonyViewRemoveBuildingMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveBuildingMessage) NotNull(org.jetbrains.annotations.NotNull) ImmutableMap(com.google.common.collect.ImmutableMap) BuildingTownHall(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)

Example 2 with BuildingTownHall

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall in project minecolonies by ldtteam.

the class BuildingManager method removeBuilding.

@Override
public void removeBuilding(@NotNull final IBuilding building, final Set<ServerPlayerEntity> subscribers) {
    if (buildings.containsKey(building.getID())) {
        final ImmutableMap.Builder<BlockPos, IBuilding> builder = new ImmutableMap.Builder<>();
        for (final IBuilding tbuilding : buildings.values()) {
            if (tbuilding != building) {
                builder.put(tbuilding.getID(), tbuilding);
            }
        }
        buildings = builder.build();
        for (final ServerPlayerEntity player : subscribers) {
            Network.getNetwork().sendToPlayer(new ColonyViewRemoveBuildingMessage(colony, building.getID()), player);
        }
        Log.getLogger().info(String.format("Colony %d - removed AbstractBuilding %s of type %s", colony.getID(), building.getID(), building.getSchematicName()));
    }
    if (building instanceof BuildingTownHall) {
        townHall = null;
    } else if (building instanceof BuildingWareHouse) {
        wareHouses.remove(building);
    } else if (building instanceof BuildingMysticalSite) {
        mysticalSites.remove(building);
    }
    // Allow Citizens to fix up any data that wasn't fixed up by the AbstractBuilding's own onDestroyed
    for (@NotNull final ICitizenData citizen : colony.getCitizenManager().getCitizens()) {
        citizen.onRemoveBuilding(building);
        building.cancelAllRequestsOfCitizen(citizen);
    }
    colony.getRequestManager().onProviderRemovedFromColony(building);
    colony.getRequestManager().onRequesterRemovedFromColony(building.getRequester());
    colony.getCitizenManager().calculateMaxCitizens();
}
Also used : BuildingMysticalSite(com.minecolonies.coremod.colony.buildings.BuildingMysticalSite) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ColonyViewRemoveBuildingMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveBuildingMessage) NotNull(org.jetbrains.annotations.NotNull) ImmutableMap(com.google.common.collect.ImmutableMap) BuildingTownHall(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall) BuildingWareHouse(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)2 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 BuildingMysticalSite (com.minecolonies.coremod.colony.buildings.BuildingMysticalSite)2 BuildingTownHall (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingTownHall)2 BuildingWareHouse (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingWareHouse)2 ColonyViewRemoveBuildingMessage (com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveBuildingMessage)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 NotNull (org.jetbrains.annotations.NotNull)2