runelite-client/src/main/java/net/runelite/client/plugins/bankvalue/BankCalculation.java
/**
	 * Calculate the bank based on the cache, price can be 0 if bank not active, or cache not set
	 */
Calculate the bank based on the cache, price can be 0 if bank not active, or cache not set
Calculate the bank based on the cache price can be 0 if bank not active or cache not set
void calculate()
	{
		WidgetItem[] widgetItems = queryRunner.runQuery(new BankItemQuery());
		if (widgetItems.length == 0 || !isBankDifferent(widgetItems))
		{
			return;
		}
		log.debug("Calculating new bank value...");
		gePrice = haPrice = 0;
		finished = false;
		List<ItemComposition> itemCompositions = new ArrayList<>();
		Map<Integer, WidgetItem> itemMap = new HashMap<>();
		List<Integer> itemIds = new ArrayList<>();
		for (WidgetItem widgetItem : widgetItems)
		{
			if (widgetItem.getId() <= 0 || widgetItem.getQuantity() == 0)
			{
				continue;
			}
			if (widgetItem.getId() == COINS_995)
			{
				gePrice += widgetItem.getQuantity();
				haPrice += widgetItem.getQuantity();
				continue;
			}
			if (widgetItem.getId() == PLATINUM_TOKEN)
			{
				gePrice += widgetItem.getQuantity() * 1000L;
				haPrice += widgetItem.getQuantity() * 1000L;
				continue;
			}
			final ItemComposition itemComposition = itemManager.getItemComposition(widgetItem.getId());
			itemCompositions.add(itemComposition);
			itemMap.put(widgetItem.getId(), widgetItem);
			if (config.showGE())
			{
				itemIds.add(widgetItem.getId());
			}
		}
		if (config.showGE() && !itemIds.isEmpty())
		{
			CompletableFuture<ItemPrice[]> future = itemManager.getItemPriceBatch(itemIds);
			future.whenComplete((ItemPrice[] itemPrices, Throwable ex) ->
			{
				if (ex != null)
				{
					log.debug("Error looking up item prices", ex);
					return;
				}
				if (itemPrices == null)
				{
					log.debug("Error looking up item prices");
					return;
				}
				log.debug("Price lookup is complete. {} prices.", itemPrices.length);
				try
				{
					for (ItemPrice itemPrice : itemPrices)
					{
						if (itemPrice.getItem() == null)
						{
							continue; 
						}
						gePrice += (long) itemPrice.getPrice() * (long) itemMap.get(itemPrice.getItem().getId()).getQuantity();
					}
				}
				catch (Exception ex2)
				{
					log.warn("error calculating price", ex2);
				}
				finally
				{
					finished = true;
				}
			});
		}
		else
		{
			finished = true;
		}
		if (config.showHA())
		{
			for (ItemComposition itemComposition : itemCompositions)
			{
				int price = itemComposition.getPrice();
				if (price > 0)
				{
					haPrice += (long) Math.round(price * HIGH_ALCHEMY_CONSTANT) *
						(long) itemMap.get(itemComposition.getId()).getQuantity();
				}
			}
		}
	}
void calculate ( ) { WidgetItem [ ] widgetItems = queryRunner . runQuery ( new BankItemQuery ( ) ) ; if ( widgetItems . length == 0 || ! isBankDifferent ( widgetItems ) ) { return ; } log . debug ( "Calculating new bank value..." ) ; gePrice = haPrice = 0 ; finished = false ; List < ItemComposition > itemCompositions = new ArrayList < > ( ) ; Map < Integer , WidgetItem > itemMap = new HashMap < > ( ) ; List < Integer > itemIds = new ArrayList < > ( ) ; for ( WidgetItem widgetItem : widgetItems ) { if ( widgetItem . getId ( ) <= 0 || widgetItem . getQuantity ( ) == 0 ) { continue ; } if ( widgetItem . getId ( ) == COINS_995 ) { gePrice += widgetItem . getQuantity ( ) ; haPrice += widgetItem . getQuantity ( ) ; continue ; } if ( widgetItem . getId ( ) == PLATINUM_TOKEN ) { gePrice += widgetItem . getQuantity ( ) * 1000L ; haPrice += widgetItem . getQuantity ( ) * 1000L ; continue ; } final ItemComposition itemComposition = itemManager . getItemComposition ( widgetItem . getId ( ) ) ; itemCompositions . add ( itemComposition ) ; itemMap . put ( widgetItem . getId ( ) , widgetItem ) ; if ( config . showGE ( ) ) { itemIds . add ( widgetItem . getId ( ) ) ; } } if ( config . showGE ( ) && ! itemIds . isEmpty ( ) ) { CompletableFuture < ItemPrice [ ] > future = itemManager . getItemPriceBatch ( itemIds ) ; future . whenComplete ( ( ItemPrice [ ] itemPrices , Throwable ex ) -> { if ( ex != null ) { log . debug ( "Error looking up item prices" , ex ) ; return ; } if ( itemPrices == null ) { log . debug ( "Error looking up item prices" ) ; return ; } log . debug ( "Price lookup is complete. {} prices." , itemPrices . length ) ; try { for ( ItemPrice itemPrice : itemPrices ) { if ( itemPrice . getItem ( ) == null ) { continue ; } gePrice += ( long ) itemPrice . getPrice ( ) * ( long ) itemMap . get ( itemPrice . getItem ( ) . getId ( ) ) . getQuantity ( ) ; } } catch ( Exception ex2 ) { log . warn ( "error calculating price" , ex2 ) ; } finally { finished = true ; } } ) ; } else { finished = true ; } if ( config . showHA ( ) ) { for ( ItemComposition itemComposition : itemCompositions ) { int price = itemComposition . getPrice ( ) ; if ( price > 0 ) { haPrice += ( long ) Math . round ( price * HIGH_ALCHEMY_CONSTANT ) * ( long ) itemMap . get ( itemComposition . getId ( ) ) . getQuantity ( ) ; } } } }
Calculate the bank based on the cache, price can be 0 if bank not active, or cache not set
Calculate the bank based on the cache price can be 0 if bank not active or cache not set
// Generate our lists (and do some quick price additions) // Now do the calculations // cached no price