use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.
the class AbstractBuildingDependentRequestResolver method resolve.
@Override
public void resolve(@NotNull final IRequestManager manager, @NotNull final IRequest<? extends R> request) {
final AbstractBuilding building = getBuilding(manager, request.getToken()).map(r -> (AbstractBuilding) r).get();
resolveForBuilding(manager, request, building);
}
use of com.minecolonies.api.colony.requestsystem.request.IRequest 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();
}
use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.
the class RequestHandler method reassignRequest.
/**
* Method used to reassign the request to a resolver that is not in the given blacklist.
* Cancels the request internally without notify the requester, and attempts a reassign. If the reassignment failed, it is assigned back to the orignal resolver.
*
* @param manager The manager that is reassigning a request.
* @param request The request that is being reassigned.
* @param resolverTokenBlackList The blacklist to which not to assign the request.
* @return The token of the resolver that has gotten the request assigned, null if none was found.
*
* @throws IllegalArgumentException Thrown when something went wrong.
*/
public static IToken<?> reassignRequest(final IStandardRequestManager manager, final IRequest<?> request, final Collection<IToken<?>> resolverTokenBlackList) {
// Get the current resolver
IRequestResolver currentResolver = null;
if (RequestHandler.isAssigned(manager, request.getToken())) {
currentResolver = ResolverHandler.getResolverForRequest(manager, request);
}
IToken<?> parent = null;
if (request.hasParent()) {
parent = request.getParent();
}
// Cancel the request to restart the search
processInternalCancellation(manager, request.getToken());
if (currentResolver != null) {
if (manager.getRequestResolverRequestAssignmentDataStore().getAssignments().containsKey(currentResolver.getRequesterId())) {
manager.getRequestResolverRequestAssignmentDataStore().getAssignments().get(currentResolver.getRequesterId()).remove(request.getToken());
if (manager.getRequestResolverRequestAssignmentDataStore().getAssignments().get(currentResolver.getRequesterId()).isEmpty()) {
manager.getRequestResolverRequestAssignmentDataStore().getAssignments().remove(currentResolver.getRequesterId());
}
}
}
manager.updateRequestState(request.getToken(), RequestState.REPORTED);
IToken<?> resolver = assignRequest(manager, request, resolverTokenBlackList);
if (parent != null) {
request.setParent(parent);
final IRequest parentRequest = RequestHandler.getRequest(manager, parent);
parentRequest.addChild(request.getToken());
}
return resolver;
}
use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.
the class WindowCitizen method fulfill.
/**
* On Button click transfert Items and fullfil.
*
* @param button the clicked button.
*/
private void fulfill(@NotNull final Button button) {
final int row = resourceList.getListElementIndexByPane(button);
if (getOpenRequestTreeOfCitizen().size() > row && row >= 0) {
@NotNull final IRequest tRequest = getOpenRequestTreeOfCitizen().get(row).getRequest();
if (!(tRequest.getRequest() instanceof IDeliverable)) {
return;
}
@NotNull final IRequest<? extends IDeliverable> request = (IRequest<? extends IDeliverable>) tRequest;
final Predicate<ItemStack> requestPredicate = stack -> request.getRequest().matches(stack);
final int amount = request.getRequest().getCount();
final int count = InventoryUtils.getItemCountInItemHandler(new InvWrapper(inventory), requestPredicate);
if (!isCreative && count <= 0) {
return;
}
// The itemStack size should not be greater than itemStack.getMaxStackSize, We send 1 instead
// and use quantity for the size
@NotNull final ItemStack itemStack;
if (isCreative) {
itemStack = request.getDisplayStacks().stream().findFirst().orElse(ItemStack.EMPTY);
} else {
itemStack = inventory.getStackInSlot(InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(inventory), requestPredicate));
}
MineColonies.getNetwork().sendToServer(new TransferItemsToCitizenRequestMessage(citizen, itemStack, isCreative ? amount : Math.min(amount, count), citizen.getColonyId()));
MineColonies.getNetwork().sendToServer(new UpdateRequestStateMessage(citizen.getColonyId(), request.getToken(), RequestState.OVERRULED, itemStack));
}
button.disable();
}
use of com.minecolonies.api.colony.requestsystem.request.IRequest in project minecolonies by Minecolonies.
the class WindowCitizen method getOpenRequestsOfCitizen.
@SuppressWarnings(RAWTYPES)
private ImmutableList<IRequest> getOpenRequestsOfCitizen() {
final ArrayList<IRequest> requests = new ArrayList<>();
if (citizen.getWorkBuilding() != null) {
requests.addAll(getOpenRequestsOfCitizenFromBuilding(citizen.getWorkBuilding()));
}
if (citizen.getHomeBuilding() != null && !citizen.getHomeBuilding().equals(citizen.getWorkBuilding())) {
requests.addAll(getOpenRequestsOfCitizenFromBuilding(citizen.getHomeBuilding()));
}
final BlockPos playerPos = Minecraft.getMinecraft().player.getPosition();
requests.sort(Comparator.comparing((IRequest request) -> request.getRequester().getDeliveryLocation().getInDimensionLocation().getDistance(playerPos.getX(), playerPos.getY(), playerPos.getZ())).thenComparingInt(request -> request.getToken().hashCode()));
return ImmutableList.copyOf(requests);
}
Aggregations