Search in sources :

Example 6 with Colony

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

the class DeliveryRequestResolver method canResolve.

@Override
public boolean canResolve(@NotNull final IRequestManager manager, final IRequest<? extends Delivery> requestToCheck) {
    if (manager.getColony().getWorld().isRemote) {
        return false;
    }
    final Colony colony = (Colony) manager.getColony();
    final CitizenData freeDeliveryMan = colony.getCitizenManager().getCitizens().stream().filter(citizenData -> citizenData.getCitizenEntity().map(entityCitizen -> requestToCheck.getRequest().getTarget().isReachableFromLocation(entityCitizen.getLocation())).orElse(false)).filter(c -> c.getJob() instanceof JobDeliveryman).findFirst().orElse(null);
    return freeDeliveryMan != null;
}
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)

Example 7 with Colony

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

the class StandardPlayerRequestResolver method resolve.

@Nullable
@Override
public void resolve(@NotNull final IRequestManager manager, @NotNull final IRequest request) throws RuntimeException {
    final IColony colony = manager.getColony();
    if (colony instanceof Colony) {
        if (Configurations.requestSystem.creativeResolve && request.getRequest() instanceof IDeliverable && request.getRequester() instanceof BuildingBasedRequester && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).isPresent() && ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).get() instanceof AbstractBuilding) {
            final AbstractBuilding building = (AbstractBuilding) ((BuildingBasedRequester) request.getRequester()).getBuilding(manager, request.getToken()).get();
            final Optional<CitizenData> citizenDataOptional = building.getCitizenForRequest(request.getToken());
            final List<ItemStack> resolvablestacks = request.getDisplayStacks();
            if (!resolvablestacks.isEmpty() && citizenDataOptional.isPresent()) {
                final ItemStack resolveStack = resolvablestacks.get(0);
                resolveStack.setCount(Math.min(((IDeliverable) request.getRequest()).getCount(), resolveStack.getMaxStackSize()));
                final ItemStack remainingItemStack = InventoryUtils.addItemStackToItemHandlerWithResult(new InvWrapper(citizenDataOptional.get().getInventory()), resolveStack);
                if (ItemStackUtils.isEmpty(remainingItemStack)) {
                    manager.updateRequestState(request.getToken(), RequestState.COMPLETED);
                    return;
                }
            }
        }
        final List<EntityPlayer> players = new ArrayList<>(((Colony) colony).getMessageEntityPlayers());
        final EntityPlayer owner = ServerUtils.getPlayerFromUUID(colony.getWorld(), ((Colony) colony).getPermissions().getOwner());
        final TextComponentString colonyDescription = new TextComponentString(colony.getName() + ":");
        if (manager.getColony().getWorld().isDaytime()) {
            if (owner != null) {
                players.remove(owner);
                LanguageHandler.sendPlayerMessage(owner, "com.minecolonies.requestsystem.playerresolver", request.getRequester().getDisplayName(manager, request.getToken()).getFormattedText(), getRequestMessage(request).getFormattedText(), request.getRequester().getRequesterLocation().toString());
            }
            LanguageHandler.sendPlayersMessage(players, "com.minecolonies.requestsystem.playerresolver", colonyDescription.getFormattedText() + " " + request.getRequester().getDisplayName(manager, request.getToken()).getFormattedText(), getRequestMessage(request).getFormattedText(), request.getRequester().getRequesterLocation().toString());
        }
    }
    assignedRequests.add(request.getToken());
}
Also used : BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) IColony(com.minecolonies.api.colony.IColony) CitizenData(com.minecolonies.coremod.colony.CitizenData) TextComponentString(net.minecraft.util.text.TextComponentString) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Colony(com.minecolonies.coremod.colony.Colony) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) IDeliverable(com.minecolonies.api.colony.requestsystem.requestable.IDeliverable) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with Colony

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

the class ClaimChunksCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
    // See if the player is opped.
    if (sender instanceof EntityPlayerMP && isPlayerOpped(sender)) {
        final Colony colony = actionMenu.getColonyForArgument("colony");
        if (colony == null) {
            sender.sendMessage(new TextComponentString(NO_COLONY_MESSAGE));
            return;
        }
        final int range = actionMenu.getIntegerForArgument("range");
        final Boolean add = actionMenu.getBooleanForArgument("add");
        final Chunk chunk = ((EntityPlayerMP) sender).getServerWorld().getChunkFromBlockCoords(sender.getPosition());
        ColonyManager.claimChunksInRange(colony.getID(), colony.getDimension(), add == null ? true : add, chunk.x, chunk.z, range, 0);
        return;
    } else {
        sender.sendMessage(new TextComponentString(NO_PERMISSION_TO_CLAIM_MESSAGE));
    }
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) TeleportToColony(com.minecolonies.coremod.util.TeleportToColony) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) Chunk(net.minecraft.world.chunk.Chunk) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 9 with Colony

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

the class ColonyTeleportCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final ActionMenu actionMenu) throws CommandException {
    Colony colony = actionMenu.getColonyForArgument("colony");
    if (null == colony) {
        final EntityPlayer player = actionMenu.getPlayerForArgument("player");
        if (player != null) {
            IColony iColony = ColonyManager.getIColonyByOwner(server.getEntityWorld(), player);
            if (null == iColony) {
                if (sender instanceof EntityPlayer) {
                    final Entity senderEntity = sender.getCommandSenderEntity();
                    if (senderEntity != null) {
                        final UUID mayorID = senderEntity.getUniqueID();
                        if (iColony == null) {
                            iColony = ColonyManager.getIColonyByOwner(sender.getEntityWorld(), mayorID);
                        }
                    }
                }
            }
            if (null != iColony) {
                colony = ColonyManager.getColony(iColony.getID());
            }
        }
    }
    // Required argument: would never be null at this point.
    if (null == colony) {
        sender.sendMessage(new TextComponentString("You are not allowed to do this"));
        return;
    }
    executeShared(server, sender, colony);
}
Also used : Entity(net.minecraft.entity.Entity) Colony(com.minecolonies.coremod.colony.Colony) TeleportToColony(com.minecolonies.coremod.util.TeleportToColony) IColony(com.minecolonies.api.colony.IColony) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IColony(com.minecolonies.api.colony.IColony) UUID(java.util.UUID) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 10 with Colony

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

the class ColonyTeleportCommand method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String... args) throws CommandException {
    Colony colony = null;
    // see if player is allowed to use in the configs
    if (args.length == 1) {
        try {
            final int colonyId = Integer.parseInt(args[0]);
            colony = ColonyManager.getColony(colonyId);
        } catch (final NumberFormatException e) {
        // we ignore the exception and deal with a null colony below.
        }
    }
    if (null == colony) {
        sender.sendMessage(new TextComponentString("You are not allowed to do this"));
        return;
    }
    executeShared(server, sender, colony);
}
Also used : Colony(com.minecolonies.coremod.colony.Colony) TeleportToColony(com.minecolonies.coremod.util.TeleportToColony) IColony(com.minecolonies.api.colony.IColony) TextComponentString(net.minecraft.util.text.TextComponentString)

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