Search in sources :

Example 6 with CitizenData

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");
            }
        }
    }
}
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 7 with CitizenData

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;
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) BlockPos(net.minecraft.util.math.BlockPos) CitizenData(com.minecolonies.coremod.colony.CitizenData) BuildingGuardTower(com.minecolonies.coremod.colony.buildings.BuildingGuardTower) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with CitizenData

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);
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ArrayList(java.util.ArrayList) ITextComponent(net.minecraft.util.text.ITextComponent) IColony(com.minecolonies.coremod.colony.IColony) CitizenData(com.minecolonies.coremod.colony.CitizenData) TextComponentString(net.minecraft.util.text.TextComponentString) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.coremod.colony.IColony) Style(net.minecraft.util.text.Style) BlockPos(net.minecraft.util.math.BlockPos)

Example 9 with CitizenData

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);
}
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 10 with CitizenData

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

Aggregations

CitizenData (com.minecolonies.coremod.colony.CitizenData)11 BlockPos (net.minecraft.util.math.BlockPos)7 Colony (com.minecolonies.coremod.colony.Colony)5 EntityCitizen (com.minecolonies.coremod.entity.EntityCitizen)4 TextComponentString (net.minecraft.util.text.TextComponentString)4 NotNull (org.jetbrains.annotations.NotNull)3 AbstractBuildingWorker (com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker)2 Nullable (org.jetbrains.annotations.Nullable)2 IColony (com.minecolonies.coremod.colony.IColony)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 BuildingGuardTower (com.minecolonies.coremod.colony.buildings.BuildingGuardTower)1 BuildingTownHall (com.minecolonies.coremod.colony.buildings.BuildingTownHall)1 JobBuilder (com.minecolonies.coremod.colony.jobs.JobBuilder)1 ArrayList (java.util.ArrayList)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ITextComponent (net.minecraft.util.text.ITextComponent)1 Style (net.minecraft.util.text.Style)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1 ClickEvent (net.minecraft.util.text.event.ClickEvent)1 World (net.minecraft.world.World)1