Search in sources :

Example 6 with IRequestResolver

use of com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver in project minecolonies by Minecolonies.

the class BuildingWareHouse method getResolvers.

@Override
public ImmutableCollection<IRequestResolver<?>> getResolvers() {
    final ImmutableCollection<IRequestResolver<?>> supers = super.getResolvers();
    final ImmutableList.Builder<IRequestResolver<?>> builder = ImmutableList.builder();
    builder.addAll(supers);
    builder.add(new WarehouseRequestResolver(getRequester().getRequesterLocation(), getColony().getRequestManager().getFactoryController().getNewInstance(TypeConstants.ITOKEN)));
    return builder.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) IRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver) WarehouseRequestResolver(com.minecolonies.coremod.colony.requestsystem.resolvers.WarehouseRequestResolver)

Example 7 with IRequestResolver

use of com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver 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;
}
Also used : IRequestResolver(com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver) IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest)

Aggregations

IRequestResolver (com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver)7 ImmutableList (com.google.common.collect.ImmutableList)3 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)3 WrappedStaticStateRequestManager (com.minecolonies.coremod.colony.requestsystem.management.manager.wrapped.WrappedStaticStateRequestManager)2 ImmutableCollection (com.google.common.collect.ImmutableCollection)1 TypeToken (com.google.common.reflect.TypeToken)1 AssigningStrategy (com.minecolonies.api.colony.requestsystem.manager.AssigningStrategy)1 RequestMappingHandler (com.minecolonies.api.colony.requestsystem.manager.RequestMappingHandler)1 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)1 IRequestable (com.minecolonies.api.colony.requestsystem.requestable.IRequestable)1 IRequester (com.minecolonies.api.colony.requestsystem.requester.IRequester)1 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)1 ReflectionUtils (com.minecolonies.api.util.ReflectionUtils)1 RAWTYPES (com.minecolonies.api.util.constant.Suppression.RAWTYPES)1 UNCHECKED (com.minecolonies.api.util.constant.Suppression.UNCHECKED)1 TypeConstants (com.minecolonies.api.util.constant.TypeConstants)1 Box (com.minecolonies.blockout.views.Box)1 MineColonies (com.minecolonies.coremod.MineColonies)1 ColonyView (com.minecolonies.coremod.colony.ColonyView)1 IStandardRequestManager (com.minecolonies.coremod.colony.requestsystem.management.IStandardRequestManager)1