Search in sources :

Example 1 with IRequester

use of com.minecolonies.api.colony.requestsystem.requester.IRequester 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);
}
Also used : IRequest(com.minecolonies.api.colony.requestsystem.request.IRequest) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester) WrappedStaticStateRequestManager(com.minecolonies.coremod.colony.requestsystem.management.manager.wrapped.WrappedStaticStateRequestManager)

Example 2 with IRequester

use of com.minecolonies.api.colony.requestsystem.requester.IRequester in project minecolonies by Minecolonies.

the class StandardRequestFactories method deserializeFromNBT.

public static <T extends IRequestable, R extends IRequest<T>> R deserializeFromNBT(final IFactoryController controller, final NBTTagCompound compound, final INBTToObjectConverter<T> typeDeserialization, final IObjectConstructor<T, R> objectConstructor) {
    final IRequester requester = controller.deserialize(compound.getCompoundTag(NBT_REQUESTER));
    final IToken token = controller.deserialize(compound.getCompoundTag(NBT_TOKEN));
    final RequestState state = RequestState.deserializeNBT((NBTTagInt) compound.getTag(NBT_STATE));
    final T requested = typeDeserialization.apply(controller, compound.getCompoundTag(NBT_REQUESTED));
    final List<IToken> childTokens = new ArrayList<>();
    final NBTTagList childCompound = compound.getTagList(NBT_CHILDREN, Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < childCompound.tagCount(); i++) {
        childTokens.add(controller.deserialize(childCompound.getCompoundTagAt(i)));
    }
    @SuppressWarnings(Suppression.LEFT_CURLY_BRACE) final R request = objectConstructor.construct(requested, token, requester, state);
    request.addChildren(childTokens);
    if (compound.hasKey(NBT_PARENT)) {
        request.setParent(controller.deserialize(compound.getCompoundTag(NBT_PARENT)));
    }
    if (compound.hasKey(NBT_RESULT)) {
        request.setResult(typeDeserialization.apply(controller, compound.getCompoundTag(NBT_RESULT)));
    }
    return request;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) RequestState(com.minecolonies.api.colony.requestsystem.request.RequestState) IToken(com.minecolonies.api.colony.requestsystem.token.IToken) ArrayList(java.util.ArrayList) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester)

Example 3 with IRequester

use of com.minecolonies.api.colony.requestsystem.requester.IRequester in project minecolonies by Minecolonies.

the class IRequestFactory method getNewInstance.

/**
 * Method to get a new instance of the output given the input and additional context data.
 *
 * @param factoryController The factory controller that called this facotry method.
 * @param t                 The input to build a new output for.
 * @param context           The context of the request.
 * @return The new output instance for a given input.
 *
 * @throws IllegalArgumentException is thrown when the factory cannot produce a new instance out of the given context and input.
 */
@NotNull
@Override
default R getNewInstance(@NotNull final IFactoryController factoryController, @NotNull final T t, @NotNull final Object... context) throws IllegalArgumentException {
    if (context.length != 2 && context.length != 3) {
        throw new IllegalArgumentException("Unsupported context - Too many parameters.");
    }
    if (!(context[0] instanceof IToken)) {
        throw new IllegalArgumentException("Unsupported context - First context object is not a token");
    }
    if (!(context[1] instanceof IRequester)) {
        throw new IllegalArgumentException("Unsupported context - Second context object should be a location");
    }
    if (context.length == NUMBER_OF_PROPERTIES) {
        final IRequester requester = (IRequester) context[1];
        final IToken token = (IToken) context[0];
        return this.getNewInstance(t, requester, token);
    }
    if (!(context[2] instanceof RequestState)) {
        throw new IllegalArgumentException("Unsupported context - Third context object is not a request state");
    }
    final IRequester requester = (IRequester) context[1];
    final IToken token = (IToken) context[0];
    final RequestState state = (RequestState) context[2];
    return this.getNewInstance(t, requester, token, state);
}
Also used : IToken(com.minecolonies.api.colony.requestsystem.token.IToken) IRequester(com.minecolonies.api.colony.requestsystem.requester.IRequester) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IRequester (com.minecolonies.api.colony.requestsystem.requester.IRequester)3 IToken (com.minecolonies.api.colony.requestsystem.token.IToken)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)1 RequestState (com.minecolonies.api.colony.requestsystem.request.RequestState)1 WrappedStaticStateRequestManager (com.minecolonies.coremod.colony.requestsystem.management.manager.wrapped.WrappedStaticStateRequestManager)1 ArrayList (java.util.ArrayList)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 NotNull (org.jetbrains.annotations.NotNull)1