use of com.minecolonies.coremod.colony.CitizenData 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.colony.CitizenData in project minecolonies by Minecolonies.
the class ItemScepterGuard method handleItemUsage.
/**
* Handles the usage of the item.
*
* @param worldIn the world it is used in.
* @param pos the position.
* @param compound the compound.
* @param playerIn the player using it.
* @return if it has been successful.
*/
@NotNull
private static EnumActionResult handleItemUsage(final World worldIn, final BlockPos pos, final NBTTagCompound compound, final EntityPlayer playerIn) {
final Colony colony = ColonyManager.getClosestColony(worldIn, pos);
if (colony == null) {
return EnumActionResult.FAIL;
}
final BlockPos guardTower = BlockPosUtil.readFromNBT(compound, "pos");
final AbstractBuilding hut = colony.getBuilding(guardTower);
if (hut == null || !(hut instanceof BuildingGuardTower)) {
return EnumActionResult.FAIL;
}
if (BlockPosUtil.getDistance2D(pos, guardTower) > ((BuildingGuardTower) hut).getPatrolDistance()) {
LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuardTooFar");
return EnumActionResult.FAIL;
}
final BuildingGuardTower.Task task = BuildingGuardTower.Task.values()[compound.getInteger("task")];
final CitizenData citizen = ((BuildingGuardTower) hut).getWorker();
String name = "";
if (citizen != null) {
name = " " + citizen.getName();
}
if (task.equals(BuildingGuardTower.Task.GUARD)) {
LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickGuard", pos, name);
((BuildingGuardTower) hut).setGuardTarget(pos);
playerIn.inventory.removeStackFromSlot(playerIn.inventory.currentItem);
} else {
if (!compound.hasKey(TAG_LAST_POS)) {
((BuildingGuardTower) hut).resetPatrolTargets();
}
((BuildingGuardTower) hut).addPatrolTargets(pos);
LanguageHandler.sendPlayerMessage(playerIn, "com.minecolonies.coremod.job.guard.toolClickPatrol", pos, name);
}
BlockPosUtil.writeToNBT(compound, TAG_LAST_POS, pos);
return EnumActionResult.SUCCESS;
}
use of com.minecolonies.coremod.colony.CitizenData in project minecolonies by Minecolonies.
the class ListCitizensCommand method execute.
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
int colonyId = getIthArgument(args, 0, getColonyId(sender));
if (sender instanceof EntityPlayer) {
if (colonyId == -1) {
IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), (EntityPlayer) sender);
if (colony != null) {
colonyId = colony.getID();
}
}
final EntityPlayer player = (EntityPlayer) sender;
if (!canPlayerUseCommand(player, LISTCITIZENS, colonyId)) {
sender.getCommandSenderEntity().sendMessage(new TextComponentString("Not happenin bro!!, You are not permitted to do that!"));
return;
}
}
final Colony colony = ColonyManager.getColony(colonyId);
final List<CitizenData> citizens = new ArrayList<>(colony.getCitizens().values());
final int citizenCount = citizens.size();
// check to see if we have to add one page to show the half page
int page = getIthArgument(args, 1, 1);
final int halfPage = (citizenCount % CITIZENS_ON_PAGE == 0) ? 0 : 1;
final int pageCount = ((citizenCount) / CITIZENS_ON_PAGE) + halfPage;
if (page < 1 || page > pageCount) {
page = 1;
}
final int pageStartIndex = CITIZENS_ON_PAGE * (page - 1);
final int pageStopIndex = Math.min(CITIZENS_ON_PAGE * page, citizenCount);
final List<CitizenData> citizensPage;
if (pageStartIndex < 0 || pageStartIndex >= citizenCount) {
citizensPage = new ArrayList<>();
} else {
citizensPage = citizens.subList(pageStartIndex, pageStopIndex);
}
final ITextComponent headerLine = new TextComponentString(String.format(PAGE_TOP, page, pageCount));
sender.sendMessage(headerLine);
for (final CitizenData citizen : citizensPage) {
sender.sendMessage(new TextComponentString(String.format(CITIZEN_DESCRIPTION, citizen.getId(), citizen.getName())).setStyle(new Style().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_CITIZEN_INFO, citizen.getColony().getID(), citizen.getId())))));
if (citizen.getCitizenEntity() != null) {
final BlockPos position = citizen.getCitizenEntity().getPosition();
sender.sendMessage(new TextComponentString(String.format(COORDINATES_XYZ, position.getX(), position.getY(), position.getZ())));
}
}
drawPageSwitcher(sender, page, citizenCount, halfPage, colonyId);
}
use of com.minecolonies.coremod.colony.CitizenData 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.colony.CitizenData 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())));
}
}
Aggregations