Search in sources :

Example 1 with JobGuard

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);
        }
    }
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) Permissions(com.minecolonies.coremod.colony.permissions.Permissions) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) JobGuard(com.minecolonies.coremod.colony.jobs.JobGuard) NotNull(org.jetbrains.annotations.NotNull) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with JobGuard

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;
    }
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) JobGuard(com.minecolonies.coremod.colony.jobs.JobGuard) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with JobGuard

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);
}
Also used : Player(com.minecolonies.api.colony.permissions.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) JobGuard(com.minecolonies.coremod.colony.jobs.JobGuard)

Aggregations

JobGuard (com.minecolonies.coremod.colony.jobs.JobGuard)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 NotNull (org.jetbrains.annotations.NotNull)2 Player (com.minecolonies.api.colony.permissions.Player)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)1 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1