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);
}
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;
}
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);
}
Aggregations