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