Search in sources :

Example 6 with EntityCitizen

use of com.minecolonies.coremod.entity.EntityCitizen 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 7 with EntityCitizen

use of com.minecolonies.coremod.entity.EntityCitizen in project minecolonies by Minecolonies.

the class RecallCitizenMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final RecallCitizenMessage message, final EntityPlayerMP player) {
    final Colony colony = ColonyManager.getColony(message.colonyId);
    if (colony != null) {
        //Verify player has permission to change this huts settings
        if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
            return;
        }
        @Nullable final AbstractBuildingWorker building = colony.getBuilding(message.buildingId, AbstractBuildingWorker.class);
        if (building != null) {
            EntityCitizen citizen = building.getWorkerEntity();
            if (citizen == null) {
                final CitizenData citizenData = building.getWorker();
                if (citizenData != null) {
                    Log.getLogger().warn(String.format("Citizen #%d:%d has gone AWOL, respawning them!", colony.getID(), citizenData.getId()));
                    colony.spawnCitizen(citizenData);
                    citizen = citizenData.getCitizenEntity();
                } else {
                    Log.getLogger().warn("Citizen is AWOL and citizenData is null!");
                    return;
                }
            }
            final BlockPos loc = building.getLocation();
            if (!TeleportHelper.teleportCitizen(citizen, colony.getWorld(), loc)) {
                LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerHuts.recallFail");
            }
        }
    }
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with EntityCitizen

use of com.minecolonies.coremod.entity.EntityCitizen in project minecolonies by Minecolonies.

the class RespawnCitizenCommand method executeSpecializedCode.

@Override
void executeSpecializedCode(@NotNull final MinecraftServer server, final ICommandSender sender, final Colony colony, final int citizenId) {
    final CitizenData citizenData = colony.getCitizen(citizenId);
    final EntityCitizen entityCitizen = citizenData.getCitizenEntity();
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizenData.getId(), citizenData.getName())));
    if (entityCitizen == null) {
        colony.spawnCitizen(citizenData);
        return;
    }
    final BlockPos position = entityCitizen.getPosition();
    sender.sendMessage(new TextComponentString(String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
    sender.sendMessage(new TextComponentString(REMOVED_MESSAGE));
    Log.getLogger().info("client? " + sender.getEntityWorld().isRemote);
    server.addScheduledTask(entityCitizen::setDead);
}
Also used : CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 9 with EntityCitizen

use of com.minecolonies.coremod.entity.EntityCitizen in project minecolonies by Minecolonies.

the class CitizenInfoCommand method executeSpecializedCode.

@Override
void executeSpecializedCode(@NotNull final MinecraftServer server, final ICommandSender sender, final Colony colony, final int citizenId) {
    final CitizenData citizenData = colony.getCitizen(citizenId);
    final EntityCitizen entityCitizen = citizenData.getCitizenEntity();
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizenData.getId(), citizenData.getName())));
    if (entityCitizen == null) {
        sender.sendMessage(new TextComponentTranslation(CITIZEN_NOT_LOADED));
        return;
    }
    final BlockPos citizenPosition = entityCitizen.getPosition();
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_POSITION, citizenPosition.getX(), citizenPosition.getY(), citizenPosition.getZ())));
    final BlockPos homePosition = entityCitizen.getHomePosition();
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_HOME_POSITION, homePosition.getX(), homePosition.getY(), homePosition.getZ())));
    if (entityCitizen.getWorkBuilding() == null) {
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_WORK_POSITION_NULL)));
    } else {
        final BlockPos workingPosition = entityCitizen.getWorkBuilding().getLocation();
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_WORK_POSITION, workingPosition.getX(), workingPosition.getY(), workingPosition.getZ())));
    }
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_HEALTH, entityCitizen.getHealth(), entityCitizen.getMaxHealth())));
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_LEVEL_AND_AGE, entityCitizen.getLevel(), entityCitizen.getAge(), entityCitizen.getExperienceLevel())));
    sender.sendMessage(new TextComponentString(String.format(CITIZEN_SKILLS, entityCitizen.getCharisma(), entityCitizen.getDexterity(), entityCitizen.getEndurance(), entityCitizen.getIntelligence(), entityCitizen.getStrength())));
    if (entityCitizen.getColonyJob() == null) {
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_JOB_NULL)));
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_NO_ACTIVITY)));
    } else if (entityCitizen.getWorkBuilding() != null) {
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_JOB, entityCitizen.getWorkBuilding().getJobName())));
        sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESIRED_ACTIVITY, entityCitizen.getDesiredActivity(), entityCitizen.getColonyJob().getNameTagDescription())));
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 10 with EntityCitizen

use of com.minecolonies.coremod.entity.EntityCitizen in project minecolonies by Minecolonies.

the class CitizenData method setWorkBuilding.

/**
     * Sets the work building of a citizen.
     *
     * @param building work building.
     */
public void setWorkBuilding(@Nullable final AbstractBuildingWorker building) {
    if (workBuilding != null && building != null && workBuilding != building) {
        throw new IllegalStateException("CitizenData.setWorkBuilding() - already assigned a work building when setting a new work building");
    } else if (workBuilding != building) {
        workBuilding = building;
        if (workBuilding != null) {
            //  We have a place to work, do we have the assigned Job?
            if (job == null) {
                //  No job, create one!
                setJob(workBuilding.createJob(this));
                colony.getWorkManager().clearWorkForCitizen(this);
            }
        } else if (job != null) {
            final EntityCitizen citizen = getCitizenEntity();
            if (citizen != null) {
                citizen.tasks.removeTask(citizen.tasks.taskEntries.stream().filter(task -> task.action instanceof AbstractAISkeleton).findFirst().orElse(null).action);
            }
            //  No place of employment, get rid of our job
            setJob(null);
            colony.getWorkManager().clearWorkForCitizen(this);
        }
        markDirty();
    }
}
Also used : AbstractAISkeleton(com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton) EntityCitizen(com.minecolonies.coremod.entity.EntityCitizen)

Aggregations

EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)12 BlockPos (net.minecraft.util.math.BlockPos)7 CitizenData (com.minecolonies.coremod.colony.CitizenData)4 TextComponentString (net.minecraft.util.text.TextComponentString)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)2 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)1 Colony (com.minecolonies.coremod.colony.Colony)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)1 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)1 JobGuard (com.minecolonies.coremod.colony.jobs.JobGuard)1 Permissions (com.minecolonies.coremod.colony.permissions.Permissions)1 AbstractAISkeleton (com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton)1 InventoryCitizen (com.minecolonies.coremod.inventory.InventoryCitizen)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Tessellator (net.minecraft.client.renderer.Tessellator)1 VertexBuffer (net.minecraft.client.renderer.VertexBuffer)1 EntityMob (net.minecraft.entity.monster.EntityMob)1