use of POGOProtos.Networking.Requests.Messages.RecycleInventoryItemMessageOuterClass.RecycleInventoryItemMessage 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.getCount() < 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.getRequestHandler().sendServerRequests(serverRequest);
RecycleInventoryItemResponseOuterClass.RecycleInventoryItemResponse response;
try {
response = RecycleInventoryItemResponseOuterClass.RecycleInventoryItemResponse.parseFrom(serverRequest.getData());
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
if (response.getResult() == RecycleInventoryItemResponseOuterClass.RecycleInventoryItemResponse.Result.SUCCESS) {
item.setCount(response.getNewCount());
if (item.getCount() <= 0) {
removeItem(item.getItemId());
}
}
return response.getResult();
}
Aggregations