Search in sources :

Example 56 with Colony

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

the class RSResetCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    if (args.length == 0) {
        sender.sendMessage(new TextComponentString(NO_ARGUMENTS));
        return;
    }
    final Entity senderEntity = sender.getCommandSenderEntity();
    int colonyId = getIthArgument(args, 0, -1);
    if (colonyId == -1 && senderEntity instanceof EntityPlayer) {
        final IColony colony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), ((EntityPlayer) sender).getUniqueID());
        if (colony == null) {
            senderEntity.sendMessage(new TextComponentString(COLONY_NULL));
            return;
        }
        colonyId = colony.getID();
    }
    final Colony colony = ColonyManager.getColony(colonyId);
    if (colony == null) {
        sender.sendMessage(new TextComponentString(String.format(COLONY_NULL, colonyId)));
        return;
    }
    executeShared(server, sender, colony);
}
Also used : Entity(net.minecraft.entity.Entity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.api.colony.IColony) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 57 with Colony

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

the class CheckForAutoDeletesCommand method executeShared.

private void executeShared(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, final boolean confirmDelete) throws CommandException {
    if (sender instanceof EntityPlayer && !isPlayerOpped(sender)) {
        sender.sendMessage(new TextComponentString("Must be OP to use command"));
        return;
    } else if (sender instanceof TileEntity) {
        return;
    }
    final List<Colony> colonies = ColonyManager.getColonies();
    final List<Colony> coloniesToDelete = new ArrayList<>();
    for (int index = 0; colonies.size() - 1 >= index; index++) {
        final Colony colony = colonies.get(index);
        if (colony.canBeAutoDeleted() && Configurations.gameplay.autoDeleteColoniesInHours != 0 && colony.getLastContactInHours() >= Configurations.gameplay.autoDeleteColoniesInHours) {
            coloniesToDelete.add(colony);
        }
    }
    if (confirmDelete) {
        sender.sendMessage(new TextComponentString("Successful"));
        for (final Colony col : coloniesToDelete) {
            server.addScheduledTask(() -> ColonyManager.deleteColony(col.getID(), Configurations.gameplay.autoDestroyColonyBlocks));
        }
    } else {
        final ITextComponent deleteButton = new TextComponentString("[DELETE]").setStyle(new Style().setBold(true).setColor(TextFormatting.GOLD).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, COMMAND_CHECK_FOR_AUTODELETES)));
        sender.sendMessage(new TextComponentString("There are: " + coloniesToDelete.size() + " of a total of " + colonies.size() + " to delete."));
        sender.sendMessage(new TextComponentString("Click [DELETE] to confirm"));
        sender.sendMessage(deleteButton);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ClickEvent(net.minecraft.util.text.event.ClickEvent) ArrayList(java.util.ArrayList) ITextComponent(net.minecraft.util.text.ITextComponent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Colony(com.minecolonies.coremod.colony.Colony) Style(net.minecraft.util.text.Style) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 58 with Colony

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

the class RandomTeleportCommand method teleportPlayer.

/**
 * Method used to teleport the player.
 *
 * @param sender           the sender to have access to the world.
 * @param playerToTeleport the player which shall be teleported.
 */
private static void teleportPlayer(final ICommandSender sender, final EntityPlayer playerToTeleport) {
    // Now the position will be calculated, we will try up to 4 times to find a save position.
    int attCounter = 0;
    while (attCounter <= ATTEMPTS) {
        attCounter++;
        /* this math is to get negative numbers */
        final int x = getRandCoordinate();
        final int z = getRandCoordinate();
        if (sender.getEntityWorld().getWorldBorder().getSize() < (sender.getEntityWorld().getSpawnPoint().getDistance(x, sender.getEntityWorld().getSpawnPoint().getY(), z))) {
            continue;
        }
        final BlockPos tpPos = new BlockPos(x, STARTING_Y, z);
        final Colony colony = ColonyManager.getClosestColony(sender.getEntityWorld(), tpPos);
        /* Check for a close by colony*/
        if (BlockPosUtil.getDistance2D(colony.getCenter(), tpPos) < Configurations.gameplay.workingRangeTownHall * 2 + Configurations.gameplay.townHallPadding) {
            continue;
        }
        /*Search for a ground position*/
        final BlockPos groundPosition = BlockPosUtil.findLand(tpPos, sender.getEntityWorld());
        /*If no position found*/
        if (groundPosition == null) {
            continue;
        }
        final boolean foundPosition = BlockPosUtil.isPositionSafe(sender, groundPosition);
        if (foundPosition) {
            if (MinecoloniesCommand.canExecuteCommand((EntityPlayer) sender)) {
                playerToTeleport.sendMessage(new TextComponentString("Buckle up buttercup, this ain't no joy ride!!!"));
                playerToTeleport.setHealth(playerToTeleport.getMaxHealth());
                playerToTeleport.setPositionAndUpdate(groundPosition.getX(), groundPosition.getY() + SAFETY_DROP, groundPosition.getZ());
                playerToTeleport.setHealth(playerToTeleport.getMaxHealth());
            } else {
                sender.getCommandSenderEntity().sendMessage(new TextComponentString("Please wait at least " + Configurations.gameplay.teleportBuffer + " seconds to teleport again"));
            }
            return;
        }
    }
    playerToTeleport.getCommandSenderEntity().sendMessage(new TextComponentString("Couldn't find a safe spot.  Try again in a moment."));
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) BlockPos(net.minecraft.util.math.BlockPos) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 59 with Colony

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

the class EntityAISleep method shouldContinueExecuting.

/**
 * Continue executing if he should sleep.
 * Call the wake up method as soon as this isn't the case anymore.
 * Might search a bed while he is trying to sleep.
 *
 * @return true while he should sleep.
 */
@Override
public boolean shouldContinueExecuting() {
    if (citizen.getDesiredActivity() == EntityCitizen.DesiredActivity.SLEEP) {
        wokeUp = false;
        final Colony colony = citizen.getColony();
        if (colony == null || colony.getBuildingManager().getBuilding(citizen.getHomePosition()) == null) {
            return true;
        }
        if (usedBed == null) {
            final AbstractBuilding hut = colony.getBuildingManager().getBuilding(citizen.getHomePosition());
            if (hut instanceof BuildingHome) {
                for (final BlockPos pos : ((BuildingHome) hut).getBedList()) {
                    final World world = citizen.world;
                    IBlockState state = world.getBlockState(pos);
                    state = state.getBlock().getActualState(state, world, pos);
                    if (state.getBlock() instanceof BlockBed && !state.getValue(BlockBed.OCCUPIED) && state.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.HEAD)) {
                        usedBed = pos;
                        citizen.world.setBlockState(pos, state.withProperty(BlockBed.OCCUPIED, true), 0x03);
                        final BlockPos feetPos = pos.offset(state.getValue(BlockBed.FACING).getOpposite());
                        final IBlockState feetState = citizen.world.getBlockState(feetPos);
                        citizen.world.setBlockState(feetPos, feetState.withProperty(BlockBed.OCCUPIED, true), 0x03);
                        return true;
                    }
                }
            }
            usedBed = citizen.getHomePosition();
        } else {
            if (citizen.isWorkerAtSiteWithMove(usedBed, 1)) {
                citizen.trySleep(usedBed);
                return true;
            }
        }
        return true;
    }
    citizen.onWakeUp();
    if (usedBed != null) {
        final IBlockState state = citizen.world.getBlockState(usedBed);
        if (state.getBlock() instanceof BlockBed) {
            final IBlockState headState = citizen.world.getBlockState(usedBed);
            citizen.world.setBlockState(usedBed, headState.withProperty(BlockBed.OCCUPIED, false), 0x03);
            final BlockPos feetPos = usedBed.offset(headState.getValue(BlockBed.FACING).getOpposite());
            final IBlockState feetState = citizen.world.getBlockState(feetPos);
            citizen.world.setBlockState(feetPos, feetState.withProperty(BlockBed.OCCUPIED, true), 0x03);
        }
        usedBed = null;
    }
    wokeUp = true;
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BuildingHome(com.minecolonies.coremod.colony.buildings.BuildingHome) Colony(com.minecolonies.coremod.colony.Colony) BlockBed(net.minecraft.block.BlockBed) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 60 with Colony

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

the class DeliveryRequestResolver method onRequestCancelled.

@Nullable
@Override
public IRequest<?> onRequestCancelled(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends Delivery> request) {
    if (!manager.getColony().getWorld().isRemote) {
        final Colony colony = (Colony) manager.getColony();
        final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(c -> c.getJob() instanceof JobDeliveryman && ((JobDeliveryman) c.getJob()).getTaskQueue().contains(request.getToken())).findFirst().orElse(null);
        if (freeDeliveryMan == null) {
            MineColonies.getLogger().error("Parent cancellation failed! Unknown request: " + request.getToken());
        } else {
            final JobDeliveryman job = (JobDeliveryman) freeDeliveryMan.getJob();
            job.onTaskDeletion(request.getToken());
        }
    }
    return null;
}
Also used : JobDeliveryman(com.minecolonies.coremod.colony.jobs.JobDeliveryman) Colony(com.minecolonies.coremod.colony.Colony) CitizenData(com.minecolonies.coremod.colony.CitizenData) 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