use of net.runelite.http.api.item.ItemClient in project runelite by runelite.
the class GrandExchangeSearchPanel method priceLookup.
private void priceLookup(boolean exactMatch) {
String lookup = searchBox.getText();
if (Strings.isNullOrEmpty(lookup)) {
return;
}
// Input is not empty, add searching label
searchItemsPanel.removeAll();
showSearchString("Searching...");
SearchResult result;
try {
result = itemManager.searchForItem(lookup);
} catch (ExecutionException ex) {
log.warn("Unable to search for item {}", lookup, ex);
showSearchString("Error performing search");
return;
}
if (result != null && !result.getItems().isEmpty()) {
itemClient = new ItemClient();
for (Item item : result.getItems()) {
int itemId = item.getId();
ItemComposition itemComp = client.getItemDefinition(itemId);
if (itemComp == null) {
continue;
}
ItemPrice itemPrice = null;
try {
itemPrice = itemManager.getItemPrice(itemId);
} catch (IOException ex) {
log.warn("Unable to fetch item price for {}", itemId, ex);
}
BufferedImage itemImage = null;
try {
itemImage = itemClient.getIcon(itemId);
} catch (IOException ex) {
log.warn("Unable to fetch item icon for {}", itemId, ex);
}
if (itemImage == null) {
log.warn("Unable to fetch item icon for {}", itemId);
}
ITEMS_LIST.add(new GrandExchangeItems(itemImage, item.getName(), itemId, itemPrice != null ? itemPrice.getPrice() : 0, itemComp.getPrice() * 0.6));
// If using hotkey to lookup item, stop after finding match.
if (exactMatch && item.getName().equalsIgnoreCase(lookup)) {
break;
}
}
}
SwingUtilities.invokeLater(() -> {
for (GrandExchangeItems item : ITEMS_LIST) {
GrandExchangeItemPanel panel = new GrandExchangeItemPanel(item.getIcon(), item.getName(), item.getItemId(), item.getGePrice(), item.getHaPrice());
searchItemsPanel.add(panel);
}
ITEMS_LIST.clear();
// Remove searching label after search is complete
showSearchString(null);
});
}
Aggregations