Search in sources :

Example 6 with ICitizenData

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;
}
Also used : IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 7 with ICitizenData

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);
        });
    }
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos)

Example 8 with ICitizenData

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;
}
Also used : Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SyncPathMessage(com.minecolonies.coremod.network.messages.client.SyncPathMessage) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) IColony(com.minecolonies.api.colony.IColony) ICitizenData(com.minecolonies.api.colony.ICitizenData) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) HashSet(java.util.HashSet)

Example 9 with ICitizenData

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);
    }
}
Also used : DefaultBuildingInstance(com.minecolonies.coremod.colony.buildings.DefaultBuildingInstance) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule) AbstractBuildingServerMessage(com.minecolonies.coremod.network.messages.server.AbstractBuildingServerMessage) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) IColony(com.minecolonies.api.colony.IColony) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) LivingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.LivingBuildingModule) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) LivingBuildingModule(com.minecolonies.coremod.colony.buildings.modules.LivingBuildingModule) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) ICitizenData(com.minecolonies.api.colony.ICitizenData) AbstractAssignedCitizenModule(com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)

Example 10 with ICitizenData

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");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ICitizenData(com.minecolonies.api.colony.ICitizenData) BlockPos(net.minecraft.util.math.BlockPos) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

ICitizenData (com.minecolonies.api.colony.ICitizenData)175 NotNull (org.jetbrains.annotations.NotNull)47 IColony (com.minecolonies.api.colony.IColony)45 BlockPos (net.minecraft.util.math.BlockPos)45 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)40 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)30 ItemStack (net.minecraft.item.ItemStack)28 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)27 PlayerEntity (net.minecraft.entity.player.PlayerEntity)26 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)22 WorkerBuildingModule (com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule)22 Nullable (org.jetbrains.annotations.Nullable)22 CompoundNBT (net.minecraft.nbt.CompoundNBT)17 ArrayList (java.util.ArrayList)16 Colony (com.minecolonies.coremod.colony.Colony)15 AbstractJobCrafter (com.minecolonies.coremod.colony.jobs.AbstractJobCrafter)14 EntityCitizen (com.minecolonies.coremod.entity.citizen.EntityCitizen)14 AbstractAssignedCitizenModule (com.minecolonies.coremod.colony.buildings.modules.AbstractAssignedCitizenModule)12 java.util (java.util)12 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)12