use of com.minecolonies.coremod.colony.jobs.JobGuard in project minecolonies by Minecolonies.
the class ColonyPermissionEventHandler method on.
/**
* AttackEntityEvent handler.
* <p>
* Check, if a player tries to attack an entity..
* Deny if:
* - If the attacking happens in the colony
* - Player is less than officer to the colony.
*
* @param event EntityItemPickupEvent
*/
@SubscribeEvent
public void on(final AttackEntityEvent event) {
if (event.getTarget() instanceof EntityMob) {
return;
}
@NotNull final EntityPlayer player = EntityUtils.getPlayerOfFakePlayer(event.getEntityPlayer(), event.getEntityPlayer().getEntityWorld());
if (Configurations.enableColonyProtection && colony.isCoordInColony(player.getEntityWorld(), player.getPosition())) {
final Permissions perms = colony.getPermissions();
if (event.getTarget() instanceof EntityCitizen) {
final EntityCitizen citizen = (EntityCitizen) event.getTarget();
if (citizen.getColonyJob() instanceof JobGuard && perms.hasPermission(event.getEntityPlayer(), Action.GUARDS_ATTACK)) {
return;
}
if (perms.hasPermission(event.getEntityPlayer(), Action.ATTACK_CITIZEN)) {
return;
}
cancelEvent(event, player);
return;
}
if (!perms.hasPermission(event.getEntityPlayer(), Action.ATTACK_ENTITY)) {
cancelEvent(event, player);
}
}
}
use of com.minecolonies.coremod.colony.jobs.JobGuard in project minecolonies by Minecolonies.
the class EntityCitizen method getDesiredActivity.
@NotNull
public DesiredActivity getDesiredActivity() {
if (this.getColonyJob() instanceof JobGuard) {
return DesiredActivity.WORK;
}
if (!world.isDaytime()) {
if (isDay && citizenData != null) {
isDay = false;
final AbstractBuildingWorker buildingWorker = getWorkBuilding();
final double decreaseBy = buildingWorker == null || buildingWorker.getBuildingLevel() == 0 ? 0.1 : (SATURATION_DECREASE_FACTOR * Math.pow(2, buildingWorker.getBuildingLevel() - 1.0));
citizenData.decreaseSaturation(decreaseBy);
citizenData.markDirty();
}
return DesiredActivity.SLEEP;
}
isDay = true;
if (world.isRaining() && !shouldWorkWhileRaining()) {
return DesiredActivity.IDLE;
} else {
if (this.getNavigator() != null && (this.getNavigator().getPath() != null && this.getNavigator().getPath().getCurrentPathLength() == 0)) {
this.getNavigator().clearPathEntity();
}
return DesiredActivity.WORK;
}
}
use of com.minecolonies.coremod.colony.jobs.JobGuard in project minecolonies by Minecolonies.
the class EntityCitizen method onDeath.
/**
* Called when the mob's health reaches 0.
*
* @param par1DamageSource the attacking entity.
*/
@Override
public void onDeath(final DamageSource par1DamageSource) {
double penalty = CITIZEN_DEATH_PENALTY;
if (par1DamageSource.getEntity() instanceof EntityPlayer) {
for (final Player player : PermissionUtils.getPlayersWithAtLeastRank(colony, Rank.OFFICER)) {
if (player.getID().equals(par1DamageSource.getEntity().getUniqueID())) {
penalty = CITIZEN_KILL_PENALTY;
break;
}
}
}
dropExperience();
this.setDead();
if (colony != null) {
colony.decreaseOverallHappiness(penalty);
triggerDeathAchievement(par1DamageSource, getColonyJob());
if (getColonyJob() instanceof JobGuard) {
LanguageHandler.sendPlayersMessage(colony.getMessageEntityPlayers(), "tile.blockHutTownHall.messageGuardDead", citizenData.getName(), (int) posX, (int) posY, (int) posZ);
} else {
LanguageHandler.sendPlayersMessage(colony.getMessageEntityPlayers(), "tile.blockHutTownHall.messageColonistDead", citizenData.getName(), (int) posX, (int) posY, (int) posZ);
}
colony.removeCitizen(getCitizenData());
}
super.onDeath(par1DamageSource);
}
Aggregations