Search in sources :

Example 1 with TavernBuildingModule

use of com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule in project minecolonies by ldtteam.

the class VisitorCitizen method die.

@Override
public void die(DamageSource cause) {
    super.die(cause);
    if (!level.isClientSide()) {
        IColony colony = getCitizenColonyHandler().getColony();
        if (colony != null && getCitizenData() != null) {
            colony.getVisitorManager().removeCivilian(getCitizenData());
            if (getCitizenData().getHomeBuilding() instanceof TavernBuildingModule) {
                TavernBuildingModule tavern = (TavernBuildingModule) getCitizenData().getHomeBuilding();
                tavern.setNoVisitorTime(level.getRandom().nextInt(5000) + 30000);
            }
            final String deathLocation = BlockPosUtil.getString(blockPosition());
            LanguageHandler.sendPlayersMessage(colony.getImportantMessageEntityPlayers(), "com.minecolonies.coremod.gui.tavern.visitordeath", getCitizenData().getName(), cause.getMsgId(), deathLocation);
        }
    }
}
Also used : TavernBuildingModule(com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule)

Example 2 with TavernBuildingModule

use of com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule in project minecolonies by ldtteam.

the class VisitorCitizen method hurt.

@Override
public boolean hurt(@NotNull final DamageSource damageSource, final float damage) {
    if (!(damageSource.getEntity() instanceof EntityCitizen) && super.hurt(damageSource, damage)) {
        if (damageSource.getEntity() instanceof LivingEntity && damage > 1.01f) {
            final IBuilding home = getCitizenData().getHomeBuilding();
            if (home.hasModule(TavernBuildingModule.class)) {
                final TavernBuildingModule module = home.getFirstModuleOccurance(TavernBuildingModule.class);
                for (final Integer id : module.getExternalCitizens()) {
                    ICitizenData data = citizenColonyHandler.getColony().getVisitorManager().getCivilian(id);
                    if (data != null && data.getEntity().isPresent() && data.getEntity().get().getLastHurtByMob() == null) {
                        data.getEntity().get().setLastHurtByMob((LivingEntity) damageSource.getEntity());
                    }
                }
            }
            final Entity sourceEntity = damageSource.getEntity();
            if (sourceEntity instanceof PlayerEntity) {
                if (sourceEntity instanceof ServerPlayerEntity) {
                    return damage <= 1 || getCitizenColonyHandler().getColony().getPermissions().hasPermission((PlayerEntity) sourceEntity, Action.HURT_VISITOR);
                } else {
                    final IColonyView colonyView = IColonyManager.getInstance().getColonyView(getCitizenColonyHandler().getColonyId(), level.dimension());
                    return damage <= 1 || colonyView == null || colonyView.getPermissions().hasPermission((PlayerEntity) sourceEntity, Action.HURT_VISITOR);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) TavernBuildingModule(com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 3 with TavernBuildingModule

use of com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule in project minecolonies by Minecolonies.

the class VisitorCitizen method hurt.

@Override
public boolean hurt(@NotNull final DamageSource damageSource, final float damage) {
    if (!(damageSource.getEntity() instanceof EntityCitizen) && super.hurt(damageSource, damage)) {
        if (damageSource.getEntity() instanceof LivingEntity && damage > 1.01f) {
            final IBuilding home = getCitizenData().getHomeBuilding();
            if (home.hasModule(TavernBuildingModule.class)) {
                final TavernBuildingModule module = home.getFirstModuleOccurance(TavernBuildingModule.class);
                for (final Integer id : module.getExternalCitizens()) {
                    ICitizenData data = citizenColonyHandler.getColony().getVisitorManager().getCivilian(id);
                    if (data != null && data.getEntity().isPresent() && data.getEntity().get().getLastHurtByMob() == null) {
                        data.getEntity().get().setLastHurtByMob((LivingEntity) damageSource.getEntity());
                    }
                }
            }
            final Entity sourceEntity = damageSource.getEntity();
            if (sourceEntity instanceof PlayerEntity) {
                if (sourceEntity instanceof ServerPlayerEntity) {
                    return damage <= 1 || getCitizenColonyHandler().getColony().getPermissions().hasPermission((PlayerEntity) sourceEntity, Action.HURT_VISITOR);
                } else {
                    final IColonyView colonyView = IColonyManager.getInstance().getColonyView(getCitizenColonyHandler().getColonyId(), level.dimension());
                    return damage <= 1 || colonyView == null || colonyView.getPermissions().hasPermission((PlayerEntity) sourceEntity, Action.HURT_VISITOR);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) TavernBuildingModule(com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 4 with TavernBuildingModule

use of com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule in project minecolonies by Minecolonies.

the class VisitorCitizen method die.

@Override
public void die(DamageSource cause) {
    super.die(cause);
    if (!level.isClientSide()) {
        IColony colony = getCitizenColonyHandler().getColony();
        if (colony != null && getCitizenData() != null) {
            colony.getVisitorManager().removeCivilian(getCitizenData());
            if (getCitizenData().getHomeBuilding() instanceof TavernBuildingModule) {
                TavernBuildingModule tavern = (TavernBuildingModule) getCitizenData().getHomeBuilding();
                tavern.setNoVisitorTime(level.getRandom().nextInt(5000) + 30000);
            }
            final String deathLocation = BlockPosUtil.getString(blockPosition());
            MessageUtils.format(MESSAGE_INFO_COLONY_VISITOR_DIED, getCitizenData().getName(), cause.getMsgId(), deathLocation).sendTo(colony).forManagers();
        }
    }
}
Also used : TavernBuildingModule(com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule)

Aggregations

TavernBuildingModule (com.minecolonies.coremod.colony.buildings.modules.TavernBuildingModule)4 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2