Interface IRequestResolver<R extends IRequestable>
- Type Parameters:
R- The request type that this resolver can provide.
- All Superinterfaces:
IRequester
- All Known Subinterfaces:
IPlayerRequestResolver,IQueuedRequestResolver<R>,IRetryingRequestResolver
- All Known Implementing Classes:
AbstractBuildingDependentRequestResolver,AbstractCraftingProductionResolver,AbstractCraftingRequestResolver,AbstractRequestResolver,AbstractWarehouseRequestResolver,BuildingRequestResolver,DeliverymenRequestResolver,DeliveryRequestResolver,PickupRequestResolver,PrivateWorkerCraftingProductionResolver,PrivateWorkerCraftingRequestResolver,PublicWorkerCraftingProductionResolver,PublicWorkerCraftingRequestResolver,StandardPlayerRequestResolver,StandardRetryingRequestResolver,StationRequestResolver,WarehouseConcreteRequestResolver,WarehouseRequestResolver
The resolver himself is responsible for storing the tokens of requests that he returns
-
Method Summary
Modifier and TypeMethodDescriptionattemptResolveRequest(@NotNull IRequestManager manager, @NotNull IRequest<? extends R> request) Method used to attempt a resolving operation.booleancanResolveRequest(@NotNull IRequestManager manager, IRequest<? extends R> requestToCheck) A PreCheck used to determine if this request resolver is able to resolve a given request.getFollowupRequestForCompletion(@NotNull IRequestManager manager, @NotNull IRequest<? extends R> completedRequest) intThe priority of this resolver.com.google.common.reflect.TypeToken<? extends R>Used to determine which type of requests can be resolved by this Resolver.default intgetSuitabilityMetric(@NotNull IRequestManager manager, @NotNull IRequest<? extends R> request) Check how suitable this resolver is for the request.booleanisValid()If this resolver has valid data in it.voidonAssignedRequestBeingCancelled(@NotNull IRequestManager manager, @NotNull IRequest<? extends R> request) Indicates that an assigned request has been cancelled.voidonAssignedRequestCancelled(@NotNull IRequestManager manager, @NotNull IRequest<? extends R> request) Indicates that an assigned request has been cancelled.default voidonColonyUpdate(@NotNull IRequestManager manager, @NotNull Predicate<IRequest<?>> shouldTriggerReassign) Called by manager given to indicate that a colony has updated their available items.default voidonRequestAssigned(@NotNull IRequestManager manager, @NotNull IRequest<? extends R> request, boolean simulation) Called by the manager given to indicate that this request has been assigned to you.voidresolveRequest(@NotNull IRequestManager manager, @NotNull IRequest<? extends R> request) Method used to resolve a given request.Methods inherited from interface com.minecolonies.api.colony.requestsystem.requester.IRequester
getId, getLocation, getRequesterDisplayName, onRequestedRequestCancelled, onRequestedRequestComplete
-
Method Details
-
getRequestType
com.google.common.reflect.TypeToken<? extends R> getRequestType()Used to determine which type of requests can be resolved by this Resolver.- Returns:
- The class that represents this Type of Request this resolver can resolve.
-
canResolveRequest
boolean canResolveRequest(@NotNull @NotNull IRequestManager manager, IRequest<? extends R> requestToCheck) A PreCheck used to determine if this request resolver is able to resolve a given request. Should quickly and cheaply check if this resolver COULD resolve this request.- Parameters:
requestToCheck- The request to check.manager- The manager that is checking if this resolver could resolve that request.- Returns:
- True when this resolver COULD resolve the given request, false when not.
-
attemptResolveRequest
@Nullable @Nullable List<IToken<?>> attemptResolveRequest(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends R> request) Method used to attempt a resolving operation.When this attempt was successful a List with tokens of required requests is returned. This list maybe empty. The list should indicate all sub requests that should be fullfilled before the @code{resolve(IRequest request)} method is called.
When this attempt was not successful, eg. this resolver could not schedule a crafting operation, a Null object should be returned. In that case the next resolver will be tried by the manager.
IT IS VITAL THAT THE REQUEST RETURNED ARE NOT YET ASSIGNED. SIMULATION AND OTHER STRATEGIES WILL FAIL ELSE! THE MANAGER GIVEN WILL HANDLE ASSIGNING HIMSELF!
- Parameters:
manager- The manager that is attempting to resolve using this resolver.request- The request to resolve.- Returns:
- The tokens of required requests if the attempt was successful (an empty list is allowed to indicate no requirements), null if the attempt failed.
-
resolveRequest
@Nullable void resolveRequest(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends R> request) Method used to resolve a given request. Is called the moment all Child requests are resolved.The resolver should update the state through the given manager.
When this method is called all requirements need be fullfilled for this resolver. If this is not the case it will throw a RunTimeException
- Parameters:
request- The request to resolve.manager- The manager that is resolving this request, under normal conditions this is the colony manager.- Throws:
RuntimeException- is thrown when the resolver could not resolve the request. Should never happen as attemptResolve should be called first, and all requirements should be available to this resolver at this point in time.
-
onRequestAssigned
default void onRequestAssigned(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends R> request, boolean simulation) Called by the manager given to indicate that this request has been assigned to you.- Parameters:
manager- The systems manager.request- The request assigned.simulation- True when simulating.
-
onAssignedRequestBeingCancelled
void onAssignedRequestBeingCancelled(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends R> request) Indicates that an assigned request has been cancelled. Is called before graph is updated.- Parameters:
manager- The manager that indicates the cancellingrequest- The request that has been cancelled.
-
onAssignedRequestCancelled
void onAssignedRequestCancelled(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends R> request) Indicates that an assigned request has been cancelled. Is called after the graph has been updated.- Parameters:
manager- The manager that indicates the cancellingrequest- The request that has been cancelled.
-
onColonyUpdate
default void onColonyUpdate(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull Predicate<IRequest<?>> shouldTriggerReassign) Called by manager given to indicate that a colony has updated their available items.- Parameters:
manager- The systems manager.shouldTriggerReassign- The request assigned
-
getFollowupRequestForCompletion
@Nullable default @Nullable List<IRequest<?>> getFollowupRequestForCompletion(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends R> completedRequest) -
getSuitabilityMetric
default int getSuitabilityMetric(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends R> request) Check how suitable this resolver is for the request.- Parameters:
manager- the req manager.request- the request to check.- Returns:
- the suitability metric (an int for easy comparison).
-
getPriority
int getPriority()The priority of this resolver. The higher the priority the earlier this resolver is called.- Returns:
- The priority of this resolver.
-
isValid
boolean isValid()If this resolver has valid data in it.- Returns:
- true if so.
-