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);
}
}
}
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;
}
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;
}
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();
}
}
}
Aggregations