use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.
the class RequestHandler method processParentReplacement.
/**
* Method used during clean up to process Parent replacement.
*
* @param manager The manager which is handling the cleanup.
* @param target The target request, which gets their parent replaced.
* @param newParent The new cleanup request used to cleanup the target when it is finished.
*/
@SuppressWarnings({ RAWTYPES, UNCHECKED })
public static void processParentReplacement(final IStandardRequestManager manager, final IRequest target, final IRequest newParent) {
// Clear out the existing parent.
if (target.hasParent()) {
final IRequest currentParent = RequestHandler.getRequest(manager, target.getParent());
currentParent.removeChild(target.getToken());
target.setParent(null);
}
if (newParent != null) {
// Switch out the parent, and add the old child to the cleanup request as new child
newParent.addChild(target.getToken());
target.setParent(newParent.getToken());
// Assign the new parent request if it is not assigned yet.
if (!RequestHandler.isAssigned(manager, newParent.getToken())) {
RequestHandler.assignRequest(manager, newParent);
}
}
}
use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.
the class RequestHandler method onRequestCancelled.
/**
* Method used to handle requests that were overruled or cancelled.
* Cancels all children first, handles the creation of clean up requests.
*
* @param manager The manager that got notified of the cancellation or overruling.
* @param token The token of the request that got cancelled or overruled
*/
@SuppressWarnings(UNCHECKED)
public static void onRequestCancelled(final IStandardRequestManager manager, final IToken<?> token) {
@SuppressWarnings(RAWTYPES) final IRequest request = RequestHandler.getRequest(manager, token);
if (request == null) {
return;
}
request.setState(new WrappedStaticStateRequestManager(manager), RequestState.CANCELLED);
processInternalCancellation(manager, token);
// Notify the requester.
final IRequester requester = request.getRequester();
requester.onRequestCancelled(manager, token);
cleanRequestData(manager, token);
}
use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.
the class RequestHandler method processInternalCancellation.
/**
* Method used to handle cancellation internally without notifying the requester that the request has been cancelled.
*
* @param manager The manager for which the cancellation is internally processed.
* @param token The token which is internally processed.
*/
@SuppressWarnings(UNCHECKED)
public static void processInternalCancellation(final IStandardRequestManager manager, final IToken<?> token) {
@SuppressWarnings(RAWTYPES) final IRequest request = getRequest(manager, token);
if (manager.getRequestResolverRequestAssignmentDataStore().getAssignmentForValue(token) == null) {
return;
}
// Lets cancel all our children first, else this would make a big fat mess.
if (request.hasChildren()) {
final ImmutableCollection<IToken<?>> currentChildren = request.getChildren();
currentChildren.forEach(t -> onRequestCancelled(manager, t));
}
// Now lets get ourselfs a clean up.
final IRequestResolver<?> targetResolver = ResolverHandler.getResolverForRequest(manager, request);
processParentReplacement(manager, request, targetResolver.onRequestCancelled(manager, request));
manager.updateRequestState(token, RequestState.FINALIZING);
}
use of com.minecolonies.api.colony.requestsystem.request.IRequest 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.request.IRequest 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;
}
Aggregations