Search in sources :

Example 1 with RecycleInventoryItemResponse

use of POGOProtos.Networking.Responses.RecycleInventoryItemResponseOuterClass.RecycleInventoryItemResponse in project PokeGOAPI-Java by Grover-c13.

the class ItemBag method removeItem.

/**
 * Discards the given item.
 *
 * @param id the id
 * @param quantity the quantity
 * @return the result
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public Result removeItem(ItemId id, int quantity) throws RequestFailedException {
    Item item = getItem(id);
    if (item.count < quantity) {
        throw new IllegalArgumentException("You cannot remove more quantity than you have");
    }
    RecycleInventoryItemMessage msg = RecycleInventoryItemMessage.newBuilder().setItemId(id).setCount(quantity).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.RECYCLE_INVENTORY_ITEM, msg);
    api.requestHandler.sendServerRequests(serverRequest, true);
    RecycleInventoryItemResponse response;
    try {
        response = RecycleInventoryItemResponse.parseFrom(serverRequest.getData());
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    if (response.getResult() == RecycleInventoryItemResponse.Result.SUCCESS) {
        item.setCount(response.getNewCount());
        if (item.count <= 0) {
            removeItem(item.getItemId());
        }
    }
    return response.getResult();
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) RecycleInventoryItemResponse(POGOProtos.Networking.Responses.RecycleInventoryItemResponseOuterClass.RecycleInventoryItemResponse) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) RecycleInventoryItemMessage(POGOProtos.Networking.Requests.Messages.RecycleInventoryItemMessageOuterClass.RecycleInventoryItemMessage)

Aggregations

RecycleInventoryItemMessage (POGOProtos.Networking.Requests.Messages.RecycleInventoryItemMessageOuterClass.RecycleInventoryItemMessage)1 RecycleInventoryItemResponse (POGOProtos.Networking.Responses.RecycleInventoryItemResponseOuterClass.RecycleInventoryItemResponse)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 ServerRequest (com.pokegoapi.main.ServerRequest)1