use of com.minecolonies.api.colony.requestsystem.token.IToken in project minecolonies by Minecolonies.
the class RequestHandler method processInternalCancellation.
/**
* Method used to handle cancellation internally without notifying the requester that the request has been cancelled.
*
* @param manager The manager for which the cancellation is internally processed.
* @param token The token which is internally processed.
*/
@SuppressWarnings(UNCHECKED)
public static void processInternalCancellation(final IStandardRequestManager manager, final IToken<?> token) {
@SuppressWarnings(RAWTYPES) final IRequest request = getRequest(manager, token);
if (manager.getRequestResolverRequestAssignmentDataStore().getAssignmentForValue(token) == null) {
return;
}
// Lets cancel all our children first, else this would make a big fat mess.
if (request.hasChildren()) {
final ImmutableCollection<IToken<?>> currentChildren = request.getChildren();
currentChildren.forEach(t -> onRequestCancelled(manager, t));
}
// Now lets get ourselfs a clean up.
final IRequestResolver<?> targetResolver = ResolverHandler.getResolverForRequest(manager, request);
processParentReplacement(manager, request, targetResolver.onRequestCancelled(manager, request));
manager.updateRequestState(token, RequestState.FINALIZING);
}
use of com.minecolonies.api.colony.requestsystem.token.IToken in project minecolonies by Minecolonies.
the class BuildingBasedRequesterFactory method getNewInstance.
@NotNull
@Override
public BuildingBasedRequester getNewInstance(@NotNull final IFactoryController factoryController, @NotNull final AbstractBuilding building, @NotNull final Object... context) throws IllegalArgumentException {
if (context.length != 0) {
throw new IllegalArgumentException("To many context elements. Only 0 supported.");
}
final ILocation location = factoryController.getNewInstance(TypeConstants.ILOCATION, building.getLocation(), building.getColony().getWorld().provider.getDimension());
final IToken token = factoryController.getNewInstance(TypeConstants.ITOKEN);
return new BuildingBasedRequester(location, token);
}
use of com.minecolonies.api.colony.requestsystem.token.IToken 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.token.IToken in project minecolonies by Minecolonies.
the class StandardFactoryControllerTest method testGetNewInstance.
@Test
public void testGetNewInstance() {
final UUID id = UUID.randomUUID();
final IToken token = new StandardToken(id);
final IToken output = StandardFactoryController.getInstance().getNewInstance(TypeConstants.ITOKEN, id);
assertEquals(output, token);
}
use of com.minecolonies.api.colony.requestsystem.token.IToken in project minecolonies by Minecolonies.
the class StandardFactoryControllerTest method testDeserialize.
@Test
public void testDeserialize() {
final StandardToken standardToken = new StandardToken(UUID.randomUUID());
final IToken token = standardToken;
final NBTTagCompound compound = StandardFactoryController.getInstance().serialize(token);
final IToken deserialize = StandardFactoryController.getInstance().deserialize(compound);
assertEquals(token, deserialize);
}
Aggregations