use of com.minecolonies.api.colony.requestsystem.request.RequestState 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.request.RequestState in project minecolonies by Minecolonies.
the class StandardRequestManagerTest method testUpdateRequestState.
@Test
public void testUpdateRequestState() throws Exception {
requestManager.onProviderAddedToColony(provider);
final StringRequestable hello = new StringRequestable(LOG);
final IToken<?> token = requestManager.createAndAssignRequest(TestRequester.INSTANCE, hello);
final RequestState originalState = requestManager.getRequestForToken(token).getState();
assertEquals(RequestState.COMPLETED, originalState);
requestManager.updateRequestState(token, RequestState.RECEIVED);
assertNull(requestManager.getRequestForToken(token));
}
Aggregations