Search in sources :

Example 1 with BuildingBasedRequester

use of com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester 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 2 with BuildingBasedRequester

use of com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester in project minecolonies by Minecolonies.

the class BuildingBasedRequesterFactory method getNewInstance.

@NotNull
@Override
public BuildingBasedRequester getNewInstance(@NotNull final IFactoryController factoryController, @NotNull final AbstractBuilding building, @NotNull final Object... context) throws IllegalArgumentException {
    if (context.length != 0) {
        throw new IllegalArgumentException("To many context elements. Only 0 supported.");
    }
    final ILocation location = factoryController.getNewInstance(TypeConstants.ILOCATION, building.getLocation(), building.getColony().getWorld().provider.getDimension());
    final IToken token = factoryController.getNewInstance(TypeConstants.ITOKEN);
    return new BuildingBasedRequester(location, token);
}
Also used : BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with BuildingBasedRequester

use of com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester in project minecolonies by Minecolonies.

the class AbstractBuildingDependentRequestResolver method getBuilding.

@Override
@Nullable
public Optional<IRequester> getBuilding(@NotNull final IRequestManager manager, @NotNull final IToken<?> token) {
    final IRequest request = manager.getRequestForToken(token);
    if (request.getRequester() instanceof BuildingBasedRequester) {
        final BuildingBasedRequester requester = (BuildingBasedRequester) request.getRequester();
        final ILocation requesterLocation = requester.getRequesterLocation();
        if (requesterLocation.equals(getRequesterLocation())) {
            return requester.getBuilding(manager, token);
        }
    }
    return Optional.empty();
}
Also used : BuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester) IBuildingBasedRequester(com.minecolonies.coremod.colony.requestsystem.requesters.IBuildingBasedRequester) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

BuildingBasedRequester (com.minecolonies.coremod.colony.requestsystem.requesters.BuildingBasedRequester)3 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 Nullable (org.jetbrains.annotations.Nullable)2 IColony (com.minecolonies.api.colony.IColony)1 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)1 IDeliverable (com.minecolonies.api.colony.requestsystem.requestable.IDeliverable)1 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)1 CitizenData (com.minecolonies.coremod.colony.CitizenData)1 Colony (com.minecolonies.coremod.colony.Colony)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 IBuildingBasedRequester (com.minecolonies.coremod.colony.requestsystem.requesters.IBuildingBasedRequester)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 InvWrapper (net.minecraftforge.items.wrapper.InvWrapper)1 NotNull (org.jetbrains.annotations.NotNull)1