use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class CommandCitizenList method displayListFor.
private int displayListFor(final CommandContext<CommandSource> context, int page) {
// Colony
final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, context.getSource().getLevel().dimension());
if (colony == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
return 0;
}
final List<ICitizenData> citizens = colony.getCitizenManager().getCitizens();
final int citizenCount = citizens.size();
// check to see if we have to add one page to show the half page
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<ICitizenData> citizensPage = getCitizensOnPage(citizens, citizenCount, pageStartIndex, pageStopIndex);
final ITextComponent headerLine = LanguageHandler.buildChatComponent("com.minecolonies.command.citizenlist.pagetop", page, pageCount);
context.getSource().sendSuccess(headerLine, true);
drawCitizens(context, citizensPage);
drawPageSwitcher(context, page, citizenCount, halfPage, colony.getID());
return 1;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class CommandCitizenList method drawCitizens.
private void drawCitizens(@NotNull final CommandContext<CommandSource> context, final List<ICitizenData> citizensPage) {
for (final ICitizenData citizen : citizensPage) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.desc", citizen.getId(), citizen.getName()).setStyle(Style.EMPTY.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format(COMMAND_CITIZEN_INFO, citizen.getColony().getID(), citizen.getId())))), true);
citizen.getEntity().ifPresent(entityCitizen -> {
final BlockPos position = entityCitizen.blockPosition();
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.pos", position.getX(), position.getY(), position.getZ()), true);
});
}
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class CommandCitizenTrack method onExecute.
/**
* What happens when the command is executed after preConditions are successful.
*
* @param context the context of the command execution
*/
@Override
public int onExecute(final CommandContext<CommandSource> context) {
final Entity sender = context.getSource().getEntity();
if (!(sender instanceof PlayerEntity)) {
return 1;
}
// Colony
final int colonyID = IntegerArgumentType.getInteger(context, COLONYID_ARG);
final IColony colony = IColonyManager.getInstance().getColonyByDimension(colonyID, sender == null ? World.OVERWORLD : context.getSource().getLevel().dimension());
if (colony == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.colonyidnotfound", colonyID), true);
return 0;
}
final ICitizenData citizenData = colony.getCitizenManager().getCivilian(IntegerArgumentType.getInteger(context, CITIZENID_ARG));
if (citizenData == null) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notfound"), true);
return 0;
}
final Optional<AbstractEntityCitizen> optionalEntityCitizen = citizenData.getEntity();
if (!optionalEntityCitizen.isPresent()) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizeninfo.notloaded"), true);
return 0;
}
final AbstractEntityCitizen entityCitizen = optionalEntityCitizen.get();
if (AbstractPathJob.trackingMap.getOrDefault((PlayerEntity) sender, UUID.randomUUID()).equals(entityCitizen.getUUID())) {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.disable"), true);
AbstractPathJob.trackingMap.remove((PlayerEntity) sender);
Network.getNetwork().sendToPlayer(new SyncPathMessage(new HashSet<>(), new HashSet<>(), new HashSet<>()), (ServerPlayerEntity) sender);
} else {
context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.citizentrack.success.enable"), true);
AbstractPathJob.trackingMap.put((PlayerEntity) sender, entityCitizen.getUUID());
}
return 1;
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class AssignUnassignMessage method onExecute.
@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final DefaultBuildingInstance building) {
final ICitizenData citizen = colony.getCitizenManager().getCivilian(citizenID);
final AbstractAssignedCitizenModule module;
if (jobEntry == null) {
module = building.getFirstModuleOccurance(LivingBuildingModule.class);
} else {
module = building.getModuleMatching(WorkerBuildingModule.class, m -> m.getJobEntry() == jobEntry);
}
if (assign && !module.isFull() && !building.equals(citizen.getHomeBuilding())) {
if (citizen.getHomeBuilding() != null) {
citizen.getHomeBuilding().getFirstModuleOccurance(LivingBuildingModule.class).removeCitizen(citizen);
}
module.assignCitizen(citizen);
} else if (module.hasAssignedCitizen(citizen)) {
module.removeCitizen(citizen);
}
}
use of com.minecolonies.api.colony.ICitizenData in project minecolonies by Minecolonies.
the class RecallCitizenMessage method onExecute.
@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
final List<ICitizenData> citizens = new ArrayList<>(building.getAllAssignedCitizen());
for (int i = 0; i < building.getAllAssignedCitizen().size(); i++) {
Optional<AbstractEntityCitizen> optionalEntityCitizen = citizens.get(i).getEntity();
final ICitizenData citizenData = citizens.get(i);
if (!optionalEntityCitizen.isPresent()) {
if (citizenData != null) {
Log.getLogger().warn(String.format("Citizen #%d:%d has gone AWOL, respawning them!", colony.getID(), citizenData.getId()));
citizenData.setNextRespawnPosition(EntityUtils.getSpawnPoint(colony.getWorld(), building.getPosition()));
citizenData.updateEntityIfNecessary();
} else {
Log.getLogger().warn("Citizen is AWOL and citizenData is null!");
return;
}
} else if (optionalEntityCitizen.get().getTicksExisted() == 0) {
citizenData.getEntity().ifPresent(Entity::remove);
citizenData.updateEntityIfNecessary();
}
final BlockPos loc = building.getPosition();
if (optionalEntityCitizen.isPresent() && !TeleportHelper.teleportCitizen(optionalEntityCitizen.get(), colony.getWorld(), loc)) {
final PlayerEntity player = ctxIn.getSender();
if (player == null) {
return;
}
LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.workerhuts.recallFail");
}
}
}
Aggregations