use of com.minecolonies.api.colony.requestsystem.requestable.IDeliverable 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());
}
use of com.minecolonies.api.colony.requestsystem.requestable.IDeliverable in project minecolonies by Minecolonies.
the class PlacementHandlers method checkForListInInvAndRequest.
/**
* Check the placers inventory for the items in the itemList and remove it of the list if found.
*
* @param placer the placer.
* @param itemList the list to check.
* @return true if need to request.
*/
public static boolean checkForListInInvAndRequest(@NotNull final AbstractEntityAIStructure<?> placer, final List<ItemStack> itemList) {
final List<ItemStack> foundStacks = InventoryUtils.filterItemHandler(new InvWrapper(placer.getWorker().getInventoryCitizen()), itemStack -> itemList.stream().anyMatch(targetStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, targetStack, true, true)));
itemList.removeIf(itemStack -> ItemStackUtils.isEmpty(itemStack) || foundStacks.stream().anyMatch(targetStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, targetStack, true, true)));
for (final ItemStack placedStack : itemList) {
if (ItemStackUtils.isEmpty(placedStack)) {
return true;
}
if (placer.getOwnBuilding().getOpenRequestsOfTypeFiltered(placer.getWorker().getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(placedStack)).isEmpty()) {
final Stack stackRequest = new Stack(placer.getTotalAmount(placedStack));
placer.getWorker().getCitizenData().createRequest(stackRequest);
return true;
}
}
return false;
}
use of com.minecolonies.api.colony.requestsystem.requestable.IDeliverable in project minecolonies by Minecolonies.
the class AbstractEntityAIBasic method checkIfRequestForItemExistOrCreateAsynch.
/**
* Check if a stack has been requested already or is in the inventory.
* If not in the inventory and not requested already, create request
*
* @param stack the requested stack.
* @return true if in the inventory, else false.
*/
public boolean checkIfRequestForItemExistOrCreateAsynch(@NotNull final ItemStack stack) {
if (InventoryUtils.hasItemInItemHandler(new InvWrapper(worker.getInventoryCitizen()), s -> ItemStackUtils.compareItemStacksIgnoreStackSize(s, stack) && s.getCount() >= stack.getCount())) {
return true;
}
if (InventoryUtils.getItemCountInProvider(getOwnBuilding(), itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack, true, true)) >= stack.getCount() && InventoryUtils.transferXOfFirstSlotInProviderWithIntoNextFreeSlotInItemHandler(getOwnBuilding(), itemStack -> ItemStackUtils.compareItemStacksIgnoreStackSize(itemStack, stack, true, true), stack.getCount(), new InvWrapper(worker.getInventoryCitizen()))) {
return true;
}
if (getOwnBuilding().getOpenRequestsOfTypeFiltered(worker.getCitizenData(), TypeConstants.DELIVERABLE, (IRequest<? extends IDeliverable> r) -> r.getRequest().matches(stack)).isEmpty()) {
final Stack stackRequest = new Stack(stack);
worker.getCitizenData().createRequestAsync(stackRequest);
}
return false;
}
use of com.minecolonies.api.colony.requestsystem.requestable.IDeliverable in project minecolonies by Minecolonies.
the class AbstractBuilding method getRequiredItemsAndAmount.
/**
* Override this method if you want to keep an amount of items in inventory.
* When the inventory is full, everything get's dumped into the building chest.
* But you can use this method to hold some stacks back.
*
* @return a list of objects which should be kept.
*/
public Map<Predicate<ItemStack>, Integer> getRequiredItemsAndAmount() {
final Map<Predicate<ItemStack>, Integer> toKeep = new HashMap<>();
toKeep.putAll(keepX);
final IRequestManager manager = colony.getRequestManager();
toKeep.put(stack -> this.getOpenRequestsByCitizen().values().stream().anyMatch(list -> list.stream().anyMatch(token -> manager.getRequestForToken(token).getRequest() instanceof IDeliverable && ((IDeliverable) manager.getRequestForToken(token).getRequest()).matches(stack))), Integer.MAX_VALUE);
return toKeep;
}
use of com.minecolonies.api.colony.requestsystem.requestable.IDeliverable in project minecolonies by Minecolonies.
the class WarehouseRequestResolver method canResolve.
@Override
public boolean canResolve(@NotNull final IRequestManager manager, final IRequest<? extends IDeliverable> requestToCheck) {
if (!manager.getColony().getWorld().isRemote) {
final Colony colony = (Colony) manager.getColony();
final Set<TileEntityWareHouse> wareHouses = getWareHousesInColony(colony);
wareHouses.removeIf(Objects::isNull);
try {
return wareHouses.stream().anyMatch(wareHouse -> wareHouse.hasMatchinItemStackInWarehouse(itemStack -> requestToCheck.getRequest().matches(itemStack)));
} catch (Exception e) {
Log.getLogger().error(e);
}
}
return false;
}
Aggregations