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