Search in sources :

Example 1 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class AbstractCitizensCommands method execute.

@NotNull
@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    if (args.length == 0) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    boolean firstArgumentColonyId = true;
    int colonyId = -1;
    if (args.length >= 2) {
        colonyId = getIthArgument(args, 0, -1);
        if (colonyId == -1) {
            firstArgumentColonyId = false;
        }
    }
    final Colony colony;
    if (sender instanceof EntityPlayer && colonyId == -1) {
        final IColony tempColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), (EntityPlayer) sender);
        if (tempColony != null) {
            colonyId = tempColony.getID();
            firstArgumentColonyId = false;
        }
    }
    colony = ColonyManager.getColony(colonyId);
    if (colony == null) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    if (sender instanceof EntityPlayer) {
        final EntityPlayer player = (EntityPlayer) sender;
        if (!canPlayerUseCommand(player, getCommand(), colonyId)) {
            sender.getCommandSenderEntity().sendMessage(new TextComponentString(NOT_PERMITTED));
            return;
        }
    }
    final int citizenId = getValidCitizenId(colony, firstArgumentColonyId, args);
    if (citizenId == -1 || colony.getCitizen(citizenId) == null) {
        sender.getCommandSenderEntity().sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    executeSpecializedCode(server, sender, colony, citizenId);
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.coremod.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.coremod.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class BuildToolPlaceMessage method handleHut.

/**
     * Handles the placement of huts.
     *
     * @param world         World the hut is being placed into.
     * @param player        Who placed the hut.
     * @param sn            The name of the structure.
     * @param workOrderName The name of the work order.
     * @param rotation      The number of times the structure should be rotated.
     * @param buildPos      The location the hut is being placed.
     * @param mirror        Whether or not the strcture is mirrored.
     */
private static void handleHut(@NotNull final World world, @NotNull final EntityPlayer player, final Structures.StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
    final String hut = sn.getSection();
    final Block block = Block.getBlockFromName(Constants.MOD_ID + ":blockHut" + hut);
    final Colony tempColony = ColonyManager.getClosestColony(world, buildPos);
    if (tempColony != null && (!tempColony.getPermissions().hasPermission(player, Action.MANAGE_HUTS) && !(block instanceof BlockHutTownHall && BlockPosUtil.getDistance2D(tempColony.getCenter(), buildPos) >= Configurations.workingRangeTownHall * 2 + Configurations.townHallPadding))) {
        return;
    }
    if (block != null && player.inventory.hasItemStack(new ItemStack(block))) {
        if (EventHandler.onBlockHutPlaced(world, player, block, buildPos)) {
            world.destroyBlock(buildPos, true);
            world.setBlockState(buildPos, block.getDefaultState().withRotation(BlockUtils.getRotation(rotation)));
            ((AbstractBlockHut) block).onBlockPlacedByBuildTool(world, buildPos, world.getBlockState(buildPos), player, null, mirror, sn.getStyle());
            player.inventory.clearMatchingItems(Item.getItemFromBlock(block), -1, 1, null);
            setupBuilding(world, player, sn, rotation, buildPos, mirror);
        }
    } else {
        LanguageHandler.sendPlayerMessage(player, BuildToolPlaceMessage.NO_HUT_IN_INVENTORY);
    }
}
Also used : Block(net.minecraft.block.Block) Colony(com.minecolonies.coremod.colony.Colony) TextComponentString(net.minecraft.util.text.TextComponentString) BlockHutTownHall(com.minecolonies.coremod.blocks.BlockHutTownHall) ItemStack(net.minecraft.item.ItemStack) AbstractBlockHut(com.minecolonies.coremod.blocks.AbstractBlockHut)

Example 3 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class BuildToolPlaceMessage method setupBuilding.

/**
     * setup the building once it has been placed.
     *
     * @param world         World the hut is being placed into.
     * @param player        Who placed the hut.
     * @param sn            The name of the structure.
     * @param workOrderName The name of the work order.
     * @param rotation      The number of times the structure should be rotated.
     * @param buildPos      The location the hut is being placed.
     * @param mirror        Whether or not the strcture is mirrored.
     */
private static void setupBuilding(@NotNull final World world, @NotNull final EntityPlayer player, final Structures.StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
    @Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, buildPos);
    if (building == null) {
        Log.getLogger().error("BuildTool: building is null!");
    } else {
        if (building.getTileEntity() != null) {
            final Colony colony = ColonyManager.getColony(world, buildPos);
            if (colony == null) {
                Log.getLogger().info("No colony for " + player.getName());
            } else {
                building.getTileEntity().setColony(colony);
            }
        }
        building.setStyle(sn.getStyle());
        building.setRotation(rotation);
        if (mirror) {
            building.setMirror();
        }
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) Nullable(org.jetbrains.annotations.Nullable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 4 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class HireFireMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final HireFireMessage 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;
        }
        if (message.hire) {
            final CitizenData citizen = colony.getCitizen(message.citizenID);
            ((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(citizen);
        } else {
            ((AbstractBuildingWorker) colony.getBuilding(message.buildingId)).setWorker(null);
        }
    }
}
Also used : AbstractBuildingWorker(com.minecolonies.coremod.colony.buildings.AbstractBuildingWorker) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData)

Example 5 with Colony

use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.

the class DeliveryRequestResolver method attemptResolve.

@Nullable
@Override
public List<IToken<?>> attemptResolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends Delivery> request) {
    if (manager.getColony().getWorld().isRemote) {
        return null;
    }
    final Colony colony = (Colony) manager.getColony();
    // We can do an instant get here, since we are already filtering on anything that has no entity.
    final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(citizenData -> citizenData.getCitizenEntity().map(entityCitizen -> request.getRequest().getTarget().isReachableFromLocation(entityCitizen.getLocation())).orElse(false)).filter(c -> c.getJob() instanceof JobDeliveryman).min(Comparator.comparing((CitizenData c) -> ((JobDeliveryman) c.getJob()).getTaskQueue().size()).thenComparing(Comparator.comparing(c -> {
        BlockPos targetPos = request.getRequest().getTarget().getInDimensionLocation();
        // We can do an instant get here, since we are already filtering on anything that has no entity.
        BlockPos entityLocation = c.getCitizenEntity().get().getLocation().getInDimensionLocation();
        return BlockPosUtil.getDistanceSquared(targetPos, entityLocation);
    }))).orElse(null);
    if (freeDeliveryMan == null) {
        return null;
    }
    final JobDeliveryman job = (JobDeliveryman) freeDeliveryMan.getJob();
    job.addRequest(request.getToken());
    return Lists.newArrayList();
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Colony(com.minecolonies.coremod.colony.Colony) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) BlockPos(net.minecraft.util.math.BlockPos) TypeToken(com.google.common.reflect.TypeToken) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) Log(com.minecolonies.blockout.Log) IRequestManager(com.minecolonies.api.colony.requestsystem.manager.IRequestManager) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Nullable(org.jetbrains.annotations.Nullable) CitizenData(com.minecolonies.coremod.colony.CitizenData) List(java.util.List) Lists(com.google.common.collect.Lists) MineColonies(com.minecolonies.coremod.MineColonies) Delivery(com.minecolonies.api.colony.requestsystem.requestable.Delivery) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) AbstractRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.core.AbstractRequestResolver) JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) BlockPos(net.minecraft.util.math.BlockPos) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Colony (com.minecolonies.coremod.colony.Colony)81 TextComponentString (net.minecraft.util.text.TextComponentString)29 IColony (com.minecolonies.api.colony.IColony)21 EntityPlayer (net.minecraft.entity.player.EntityPlayer)20 BlockPos (net.minecraft.util.math.BlockPos)19 Nullable (org.jetbrains.annotations.Nullable)16 CitizenData (com.minecolonies.coremod.colony.CitizenData)13 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)13 NotNull (org.jetbrains.annotations.NotNull)11 ItemStack (net.minecraft.item.ItemStack)9 Entity (net.minecraft.entity.Entity)8 TileEntity (net.minecraft.tileentity.TileEntity)8 World (net.minecraft.world.World)6 List (java.util.List)5 UUID (java.util.UUID)5 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)4 Delivery (com.minecolonies.api.colony.requestsystem.requestable.Delivery)4 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)4 AbstractBlockHut (com.minecolonies.coremod.blocks.AbstractBlockHut)4